Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Simulator::advanceInJunction(){
- for (map<string,Junction*>:: iterator it= JunctionMap.begin(); it!=JunctionMap.end(); ++it){
- if(it->second->incomingRoads.empty()==false){
- Road* currRoad = (*it->second->vectorIt);
- if(currRoad->trafficlight.empty()==false){
- Car& PoppedCar=(*currRoad->trafficlight.front());
- if(PoppedCar.isFault==true){
- queue <Car*> tempQueue;
- while(currRoad->trafficlight.empty()==false&&PoppedCar.isFault==true){
- currRoad->trafficlight.pop();
- PoppedCar.faultTimeLeft--;
- if(PoppedCar.faultTimeLeft==0){
- PoppedCar.isFault=false;
- }
- Car& faultPoppedCar=PoppedCar;
- tempQueue.push(&faultPoppedCar);
- if(currRoad->trafficlight.empty()==false){
- PoppedCar=(*currRoad->trafficlight.front());
- }
- }
- while (currRoad->trafficlight.empty()==false){
- PoppedCar = (*currRoad->trafficlight.front());
- Car& tempCar = PoppedCar;
- currRoad->trafficlight.pop();
- tempQueue.push(&tempCar);
- }
- while (tempQueue.empty()==false){
- Car& tempCar = *tempQueue.front();
- tempQueue.pop();
- currRoad->trafficlight.push(&tempCar);
- }
- }
- currRoad->trafficlight.pop();
- currRoad->numOfCarsPerGreenSlice++;
- Road& NextRoad=*PoppedCar.roadPlanQueue.front();
- PoppedCar.roadPlanQueue.pop();
- NextRoad.CarsOnRoad.push_back(&PoppedCar);
- NextRoad.numOfCars++;
- PoppedCar.road->numOfCars--;
- PoppedCar.road=&NextRoad;
- string timeAsString = SSTR(simulatorTime);
- string start=NextRoad.start;
- string end=NextRoad.end;
- PoppedCar.history.push_back('(');
- PoppedCar.history+timeAsString;
- PoppedCar.history.push_back(',');
- PoppedCar.history+start;
- PoppedCar.history.push_back(',');
- PoppedCar.history+end;
- PoppedCar.history.push_back(',');
- PoppedCar.history.push_back('0');
- PoppedCar.history.push_back(')');
- }
- currRoad->leftGreenTime--;
- if(currRoad->leftGreenTime==0){
- if(it->second->vectorIt==it->second->incomingRoads.end()){
- it->second->vectorIt=it->second->incomingRoads.begin();
- }
- else{
- it->second->vectorIt++;
- }
- int gap=(currRoad->greenSliceTime)-(currRoad->numOfCarsPerGreenSlice);
- if (gap==0){
- currRoad->greenSliceTime=min(currRoad->greenSliceTime+1,MAX_TIME_SLICE);
- }
- if (gap==currRoad->greenSliceTime){
- currRoad->greenSliceTime=max(currRoad->greenSliceTime-1,MIN_TIME_SLICE);
- }
- currRoad->numOfCarsPerGreenSlice=0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement