#include <MSEmitControl.h>
A vehicle emitter; Holds a list of vehicles which may be filled by vehicles read by MSRouteLoaders. Tries to emit vehicles departing at a time into the network as soon this time is reached and keeps them as long the emission fails.
If a vehicle is emitted, the control about it is given to the lanes.
Vehicles are not controlled (created, deleted) by this class.
Definition at line 63 of file MSEmitControl.h.
Public Member Functions | |
| void | add (SUMOVehicleParameter *pars) throw () |
| Adds parameter for a vehicle flow for departure. | |
| void | add (MSVehicle *veh) throw () |
| Adds a single vehicle for departure. | |
| unsigned int | emitVehicles (SUMOTime time) throw (ProcessError) |
| Emits vehicles that want to depart at the given time. | |
| unsigned int | getWaitingVehicleNo () const throw () |
| Returns the number of waiting vehicles. | |
| bool | hasPendingFlows () const throw () |
| Returns whether any flows are still active. | |
| MSEmitControl (MSVehicleControl &vc, SUMOTime maxDepartDelay, bool checkEdgesOnce) throw () | |
| Constructor. | |
| ~MSEmitControl () throw () | |
| Destructor. | |
Private Member Functions | |
| unsigned int | checkFlows (SUMOTime time, MSVehicleContainer::VehicleVector &refusedEmits) throw (ProcessError) |
| Checks for all vehicles coming from flows whether they can be emitted. | |
| void | checkFlowWait (MSVehicle *veh) throw () |
| Checks whether any flow is blocked due to this vehicle and clears the block. | |
| void | checkPrevious (SUMOTime time) throw () |
| Adds all vehicles that should have been emitted earlier to the refuse container. | |
| MSEmitControl (const MSEmitControl &) | |
| Invalidated copy constructor. | |
| MSEmitControl & | operator= (const MSEmitControl &) |
| Invalidated assignment operator. | |
| unsigned int | tryEmit (SUMOTime time, MSVehicle *veh, MSVehicleContainer::VehicleVector &refusedEmits) throw (ProcessError) |
| Tries to emit the vehicle. | |
Private Attributes | |
| MSVehicleContainer | myAllVeh |
| All loaded vehicles sorted by their departure time. | |
| bool | myCheckEdgesOnce |
| Whether an edge on which a vehicle could not depart should be ignored in the same step. | |
| std::vector< Flow > | myFlows |
| Container for periodical vehicle parameters. | |
| SUMOTime | myMaxDepartDelay |
| The maximum waiting time; vehicles waiting longer are deleted (-1: no deletion). | |
| MSVehicleContainer::VehicleVector | myRefusedEmits1 |
| Buffers for vehicles that could not been inserted. | |
| MSVehicleContainer::VehicleVector | myRefusedEmits2 |
| MSVehicleControl & | myVehicleControl |
| The assigned vehicle control (needed for vehicle reemission and deletion). | |
Data Structures | |
| struct | Flow |
| MSEmitControl::MSEmitControl | ( | MSVehicleControl & | vc, | |
| SUMOTime | maxDepartDelay, | |||
| bool | checkEdgesOnce | |||
| ) | throw () |
Constructor.
| [in] | vc | The assigned vehicle control (needed for vehicle reemission and deletion) |
| [in] | maxDepartDelay | Vehicles waiting longer than this for emission are deleted (-1: no deletion) |
| [in] | checkEdgesOnce | Whether an edge on which a vehicle could not depart should be ignored in the same step |
Definition at line 45 of file MSEmitControl.cpp.
00048 : myVehicleControl(vc), myMaxDepartDelay(maxDepartDelay), 00049 myCheckEdgesOnce(checkEdgesOnce) {}
| MSEmitControl::~MSEmitControl | ( | ) | throw () |
Destructor.
Definition at line 52 of file MSEmitControl.cpp.
References myFlows.
00052 { 00053 for (std::vector<Flow>::iterator i=myFlows.begin(); i!=myFlows.end(); ++i) { 00054 delete(i->pars); 00055 } 00056 }
| MSEmitControl::MSEmitControl | ( | const MSEmitControl & | ) | [private] |
Invalidated copy constructor.
| void MSEmitControl::add | ( | SUMOVehicleParameter * | pars | ) | throw () |
Adds parameter for a vehicle flow for departure.
| [in] | flow | The flow to add for later emission |
Definition at line 66 of file MSEmitControl.cpp.
References DEPART_LANE_RANDOM, DEPART_POS_RANDOM, MSRoute::distDictionary(), MSNet::getInstance(), RandomDistributor< T >::getVals(), MSNet::getVehicleControl(), MSVehicleControl::hasVTypeDistribution(), MSEmitControl::Flow::isVolatile, myFlows, MSEmitControl::Flow::pars, and MSEmitControl::Flow::vehicle.
00066 { 00067 Flow flow; 00068 flow.pars = pars; 00069 flow.isVolatile = pars->departLaneProcedure==DEPART_LANE_RANDOM || 00070 pars->departPosProcedure==DEPART_POS_RANDOM || 00071 MSNet::getInstance()->getVehicleControl().hasVTypeDistribution(pars->vtypeid); 00072 if (!flow.isVolatile) { 00073 RandomDistributor<const MSRoute*> *dist = MSRoute::distDictionary(pars->routeid); 00074 if (dist != 0) { 00075 const std::vector<const MSRoute*>& routes = dist->getVals(); 00076 const MSEdge* e = 0; 00077 for (std::vector<const MSRoute*>::const_iterator i = routes.begin(); i != routes.end(); ++i) { 00078 if (e == 0) { 00079 e = (*i)->getEdges()[0]; 00080 } else { 00081 if (e != (*i)->getEdges()[0]) { 00082 flow.isVolatile = true; 00083 break; 00084 } 00085 } 00086 } 00087 } 00088 } 00089 flow.vehicle = 0; 00090 myFlows.push_back(flow); 00091 }
| void MSEmitControl::add | ( | MSVehicle * | veh | ) | throw () |
Adds a single vehicle for departure.
The vehicle is added to "myAllVeh".
| [in] | veh | The vehicle to add for later emission |
Definition at line 60 of file MSEmitControl.cpp.
References MSVehicleContainer::add(), and myAllVeh.
Referenced by MSRouteHandler::closeFlow(), MSRouteHandler::closeVehicle(), MSPerson::MSPersonStage_Driving::proceed(), and MSRouteHandler::retrieveLastReadVehicle().
| unsigned int MSEmitControl::checkFlows | ( | SUMOTime | time, | |
| MSVehicleContainer::VehicleVector & | refusedEmits | |||
| ) | throw (ProcessError) [private] |
Checks for all vehicles coming from flows whether they can be emitted.
| [in] | time | The current simulation time |
| [in] | refusedEmits | Container to insert vehicles that could not be emitted into |
Definition at line 194 of file MSEmitControl.cpp.
References MSVehicleControl::addVehicle(), MSVehicleControl::buildVehicle(), DELTA_T, SUMOVehicleParameter::depart, MSRoute::dictionary(), MSNet::getInstance(), MSVehicleControl::getVehicle(), MSNet::getVehicleControl(), MSVehicleControl::getVType(), SUMOVehicleParameter::id, myFlows, SUMOVehicleParameter::repetitionNumber, SUMOVehicleParameter::repetitionOffset, SUMOVehicleParameter::repetitionsDone, SUMOVehicleParameter::routeid, toString(), tryEmit(), and SUMOVehicleParameter::vtypeid.
Referenced by emitVehicles().
00195 { 00196 unsigned int noEmitted = 0; 00197 for (std::vector<Flow>::iterator i=myFlows.begin(); i!=myFlows.end();) { 00198 SUMOVehicleParameter* pars = i->pars; 00199 if (!i->isVolatile && i->vehicle!=0) { 00200 ++i; 00201 continue; 00202 } 00203 while (pars->repetitionsDone < pars->repetitionNumber && 00204 pars->depart + pars->repetitionsDone * pars->repetitionOffset < time + DELTA_T) { 00205 SUMOVehicleParameter* newPars = new SUMOVehicleParameter(*pars); 00206 newPars->id = pars->id + "." + toString(pars->repetitionsDone); 00207 newPars->depart = (SUMOTime)(pars->depart + pars->repetitionsDone * pars->repetitionOffset); 00208 pars->repetitionsDone++; 00209 // try to build the vehicle 00210 if (MSNet::getInstance()->getVehicleControl().getVehicle(newPars->id)==0) { 00211 const MSRoute *route = MSRoute::dictionary(pars->routeid); 00212 const MSVehicleType *vtype = MSNet::getInstance()->getVehicleControl().getVType(pars->vtypeid); 00213 i->vehicle = MSNet::getInstance()->getVehicleControl().buildVehicle(newPars, route, vtype); 00214 MSNet::getInstance()->getVehicleControl().addVehicle(newPars->id, i->vehicle); 00215 noEmitted += tryEmit(time, i->vehicle, refusedEmits); 00216 if (!i->isVolatile && i->vehicle!=0) { 00217 break; 00218 } 00219 } else { 00220 // strange: another vehicle with the same id already exists 00221 #ifdef HAVE_MESOSIM 00222 if (MSGlobals::gStateLoaded) { 00223 break; 00224 } 00225 #endif 00226 throw ProcessError("Another vehicle with the id '" + newPars->id + "' exists."); 00227 } 00228 } 00229 if (pars->repetitionsDone == pars->repetitionNumber) { 00230 i = myFlows.erase(i); 00231 delete(pars); 00232 } else { 00233 ++i; 00234 } 00235 } 00236 return noEmitted; 00237 }
| void MSEmitControl::checkFlowWait | ( | MSVehicle * | veh | ) | throw () [private] |
Checks whether any flow is blocked due to this vehicle and clears the block.
| [in] | veh | The vehicle to check for |
Definition at line 170 of file MSEmitControl.cpp.
References myFlows.
Referenced by tryEmit().
00170 { 00171 for (std::vector<Flow>::iterator i=myFlows.begin(); i!=myFlows.end(); ++i) { 00172 if (i->vehicle == veh) { 00173 i->vehicle = 0; 00174 break; 00175 } 00176 } 00177 }
| void MSEmitControl::checkPrevious | ( | SUMOTime | time | ) | throw () [private] |
Adds all vehicles that should have been emitted earlier to the refuse container.
| [in] | time | The current simulation time |
Definition at line 181 of file MSEmitControl.cpp.
References MSVehicleContainer::isEmpty(), myAllVeh, myRefusedEmits1, myRefusedEmits2, MSVehicleContainer::pop(), MSVehicleContainer::top(), and MSVehicleContainer::topTime().
Referenced by emitVehicles().
00181 { 00182 // check to which list append to 00183 MSVehicleContainer::VehicleVector &previousRefused = 00184 myRefusedEmits2.size()==0 ? myRefusedEmits1 : myRefusedEmits2; 00185 while (!myAllVeh.isEmpty()&&myAllVeh.topTime()<time) { 00186 const MSVehicleContainer::VehicleVector &top = myAllVeh.top(); 00187 copy(top.begin(), top.end(), back_inserter(previousRefused)); 00188 myAllVeh.pop(); 00189 } 00190 }
| unsigned int MSEmitControl::emitVehicles | ( | SUMOTime | time | ) | throw (ProcessError) |
Emits vehicles that want to depart at the given time.
All vehicles scheduled for this time are tried to be emitted. This includes those with a depart time as the given time and those that wait for being emitted due they could not be inserted in previous steps.
For each vehicle, tryEmit is called. If this fails, a vehicle keeps within the refused emit containers ("myRefusedEmits1", "myRefusedEmits2") so that it may be emitted within the next steps.
Returns the number of vehicles that could be inserted into the net.
| [in] | time | The current simulation time |
Definition at line 95 of file MSEmitControl.cpp.
References MSVehicleContainer::anyWaitingFor(), checkFlows(), checkPrevious(), myAllVeh, myFlows, myRefusedEmits1, myRefusedEmits2, MSVehicleContainer::pop(), MSVehicleContainer::top(), and tryEmit().
Referenced by MSNet::simulationStep().
00095 { 00096 checkPrevious(time); 00097 // check whether any vehicles shall be emitted within this time step 00098 if (!myAllVeh.anyWaitingFor(time)&&myRefusedEmits1.empty()&&myRefusedEmits2.empty()&&myFlows.empty()) { 00099 return 0; 00100 } 00101 unsigned int noEmitted = 0; 00102 // we use buffering for the refused emits to save time 00103 // for this, we have two lists; one contains previously refused emits, the second 00104 // will be used to append those vehicles that will not be able to depart in this 00105 // time step 00106 assert(myRefusedEmits1.size()==0||myRefusedEmits2.size()==0); 00107 MSVehicleContainer::VehicleVector &refusedEmits = 00108 myRefusedEmits1.size()==0 ? myRefusedEmits1 : myRefusedEmits2; 00109 MSVehicleContainer::VehicleVector &previousRefused = 00110 myRefusedEmits2.size()==0 ? myRefusedEmits1 : myRefusedEmits2; 00111 00112 // go through the list of previously refused vehicles, first 00113 MSVehicleContainer::VehicleVector::const_iterator veh; 00114 for (veh=previousRefused.begin(); veh!=previousRefused.end(); veh++) { 00115 noEmitted += tryEmit(time, *veh, refusedEmits); 00116 } 00117 // clear previously refused vehicle container 00118 previousRefused.clear(); 00119 00120 // Insert vehicles from myTrips into the net until the next vehicle's 00121 // departure time is greater than the current time. 00122 // Retrieve the list of vehicles to emit within this time step 00123 00124 noEmitted += checkFlows(time, refusedEmits); 00125 while (myAllVeh.anyWaitingFor(time)) { 00126 const MSVehicleContainer::VehicleVector &next = myAllVeh.top(); 00127 // go through the list and try to emit 00128 for (veh=next.begin(); veh!=next.end(); veh++) { 00129 noEmitted += tryEmit(time, *veh, refusedEmits); 00130 } 00131 // let the MSVehicleContainer clear the vehicles 00132 myAllVeh.pop(); 00133 } 00134 // Return the number of emitted vehicles 00135 return noEmitted; 00136 }
| unsigned int MSEmitControl::getWaitingVehicleNo | ( | ) | const throw () |
Returns the number of waiting vehicles.
The sizes of refused emits (sum of vehicles in "myRefusedEmits1" and "myRefusedEmits2") is returned.
Definition at line 241 of file MSEmitControl.cpp.
References myRefusedEmits1, and myRefusedEmits2.
Referenced by MSNet::closeSimulation(), GUINet::getParameterWindow(), and MSNet::writeOutput().
00241 { 00242 return (unsigned int)(myRefusedEmits1.size() + myRefusedEmits2.size()); 00243 }
| bool MSEmitControl::hasPendingFlows | ( | ) | const throw () |
Returns whether any flows are still active.
Definition at line 247 of file MSEmitControl.cpp.
References myFlows.
Referenced by MSNet::simulationState().
00247 { 00248 return !myFlows.empty(); 00249 }
| MSEmitControl& MSEmitControl::operator= | ( | const MSEmitControl & | ) | [private] |
Invalidated assignment operator.
| unsigned int MSEmitControl::tryEmit | ( | SUMOTime | time, | |
| MSVehicle * | veh, | |||
| MSVehicleContainer::VehicleVector & | refusedEmits | |||
| ) | throw (ProcessError) [private] |
Tries to emit the vehicle.
If the emission fails, it is examined whether the reason was a vaporizing edge. If so, the vehicle is deleted. Otherwise, it is checked whether the time the vehicle had to wait so far is larger than the maximum allowed waiting time. If so, the vehicle is deleted, too. If both does not match, the vehicle is reinserted to "refusedEmits" in order to be emitted in next steps.
As soon as the vehicle is emitted or deleted, it is checked whether a vehicle with same parameter shall be reinserter by calling "checkReemission".
| [in] | time | The current simulation time |
| [in] | veh | The vehicle to emit |
| [in] | refusedEmits | Container to insert vehicles that could not be emitted into |
Definition at line 140 of file MSEmitControl.cpp.
References checkFlowWait(), MSVehicleControl::deleteVehicle(), MSEdge::emit(), MSEdge::getLastFailedEmissionTime(), MSEdge::isVaporizing(), myCheckEdgesOnce, myMaxDepartDelay, myVehicleControl, and MSEdge::setLastFailedEmissionTime().
Referenced by checkFlows(), and emitVehicles().
00141 { 00142 assert(veh->getDesiredDepart() <= time); 00143 veh->onTryEmit(); 00144 const MSEdge &edge = veh->getDepartEdge(); 00145 if ((!myCheckEdgesOnce || edge.getLastFailedEmissionTime()!=time) && edge.emit(*veh, time)) { 00146 // Successful emission. 00147 checkFlowWait(veh); 00148 veh->onDepart(); 00149 return 1; 00150 } 00151 if (myMaxDepartDelay != -1 && time - veh->getDesiredDepart() > myMaxDepartDelay) { 00152 // remove vehicles waiting too long for departure 00153 checkFlowWait(veh); 00154 myVehicleControl.deleteVehicle(veh); 00155 } else if (edge.isVaporizing()) { 00156 // remove vehicles if the edge shall be empty 00157 checkFlowWait(veh); 00158 veh->setWasVaporized(true); 00159 myVehicleControl.deleteVehicle(veh); 00160 } else { 00161 // let the vehicle wait one step, we'll retry then 00162 refusedEmits.push_back(veh); 00163 } 00164 edge.setLastFailedEmissionTime(time); 00165 return 0; 00166 }
MSVehicleContainer MSEmitControl::myAllVeh [private] |
All loaded vehicles sorted by their departure time.
Definition at line 184 of file MSEmitControl.h.
Referenced by add(), checkPrevious(), and emitVehicles().
bool MSEmitControl::myCheckEdgesOnce [private] |
Whether an edge on which a vehicle could not depart should be ignored in the same step.
Definition at line 208 of file MSEmitControl.h.
Referenced by tryEmit().
std::vector<Flow> MSEmitControl::myFlows [private] |
Container for periodical vehicle parameters.
Definition at line 202 of file MSEmitControl.h.
Referenced by add(), checkFlows(), checkFlowWait(), emitVehicles(), hasPendingFlows(), and ~MSEmitControl().
SUMOTime MSEmitControl::myMaxDepartDelay [private] |
The maximum waiting time; vehicles waiting longer are deleted (-1: no deletion).
Definition at line 205 of file MSEmitControl.h.
Referenced by tryEmit().
Buffers for vehicles that could not been inserted.
Definition at line 187 of file MSEmitControl.h.
Referenced by checkPrevious(), emitVehicles(), and getWaitingVehicleNo().
Definition at line 187 of file MSEmitControl.h.
Referenced by checkPrevious(), emitVehicles(), and getWaitingVehicleNo().
MSVehicleControl& MSEmitControl::myVehicleControl [private] |
The assigned vehicle control (needed for vehicle reemission and deletion).
Definition at line 181 of file MSEmitControl.h.
Referenced by tryEmit().
1.5.6