#include <MSEdgeControl.h>
In order to avoid touching all lanes, even the empty ones, this class stores and updates the information about "active" lanes, those that have at least one vehicle on them. During longitudinal movement, this can be simply achieved through return values of the MSLane-methods, signalling either that the lane got active or inactive. This is but not possible when changing lanes, we have to go through the lanes, here. Also, we have to add lanes on which a vehicle was emitted, separately, doing this into ("myChangedStateLanes") which entries are integrated at the begin of is step in "patchActiveLanes".
Definition at line 65 of file MSEdgeControl.h.
Public Types | |
| typedef std::vector< MSEdge * > | EdgeCont |
| Container for edges. | |
Public Member Functions | |
| void | changeLanes (SUMOTime t) throw () |
| Moves (precomputes) critical vehicles. | |
| void | detectCollisions (SUMOTime timestep) throw () |
| Detect collisions. | |
| std::vector< std::string > | getEdgeNames () const throw () |
| Returns the list of names of all known edges. | |
| const std::vector< MSEdge * > & | getEdges () const throw () |
| Returns loaded edges. | |
| void | gotActive (MSLane *l) throw () |
| Informs the control that the given lane got active. | |
| MSEdgeControl (const std::vector< MSEdge * > &edges) throw () | |
| Constructor. | |
| void | patchActiveLanes () throw () |
| Resets information whether a lane is active for all lanes. | |
| ~MSEdgeControl () throw () | |
| Destructor. | |
Interfaces for longitudinal vehicle movement | |
| void | moveCritical (SUMOTime t) throw () |
| Moves (precomputes) critical vehicles. | |
| void | moveFirst (SUMOTime t) throw () |
| Really moves critical vehicles. | |
Private Types | |
| typedef std::vector< LaneUsage > | LaneUsageVector |
| Definition of a container about a lane's number of vehicles and neighbors. | |
Private Member Functions | |
| MSEdgeControl (const MSEdgeControl &) | |
| Copy constructor. | |
| MSEdgeControl & | operator= (const MSEdgeControl &) |
| Assignment operator. | |
Private Attributes | |
| std::list< MSLane * > | myActiveLanes |
| The list of active (not empty) lanes. | |
| std::set< MSLane * > | myChangedStateLanes |
| Lanes which changed the state without informing the control. | |
| std::vector< MSEdge * > | myEdges |
| Loaded edges. | |
| LaneUsageVector | myLanes |
| Information about lanes' number of vehicles and neighbors. | |
| std::vector< SUMOTime > | myLastLaneChange |
| The list of active (not empty) lanes. | |
| std::vector< MSLane * > | myWithVehicles2Integrate |
| A storage for lanes which shall be integrated because vehicles have moved onto them. | |
Data Structures | |
| struct | LaneUsage |
| A structure holding some basic information about a simulated lane. More... | |
| typedef std::vector< MSEdge* > MSEdgeControl::EdgeCont |
typedef std::vector<LaneUsage> MSEdgeControl::LaneUsageVector [private] |
Definition of a container about a lane's number of vehicles and neighbors.
Definition at line 211 of file MSEdgeControl.h.
| MSEdgeControl::MSEdgeControl | ( | const std::vector< MSEdge * > & | edges | ) | throw () |
Constructor.
Builds LaneUsage information for each lane and assigns them to lanes.
| [in] | edges | The loaded edges |
Definition at line 44 of file MSEdgeControl.cpp.
00045 : myEdges(edges), 00046 myLanes(MSLane::dictSize()), 00047 myLastLaneChange(MSEdge::dictSize()) { 00048 // build the usage definitions for lanes 00049 for (std::vector< MSEdge* >::const_iterator i=myEdges.begin(); i!=myEdges.end(); ++i) { 00050 const std::vector<MSLane*> &lanes = (*i)->getLanes(); 00051 if (lanes.size()==1) { 00052 size_t pos = (*lanes.begin())->getNumericalID(); 00053 myLanes[pos].lane = *(lanes.begin()); 00054 myLanes[pos].firstNeigh = lanes.end(); 00055 myLanes[pos].lastNeigh = lanes.end(); 00056 myLanes[pos].amActive = false; 00057 myLanes[pos].haveNeighbors = false; 00058 } else { 00059 for (std::vector<MSLane*>::const_iterator j=lanes.begin(); j!=lanes.end(); ++j) { 00060 size_t pos = (*j)->getNumericalID(); 00061 myLanes[pos].lane = *j; 00062 myLanes[pos].firstNeigh = (j+1); 00063 myLanes[pos].lastNeigh = lanes.end(); 00064 myLanes[pos].amActive = false; 00065 myLanes[pos].haveNeighbors = true; 00066 } 00067 } 00068 size_t pos = (*i)->getNumericalID(); 00069 myLastLaneChange[pos] = -1; 00070 } 00071 // assign lane usage definitions to lanes 00072 for (size_t j=0; j<myLanes.size(); j++) { 00073 myLanes[j].lane->init(*this, myLanes[j].firstNeigh, myLanes[j].lastNeigh); 00074 } 00075 }
| MSEdgeControl::~MSEdgeControl | ( | ) | throw () |
| MSEdgeControl::MSEdgeControl | ( | const MSEdgeControl & | ) | [private] |
Copy constructor.
| void MSEdgeControl::changeLanes | ( | SUMOTime | t | ) | throw () |
Moves (precomputes) critical vehicles.
Calls "changeLanes" of each of the multi-lane edges. Check then for this edge whether a lane got active, adding it to "myActiveLanes" and marking it as active in such cases.
Definition at line 141 of file MSEdgeControl.cpp.
References MSEdgeControl::LaneUsage::amActive, MSEdge::changeLanes(), MSEdge::getLanes(), MSEdge::getNumericalID(), MSEdgeControl::LaneUsage::haveNeighbors, myActiveLanes, myLanes, and myLastLaneChange.
Referenced by MSNet::simulationStep().
00141 { 00142 std::vector<MSLane*> toAdd; 00143 for (std::list<MSLane*>::iterator i=myActiveLanes.begin(); i!=myActiveLanes.end();) { 00144 LaneUsage &lu = myLanes[(*i)->getNumericalID()]; 00145 if (lu.haveNeighbors) { 00146 MSEdge &edge = (*i)->getEdge(); 00147 if (myLastLaneChange[edge.getNumericalID()]!=t) { 00148 myLastLaneChange[edge.getNumericalID()] = t; 00149 edge.changeLanes(t); 00150 const std::vector<MSLane*> &lanes = edge.getLanes(); 00151 for (std::vector<MSLane*>::const_iterator i=lanes.begin(); i!=lanes.end(); ++i) { 00152 LaneUsage &lu = myLanes[(*i)->getNumericalID()]; 00153 if ((*i)->getVehicleNumber()>0 && !lu.amActive) { 00154 toAdd.push_back(*i); 00155 lu.amActive = true; 00156 } 00157 } 00158 } 00159 ++i; 00160 } else { 00161 i = myActiveLanes.end(); 00162 } 00163 } 00164 for (std::vector<MSLane*>::iterator i=toAdd.begin(); i!=toAdd.end(); ++i) { 00165 myActiveLanes.push_front(*i); 00166 } 00167 }
| void MSEdgeControl::detectCollisions | ( | SUMOTime | timestep | ) | throw () |
Detect collisions.
Calls "detectCollisions" of each lane. Shouldn't be necessary if model-implementation is correct. The parameter is simply passed to the lane-instance for reporting.
| [in] | timestep | The current time step |
Definition at line 171 of file MSEdgeControl.cpp.
References myActiveLanes.
Referenced by MSNet::simulationStep().
00171 { 00172 // Detections is made by the edge's lanes, therefore hand over. 00173 for (std::list<MSLane*>::iterator i = myActiveLanes.begin(); i != myActiveLanes.end(); ++i) { 00174 (*i)->detectCollisions(timestep); 00175 } 00176 }
| std::vector< std::string > MSEdgeControl::getEdgeNames | ( | ) | const throw () |
Returns the list of names of all known edges.
Definition at line 180 of file MSEdgeControl.cpp.
References myEdges.
Referenced by traci::TraCIServer::convertCartesianToRoadMap().
00180 { 00181 std::vector<std::string> ret; 00182 for (std::vector<MSEdge*>::const_iterator i=myEdges.begin(); i!=myEdges.end(); ++i) { 00183 ret.push_back((*i)->getID()); 00184 } 00185 return ret; 00186 }
| const std::vector<MSEdge*>& MSEdgeControl::getEdges | ( | ) | const throw () [inline] |
Returns loaded edges.
Definition at line 161 of file MSEdgeControl.h.
References myEdges.
Referenced by MSDevice_Routing::adaptEdgeEfforts(), MSDevice_Routing::buildVehicleDevices(), and traci::TraCIServer::getNetBoundary().
00161 { 00162 return myEdges; 00163 }
| void MSEdgeControl::gotActive | ( | MSLane * | l | ) | throw () |
Informs the control that the given lane got active.
| [in] | l | The activated lane |
Definition at line 190 of file MSEdgeControl.cpp.
References myChangedStateLanes.
Referenced by MSLane::isEmissionSuccess().
00190 { 00191 myChangedStateLanes.insert(l); 00192 }
| void MSEdgeControl::moveCritical | ( | SUMOTime | t | ) | throw () |
Moves (precomputes) critical vehicles.
"Critical" are those vehicles that interact with the next junction and all first vehicles. They are not moved, in fact, but their speed along the next path is precomputed.
This method goes through all active lanes calling their "moveCritical" implementation. If this call returns true, the lane is removed from the list of active lanes.
Definition at line 101 of file MSEdgeControl.cpp.
References myActiveLanes, and myLanes.
Referenced by MSNet::simulationStep().
00101 { 00102 for (std::list<MSLane*>::iterator i=myActiveLanes.begin(); i!=myActiveLanes.end();) { 00103 if ((*i)->getVehicleNumber()==0 || (*i)->moveCritical(t)) { 00104 myLanes[(*i)->getNumericalID()].amActive = false; 00105 i = myActiveLanes.erase(i); 00106 } else { 00107 ++i; 00108 } 00109 } 00110 }
| void MSEdgeControl::moveFirst | ( | SUMOTime | t | ) | throw () |
Really moves critical vehicles.
"Critical" are those vehicles that interact with the next junction and all first vehicles.
At first, this method goes through all active lanes calling their "setCritical" implementation. If this call returns true, the lane is removed from the list of active lanes. During this call, "myWithVehicles2Integrate" is filled with lanes that obtain new vehicles.
Then, myWithVehicles2Integrate is gone through, calling "integrateNewVehicle" of each of the stored instances. If this call returns true and the lane was not active before, it is added to the list of active lanes.
Definition at line 114 of file MSEdgeControl.cpp.
References MSEdgeControl::LaneUsage::amActive, MSEdgeControl::LaneUsage::haveNeighbors, myActiveLanes, myLanes, and myWithVehicles2Integrate.
Referenced by MSNet::simulationStep().
00114 { 00115 myWithVehicles2Integrate.clear(); 00116 for (std::list<MSLane*>::iterator i=myActiveLanes.begin(); i!=myActiveLanes.end();) { 00117 if ((*i)->getVehicleNumber()==0 || (*i)->setCritical(t, myWithVehicles2Integrate)) { 00118 myLanes[(*i)->getNumericalID()].amActive = false; 00119 i = myActiveLanes.erase(i); 00120 } else { 00121 ++i; 00122 } 00123 } 00124 for (std::vector<MSLane*>::iterator i=myWithVehicles2Integrate.begin(); i!=myWithVehicles2Integrate.end(); ++i) { 00125 if ((*i)->integrateNewVehicle(t)) { 00126 LaneUsage &lu = myLanes[(*i)->getNumericalID()]; 00127 if (!lu.amActive) { 00128 if (lu.haveNeighbors) { 00129 myActiveLanes.push_front(*i); 00130 } else { 00131 myActiveLanes.push_back(*i); 00132 } 00133 lu.amActive = true; 00134 } 00135 } 00136 } 00137 }
| MSEdgeControl& MSEdgeControl::operator= | ( | const MSEdgeControl & | ) | [private] |
Assignment operator.
| void MSEdgeControl::patchActiveLanes | ( | ) | throw () |
Resets information whether a lane is active for all lanes.
For each lane in "myChangedStateLanes": if the lane has at least one vehicle and is not marked as being active, it is added to the list og active lanes and marked as being active.
Definition at line 83 of file MSEdgeControl.cpp.
References MSEdgeControl::LaneUsage::amActive, MSEdgeControl::LaneUsage::haveNeighbors, myActiveLanes, myChangedStateLanes, and myLanes.
Referenced by MSNet::simulationStep().
00083 { 00084 for (std::set<MSLane*>::iterator i=myChangedStateLanes.begin(); i!=myChangedStateLanes.end(); ++i) { 00085 LaneUsage &lu = myLanes[(*i)->getNumericalID()]; 00086 // if the lane was inactive but is now... 00087 if (!lu.amActive && (*i)->getVehicleNumber()>0) { 00088 // ... add to active lanes and mark as such 00089 if (lu.haveNeighbors) { 00090 myActiveLanes.push_front(*i); 00091 } else { 00092 myActiveLanes.push_back(*i); 00093 } 00094 lu.amActive = true; 00095 } 00096 } 00097 myChangedStateLanes.clear(); 00098 }
std::list<MSLane*> MSEdgeControl::myActiveLanes [private] |
The list of active (not empty) lanes.
Definition at line 217 of file MSEdgeControl.h.
Referenced by changeLanes(), detectCollisions(), moveCritical(), moveFirst(), and patchActiveLanes().
std::set<MSLane*> MSEdgeControl::myChangedStateLanes [private] |
Lanes which changed the state without informing the control.
Definition at line 223 of file MSEdgeControl.h.
Referenced by gotActive(), and patchActiveLanes().
std::vector<MSEdge*> MSEdgeControl::myEdges [private] |
Loaded edges.
Definition at line 208 of file MSEdgeControl.h.
Referenced by getEdgeNames(), and getEdges().
LaneUsageVector MSEdgeControl::myLanes [private] |
Information about lanes' number of vehicles and neighbors.
Definition at line 214 of file MSEdgeControl.h.
Referenced by changeLanes(), moveCritical(), moveFirst(), and patchActiveLanes().
std::vector<SUMOTime> MSEdgeControl::myLastLaneChange [private] |
The list of active (not empty) lanes.
Definition at line 226 of file MSEdgeControl.h.
Referenced by changeLanes().
std::vector<MSLane*> MSEdgeControl::myWithVehicles2Integrate [private] |
A storage for lanes which shall be integrated because vehicles have moved onto them.
Definition at line 220 of file MSEdgeControl.h.
Referenced by moveFirst().
1.5.6