#include <MSRightOfWayJunction.h>

A class which realises junctions that do regard any kind of a right-of-way. The rules for the right-of-way themselves are stored within the associated "MSJunctionLogic" - structure.
Definition at line 56 of file MSRightOfWayJunction.h.
Public Types | |
| typedef std::bitset< 64 > | InnerState |
| Container for junction-internal lane occupation Each element of this container represents one particular junction-internal lane. | |
| typedef std::vector < ApproachingVehicleInformation > | LinkApproachingVehicles |
| typedef std::bitset< 64 > | LinkFoes |
| Container for link foes. | |
| typedef std::bitset< 64 > | Request |
| Container for vehicle requests. Each element of this container represents one particular link from one lane to another. | |
| typedef std::bitset< 64 > | Respond |
| Container for the request responds. The respond is link-bound. | |
Public Member Functions | |
| bool | clearRequests () |
| const std::vector< MSLane * > & | getFoeInternalLanes (const MSLink *const srcLink) const throw () |
| const std::vector< MSLink * > & | getFoeLinks (const MSLink *const srcLink) const throw () |
| const std::string & | getID () const |
| Returns the id of the junction. | |
| const Position2D & | getPosition () const |
| const Position2DVector & | getShape () const throw () |
| Returns this junction's shape. | |
| MSRightOfWayJunction (const std::string &id, const Position2D &position, const Position2DVector &shape, std::vector< MSLane * > incoming, MSJunctionLogic *logic) throw () | |
| Constructor. | |
| void | postloadInit () throw (ProcessError) |
| initialises the junction after the whole net has been loaded | |
| virtual bool | setAllowed () |
| virtual | ~MSRightOfWayJunction () |
| Destructor. | |
Protected Member Functions | |
| virtual void | deadlockKiller () |
| Search for deadlock-situations and eleminate them. | |
Protected Attributes | |
| std::vector< MSLane * > | myEmptyLanes |
| std::vector< MSLink * > | myEmptyLinks |
| std::string | myID |
| The id of the junction. | |
| std::vector< MSLane * > | myIncomingLanes |
| list of incoming lanes | |
| InnerState | myInnerState |
| std::map< MSLink *, std::vector< MSLane * > > | myLinkFoeInternalLanes |
| std::map< MSLink *, std::vector< MSLink * > > | myLinkFoeLinks |
| MSJunctionLogic * | myLogic |
| Position2D | myPosition |
| The position of the junction. | |
| Request | myRequest |
| Respond | myRespond |
| Position2DVector | myShape |
| The shape of the junction. | |
Private Member Functions | |
| MSRightOfWayJunction (const MSRightOfWayJunction &) | |
| Invalidated copy constructor. | |
| MSRightOfWayJunction & | operator= (const MSRightOfWayJunction &) |
| Invalidated assignment operator. | |
typedef std::bitset<64> MSLogicJunction::InnerState [inherited] |
Container for junction-internal lane occupation Each element of this container represents one particular junction-internal lane.
Definition at line 75 of file MSLogicJunction.h.
typedef std::vector<ApproachingVehicleInformation> MSJunction::LinkApproachingVehicles [inherited] |
Definition at line 62 of file MSJunction.h.
typedef std::bitset<64> MSLogicJunction::LinkFoes [inherited] |
typedef std::bitset<64> MSLogicJunction::Request [inherited] |
Container for vehicle requests. Each element of this container represents one particular link from one lane to another.
Definition at line 63 of file MSLogicJunction.h.
typedef std::bitset<64> MSLogicJunction::Respond [inherited] |
Container for the request responds. The respond is link-bound.
Definition at line 67 of file MSLogicJunction.h.
| MSRightOfWayJunction::MSRightOfWayJunction | ( | const std::string & | id, | |
| const Position2D & | position, | |||
| const Position2DVector & | shape, | |||
| std::vector< MSLane * > | incoming, | |||
| MSJunctionLogic * | logic | |||
| ) | throw () |
Constructor.
| [in] | id | The id of the junction |
| [in] | position | The position of the junction |
| [in] | shape | The shape of the junction |
| [in] | incoming | The incoming lanes |
| [in] | internal | The internal lanes |
| [in] | logic | The logic of this junction |
Definition at line 49 of file MSRightOfWayJunction.cpp.
00057 : MSLogicJunction(id, position, shape, incoming 00058 #ifdef HAVE_INTERNAL_LANES 00059 , internal), 00060 #else 00061 ), 00062 #endif 00063 myLogic(logic) {}
| MSRightOfWayJunction::~MSRightOfWayJunction | ( | ) | [virtual] |
Destructor.
Definition at line 74 of file MSRightOfWayJunction.cpp.
References myLogic.
00074 { 00075 delete myLogic; 00076 }
| MSRightOfWayJunction::MSRightOfWayJunction | ( | const MSRightOfWayJunction & | ) | [private] |
Invalidated copy constructor.
| bool MSRightOfWayJunction::clearRequests | ( | ) | [virtual] |
Clears junction's and lane's requests to prepare for the next iteration.
Implements MSJunction.
Definition at line 67 of file MSRightOfWayJunction.cpp.
References MSLogicJunction::myInnerState, and MSLogicJunction::myRequest.
00067 { 00068 myRequest.reset(); 00069 myInnerState.reset(); 00070 return true; 00071 }
| void MSRightOfWayJunction::deadlockKiller | ( | ) | [protected, virtual] |
Search for deadlock-situations and eleminate them.
Definition at line 199 of file MSRightOfWayJunction.cpp.
References MSLogicJunction::myInnerState, myLogic, MSLogicJunction::myRequest, MSLogicJunction::myRespond, RandHelper::rand(), and MSJunctionLogic::respond().
Referenced by setAllowed().
00199 { 00200 if (myRequest.none()) { 00201 return; 00202 } 00203 00204 // let's assume temporary, that deadlocks only occure on right-before-left 00205 // junctions 00206 if (myRespond.none() && myInnerState.none()) { 00207 // Handle deadlock: Create randomly a deadlock-free request out of 00208 // myRequest, i.e. a "single bit" request. Then again, send it 00209 // through myLogic (this is necessary because we don't have a 00210 // mapping between requests and lanes.) !!! (we do now!!) 00211 std::vector< unsigned > trueRequests; 00212 trueRequests.reserve(myRespond.size()); 00213 for (unsigned i = 0; i < myRequest.size(); ++i) { 00214 if (myRequest.test(i)) { 00215 trueRequests.push_back(i); 00216 assert(trueRequests.size() <= myRespond.size()); 00217 } 00218 } 00219 // Choose randomly an index out of [0,trueRequests.size()]; 00220 // !!! random choosing may choose one of less priorised lanes 00221 unsigned int noLockIndex = (unsigned int) RandHelper::rand(trueRequests.size()); 00222 00223 // Create deadlock-free request. 00224 std::bitset<64> noLockRequest(false); 00225 assert(trueRequests.size()>noLockIndex); 00226 noLockRequest.set(trueRequests[ noLockIndex ]); 00227 // Calculate respond with deadlock-free request. 00228 myLogic->respond(noLockRequest, myInnerState, myRespond); 00229 } 00230 return; 00231 }
| const std::vector<MSLane*>& MSRightOfWayJunction::getFoeInternalLanes | ( | const MSLink *const | srcLink | ) | const throw () [inline, virtual] |
Reimplemented from MSJunction.
Definition at line 90 of file MSRightOfWayJunction.h.
References myLinkFoeInternalLanes.
00090 { 00091 return myLinkFoeInternalLanes.find((MSLink*) srcLink)->second; 00092 }
| const std::vector<MSLink*>& MSRightOfWayJunction::getFoeLinks | ( | const MSLink *const | srcLink | ) | const throw () [inline, virtual] |
Reimplemented from MSJunction.
Definition at line 86 of file MSRightOfWayJunction.h.
References myLinkFoeLinks.
00086 { 00087 return myLinkFoeLinks.find((MSLink*) srcLink)->second; 00088 }
| const std::string & MSJunction::getID | ( | ) | const [inherited] |
Returns the id of the junction.
Definition at line 65 of file MSJunction.cpp.
References MSJunction::myID.
Referenced by GUIJunctionWrapper::getMicrosimID().
00065 { 00066 return myID; 00067 }
| const Position2D & MSJunction::getPosition | ( | ) | const [inherited] |
returns the junction's position
Definition at line 55 of file MSJunction.cpp.
References MSJunction::myPosition.
Referenced by GUIJunctionWrapper::drawGL(), GUINet::getJunctionPosition(), traci::TraCIServer::handleTrafficLightDomain(), and TraCIServerAPI_Junction::processGet().
00055 { 00056 return myPosition; 00057 }
| const Position2DVector& MSJunction::getShape | ( | ) | const throw () [inline, inherited] |
Returns this junction's shape.
Definition at line 108 of file MSJunction.h.
References MSJunction::myShape.
Referenced by GUIJunctionWrapper::drawGL().
00108 { 00109 return myShape; 00110 }
| MSRightOfWayJunction& MSRightOfWayJunction::operator= | ( | const MSRightOfWayJunction & | ) | [private] |
Invalidated assignment operator.
| void MSRightOfWayJunction::postloadInit | ( | ) | throw (ProcessError) [virtual] |
initialises the junction after the whole net has been loaded
Reimplemented from MSLogicJunction.
Definition at line 80 of file MSRightOfWayJunction.cpp.
References MSJunctionLogic::getFoesFor(), MSJunctionLogic::getInternalFoesFor(), MSJunctionLogic::getIsCont(), MSJunctionLogic::getLogicSize(), MSJunctionLogic::isCrossing(), MSLogicJunction::myIncomingLanes, MSLogicJunction::myInnerState, myLinkFoeInternalLanes, myLinkFoeLinks, myLogic, MSLogicJunction::myRequest, and MSLogicJunction::myRespond.
00080 { 00081 // inform links where they have to report approaching vehicles to 00082 unsigned int requestPos = 0; 00083 std::vector<MSLane*>::iterator i; 00084 // going through the incoming lanes... 00085 unsigned int maxNo = 0; 00086 std::vector<std::pair<MSLane*, MSLink*> > sortedLinks; 00087 for (i=myIncomingLanes.begin(); i!=myIncomingLanes.end(); ++i) { 00088 const MSLinkCont &links = (*i)->getLinkCont(); 00089 // ... set information for every link 00090 for (MSLinkCont::const_iterator j=links.begin(); j!=links.end(); j++) { 00091 if (myLogic->getLogicSize()<=requestPos) { 00092 throw ProcessError("Found invalid logic position of a link (network error)"); 00093 } 00094 sortedLinks.push_back(std::make_pair(*i, *j)); 00095 ++maxNo; 00096 } 00097 } 00098 00099 bool isCrossing = myLogic->isCrossing(); 00100 for (i=myIncomingLanes.begin(); i!=myIncomingLanes.end(); ++i) { 00101 const MSLinkCont &links = (*i)->getLinkCont(); 00102 // ... set information for every link 00103 for (MSLinkCont::const_iterator j=links.begin(); j!=links.end(); j++) { 00104 if (myLogic->getLogicSize()<=requestPos) { 00105 throw ProcessError("Found invalid logic position of a link (network error)"); 00106 } 00107 const MSLogicJunction::LinkFoes &foeLinks = myLogic->getFoesFor(requestPos); 00108 const std::bitset<64> &internalFoes = myLogic->getInternalFoesFor(requestPos); 00109 bool cont = myLogic->getIsCont(requestPos); 00110 myLinkFoeLinks[*j] = std::vector<MSLink*>(); 00111 for (unsigned int c=0; c<maxNo; ++c) { 00112 if (foeLinks.test(c)) { 00113 myLinkFoeLinks[*j].push_back(sortedLinks[c].second); 00114 } 00115 } 00116 myLinkFoeInternalLanes[*j] = std::vector<MSLane*>(); 00117 for (unsigned int c=0; c<myInternalLanes.size(); ++c) { 00118 if (internalFoes.test(c)) { 00119 myLinkFoeInternalLanes[*j].push_back(myInternalLanes[c]); 00120 } 00121 } 00122 (*j)->setRequestInformation(&myRequest, requestPos, &myRespond, requestPos, 00123 foeLinks, isCrossing, cont, myLinkFoeLinks[*j], myLinkFoeInternalLanes[*j]); 00124 requestPos++; 00125 } 00126 } 00127 #ifdef HAVE_INTERNAL_LANES 00128 // set information for the internal lanes 00129 requestPos = 0; 00130 for (i=myInternalLanes.begin(); i!=myInternalLanes.end(); ++i) { 00131 // ... set information about participation 00132 static_cast<MSInternalLane*>(*i)->setParentJunctionInformation(&myInnerState, requestPos++); 00133 } 00134 #endif 00135 }
| bool MSRightOfWayJunction::setAllowed | ( | ) | [virtual] |
Sets the information which vehicles may drive
Implements MSJunction.
Definition at line 139 of file MSRightOfWayJunction.cpp.
References deadlockKiller(), MSGlobals::gUsingInternalLanes, MSLogicJunction::myInnerState, myLogic, MSLogicJunction::myRequest, MSLogicJunction::myRespond, and MSJunctionLogic::respond().
00139 { 00140 #ifdef HAVE_INTERNAL_LANES 00141 // lets reset the yield information on internal, split 00142 // left-moving links 00143 /* 00144 if (MSGlobals::gUsingInternalLanes) { 00145 std::vector<MSLane*>::iterator i; 00146 size_t requestPos = 0; 00147 // going through the incoming lanes... 00148 for (i=myIncomingLanes.begin(); i!=myIncomingLanes.end(); ++i) { 00149 const MSLinkCont &links = (*i)->getLinkCont(); 00150 // check whether the next lane is free 00151 for (MSLinkCont::const_iterator j=links.begin(); j!=links.end(); j++) { 00152 if(myRequest.test(requestPos)) { 00153 MSLane *dest = (*j)->getLane(); 00154 if (dest!=0) { 00155 SUMOReal approachingLength = 0; 00156 MSLane *via = 0; 00157 if(via!=0) { 00158 approachingLength = via->getVehLenSum(); 00159 } 00160 const MSVehicle * const lastOnDest = dest->getLastVehicle(); 00161 if (lastOnDest!=0) { 00162 if (lastOnDest->getPositionOnLane()-lastOnDest->getLength()-approachingLength<0) { 00163 myRequest.set(requestPos, false); 00164 } 00165 } 00166 } 00167 } 00168 requestPos++; 00169 } 00170 } 00171 } 00172 */ 00173 #endif 00174 // Get myRespond from logic and check for deadlocks. 00175 myLogic->respond(myRequest, myInnerState, myRespond); 00176 deadlockKiller(); 00177 00178 #ifdef HAVE_INTERNAL_LANES 00179 // reset the yield information on internal, split left-moving links 00180 if (MSGlobals::gUsingInternalLanes) { 00181 for (std::vector<MSLane*>::iterator i=myInternalLanes.begin(); i!=myInternalLanes.end(); ++i) { 00182 const MSLinkCont &lc = (*i)->getLinkCont(); 00183 if (lc.size()==1) { 00184 MSLink *link = lc[0]; 00185 if (link->getViaLane()!=0) { 00186 // this is a split left-mover 00187 link->resetInternalPriority(); 00188 } 00189 } 00190 } 00191 } 00192 #endif 00193 myInnerState.reset(); 00194 return true; 00195 }
std::vector<MSLane*> MSJunction::myEmptyLanes [protected, inherited] |
std::vector<MSLink*> MSJunction::myEmptyLinks [protected, inherited] |
std::string MSJunction::myID [protected, inherited] |
The id of the junction.
Definition at line 122 of file MSJunction.h.
Referenced by MSJunction::getID().
std::vector<MSLane*> MSLogicJunction::myIncomingLanes [protected, inherited] |
list of incoming lanes
Definition at line 98 of file MSLogicJunction.h.
Referenced by postloadInit().
InnerState MSLogicJunction::myInnerState [protected, inherited] |
Current inner state
Definition at line 109 of file MSLogicJunction.h.
Referenced by clearRequests(), deadlockKiller(), postloadInit(), and setAllowed().
std::map<MSLink*, std::vector<MSLane*> > MSRightOfWayJunction::myLinkFoeInternalLanes [protected] |
Definition at line 103 of file MSRightOfWayJunction.h.
Referenced by getFoeInternalLanes(), and postloadInit().
std::map<MSLink*, std::vector<MSLink*> > MSRightOfWayJunction::myLinkFoeLinks [protected] |
Definition at line 102 of file MSRightOfWayJunction.h.
Referenced by getFoeLinks(), and postloadInit().
MSJunctionLogic* MSRightOfWayJunction::myLogic [protected] |
the type of the junction (its logic)
Definition at line 100 of file MSRightOfWayJunction.h.
Referenced by deadlockKiller(), postloadInit(), setAllowed(), and ~MSRightOfWayJunction().
Position2D MSJunction::myPosition [protected, inherited] |
The position of the junction.
Definition at line 125 of file MSJunction.h.
Referenced by MSJunction::getPosition().
Request MSLogicJunction::myRequest [protected, inherited] |
Current request.
Definition at line 105 of file MSLogicJunction.h.
Referenced by clearRequests(), deadlockKiller(), postloadInit(), and setAllowed().
Respond MSLogicJunction::myRespond [protected, inherited] |
Current respond
Definition at line 112 of file MSLogicJunction.h.
Referenced by deadlockKiller(), postloadInit(), and setAllowed().
Position2DVector MSJunction::myShape [protected, inherited] |
The shape of the junction.
Definition at line 128 of file MSJunction.h.
Referenced by MSJunction::getShape().
1.5.6