Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. void Simulator::advanceInJunction(){
  2.  
  3. for (map<string,Junction*>:: iterator it= JunctionMap.begin(); it!=JunctionMap.end(); ++it){
  4. if(it->second->incomingRoads.empty()==false){
  5. Road* currRoad = (*it->second->vectorIt);
  6. if(currRoad->trafficlight.empty()==false){
  7.  
  8. Car& PoppedCar=(*currRoad->trafficlight.front());
  9. if(PoppedCar.isFault==true){
  10. queue <Car*> tempQueue;
  11. while(currRoad->trafficlight.empty()==false&&PoppedCar.isFault==true){
  12. currRoad->trafficlight.pop();
  13. PoppedCar.faultTimeLeft--;
  14. if(PoppedCar.faultTimeLeft==0){
  15. PoppedCar.isFault=false;
  16. }
  17. Car& faultPoppedCar=PoppedCar;
  18. tempQueue.push(&faultPoppedCar);
  19. if(currRoad->trafficlight.empty()==false){
  20. PoppedCar=(*currRoad->trafficlight.front());
  21. }
  22. }
  23.  
  24. while (currRoad->trafficlight.empty()==false){
  25. PoppedCar = (*currRoad->trafficlight.front());
  26. Car& tempCar = PoppedCar;
  27. currRoad->trafficlight.pop();
  28. tempQueue.push(&tempCar);
  29. }
  30. while (tempQueue.empty()==false){
  31. Car& tempCar = *tempQueue.front();
  32. tempQueue.pop();
  33. currRoad->trafficlight.push(&tempCar);
  34. }
  35. }
  36. currRoad->trafficlight.pop();
  37. currRoad->numOfCarsPerGreenSlice++;
  38. Road& NextRoad=*PoppedCar.roadPlanQueue.front();
  39. PoppedCar.roadPlanQueue.pop();
  40. NextRoad.CarsOnRoad.push_back(&PoppedCar);
  41. NextRoad.numOfCars++;
  42. PoppedCar.road->numOfCars--;
  43. PoppedCar.road=&NextRoad;
  44. string timeAsString = SSTR(simulatorTime);
  45. string start=NextRoad.start;
  46. string end=NextRoad.end;
  47. PoppedCar.history.push_back('(');
  48. PoppedCar.history+timeAsString;
  49. PoppedCar.history.push_back(',');
  50. PoppedCar.history+start;
  51. PoppedCar.history.push_back(',');
  52. PoppedCar.history+end;
  53. PoppedCar.history.push_back(',');
  54. PoppedCar.history.push_back('0');
  55. PoppedCar.history.push_back(')');
  56. }
  57.  
  58. currRoad->leftGreenTime--;
  59. if(currRoad->leftGreenTime==0){
  60. if(it->second->vectorIt==it->second->incomingRoads.end()){
  61. it->second->vectorIt=it->second->incomingRoads.begin();
  62. }
  63. else{
  64. it->second->vectorIt++;
  65. }
  66. int gap=(currRoad->greenSliceTime)-(currRoad->numOfCarsPerGreenSlice);
  67. if (gap==0){
  68. currRoad->greenSliceTime=min(currRoad->greenSliceTime+1,MAX_TIME_SLICE);
  69. }
  70. if (gap==currRoad->greenSliceTime){
  71. currRoad->greenSliceTime=max(currRoad->greenSliceTime-1,MIN_TIME_SLICE);
  72. }
  73. currRoad->numOfCarsPerGreenSlice=0;
  74. }
  75.  
  76.  
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement