Guest User

Untitled

a guest
Mar 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include "..\h\TraciControlToSumo.h"
  2.  
  3. void TraciControlToSumo::initialize()
  4. {
  5. random = false;
  6. /*Initializes StartupInfo, sumoCfgString, sumoCmd, and cmdArgs*/
  7.  
  8. ZeroMemory(&StartupInfo, sizeof(StartupInfo)); //Fills StartupInfo with zeros
  9. StartupInfo.cb = sizeof StartupInfo; //Only parameter of StartupInfo that needs to be configured
  10.  
  11. std::cout << "Enter 0 for normal mode, 1 for random mode: ";
  12. std::cin >> random;
  13.  
  14. std::cout << "Input path to SUMO config file: ";
  15. std::cin >> sumoCfgString;
  16.  
  17.  
  18. if (random == true)
  19. {
  20. srand(time(NULL)); //Provides a seed for the random number generator
  21.  
  22. seed = rand() % 10000; //Generates a random seed for Sumo
  23.  
  24. sumoCmd = "sumo-gui -c " + sumoCfgString + " --remote-port 1340" + " --seed " + std::to_string(seed);
  25.  
  26. }
  27.  
  28. else
  29. sumoCmd = "sumo-gui -c " + sumoCfgString + " --remote-port 1340";
  30.  
  31. cmdArgs = const_cast<char *>(sumoCmd.c_str());
  32. }
  33.  
  34. void TraciControlToSumo::runSumo()
  35. {
  36. //Spawns a process and it's own separate thread
  37. CreateProcess(NULL, cmdArgs,
  38. NULL, NULL, FALSE, 0, NULL,
  39. NULL, &StartupInfo, &ProcessInfo);
  40.  
  41. Sleep(5000); //SUMO needs to start entirely before runClient() is called. This assures there's enough time for SUMO to boot up.
  42. }
  43.  
  44. void TraciControlToSumo::runClient()
  45. {
  46. //Connects the client, outputs time, runs for 5000 time steps, closes the client, and outputs time once more
  47. client.connect("localhost", 1340);
  48. std::cout << "time in ms: " << client.simulation.getCurrentTime() << "\n";
  49. std::cout << "run 500 steps ...\n";
  50. client.simulationStep(500);
  51. std::cout << "time in ms: " << client.simulation.getCurrentTime() << "\n";
  52. std::cout << "Command line: " << sumoCmd << std::endl;
  53. client.close();
  54. system("PAUSE");
  55. }
  56.  
  57. std::string TraciControlToSumo::getSumoCmd()
  58. {
  59. return sumoCmd;
  60. }
  61.  
  62. bool TraciControlToSumo::getRandom()
  63. {
  64. return random;
  65. }
  66.  
  67. std::string TraciControlToSumo::getSumoCfgString()
  68. {
  69. return sumoCfgString;
  70. }
  71.  
  72. int TraciControlToSumo::getSeed()
  73. {
  74. return seed;
  75. }
Add Comment
Please, Sign In to add comment