本文整理汇总了C++中Road::getRoomLeftInTravelingArea方法的典型用法代码示例。如果您正苦于以下问题:C++ Road::getRoomLeftInTravelingArea方法的具体用法?C++ Road::getRoomLeftInTravelingArea怎么用?C++ Road::getRoomLeftInTravelingArea使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Road
的用法示例。
在下文中一共展示了Road::getRoomLeftInTravelingArea方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eventsToReschedule
vector<Event> Intersection::runEvent(Event ev, double time, double dt)
{
vector<Event> eventsToReschedule(0);
EventType type = ev.getType();
switch(type)
{
case enteringRoad:
{
Road* road = ev.getRoad();
bool hasMoved = road->moveCarsInJA();
if(hasMoved) //if at least one car has moved
{
Intersection* previousIntersection = road->getIntersectionA();
//Reschedule event running the TravelingArea and CommonQueue in current road
eventsToReschedule.push_back(Event(outgoingRoad,road,previousIntersection));
}
break;
}
case outgoingRoad:
{
Road* road = ev.getRoad();
bool hasMoved = road->moveCarsInCQandTA(dt);
if(hasMoved) //if at least one car has moved
{
//Rescheduling the entrance of the car that enter the network
eventsToReschedule.push_back(Event(enteringNetwork,NULL,this));
//Rescheduling entry of cars from the road entering the intersection
for(vector<Road*>::iterator it = enteringRoads.begin(); it != enteringRoads.end(); it++)
{
eventsToReschedule.push_back(Event(enteringRoad,*it,this));
}
}
break;
}
case enteringNetwork:
{
EnterCarIt it = enteringCars.begin();
while(it != enteringCars.end()) //We go through every entering car
{
EnterCarIt it2 = next(it);
Car* currentCar = it->first;
Road* targetRoad = it->second;
if(currentCar->getEnteringTime() <= time) //If it is time for the current car to enter the network
{
if(targetRoad->getRoomLeftInTravelingArea() >= currentCar->getLength()) //If there is room for the car
{
MoveResult result = currentCar->tryToEnterRoad(targetRoad); //Run the moving function in the car
targetRoad->getTA()->addCar(currentCar); //Add the car to the new traveling area
enteringCars.erase(it); //erasing the car
it = it2; //updating the iterator
}
else
{
currentCar->postponeEnteringTime(dt); //We postpone the car's entering time
it++; //updating the iterator
}
}
else
it++;
}
break;
}
}
return eventsToReschedule;
}