56 #define MAX_BLOCK_LENGTH 20000
57 #define MAX_SIGNAL_WARNINGS 10
64 #define DEBUG_SIGNALSTATE
65 #define DEBUG_SIGNALSTATE_PRIORITY
66 #define DEBUG_FIND_PROTECTION
70 #define DEBUG_COND DEBUG_HELPER(this)
71 #define DEBUG_COND_LINKINFO DEBUG_HELPER(myLink->getTLLogic())
72 #define DEBUG_HELPER(obj) ((obj)->isSelected())
95 const std::string&
id,
const std::string& programID,
SUMOTime delay,
96 const std::map<std::string, std::string>& parameters) :
111 if (links.size() != 1) {
113 +
" links controlled by index " +
toString(links[0]->getTLIndex()));
152 #ifdef DEBUG_SIGNALSTATE
156 std::string state(
myLinks.size(),
'G');
158 if (li.myLink->getApproaching().size() > 0) {
160 DriveWay& driveway = li.getDriveWay(closest.first);
165 if (mustWait || !driveway.
reserve(closest, occupied)) {
166 state[li.myLink->getTLIndex()] =
'r';
167 if (occupied.size() > 0) {
168 li.reroute(
const_cast<SUMOVehicle*
>(closest.first), occupied);
170 #ifdef DEBUG_SIGNALSTATE
172 std::cout <<
SIMTIME <<
" rsl=" << li.getID() <<
" veh=" << closest.first->getID() <<
" notReserved\n";
176 state[li.myLink->getTLIndex()] =
'G';
181 #ifdef DEBUG_SIGNALSTATE
183 std::cout <<
SIMTIME <<
" rsl=" << li.getID() <<
" veh=" << closest.first->getID() <<
" reserved\n";
188 DriveWay& driveway = li.myDriveways.front();
190 #ifdef DEBUG_SIGNALSTATE
195 state[li.myLink->getTLIndex()] =
'r';
197 #ifdef DEBUG_SIGNALSTATE
199 std::cout <<
SIMTIME <<
" rsl=" << li.getID() <<
" green for default driveway (" <<
toString(driveway.
myRoute) <<
")\n";
209 #ifdef DEBUG_SIGNALSTATE
225 #ifdef DEBUG_SIGNALSTATE
227 std::cout <<
" constraint '" << c->
getDescription() <<
"' not cleared\n";
252 auto it = std::find(constraints.begin(), constraints.end(), constraint);
253 if (it != constraints.end()) {
255 constraints.erase(it);
261 auto it = std::find(constraints.begin(), constraints.end(), constraint);
262 if (it != constraints.end()) {
264 constraints.erase(it);
362 for (
MSLink* link : links) {
363 result += link->getDescription() +
" ";
370 std::vector<const MSLane*> lanes(visited.size(),
nullptr);
371 for (
auto item : visited) {
372 lanes[item.second] = item.first;
380 double minDist = std::numeric_limits<double>::max();
383 if (apprIt->second.dist < minDist) {
384 minDist = apprIt->second.
dist;
414 for (
const DriveWay& dw : li.myDriveways) {
427 if (bidi ==
nullptr) {
437 #ifdef DEBUG_SIGNALSTATE
439 std::cout <<
" oncoming vehicle on bidi-lane " << lane->
getID() <<
"\n";
449 #ifdef DEBUG_SIGNALSTATE
451 std::cout <<
" oncoming vehicle on flank-lane " << lane->
getID() <<
"\n";
462 if (veh->
getSpeed() > 0 && closest.second.arrivalSpeedBraking > 0
464 #ifdef DEBUG_SIGNALSTATE
466 std::cout <<
" oncoming vehicle approaching foe link " << foeLink->
getDescription() <<
"\n";
489 #ifdef DEBUG_SIGNALSTATE
491 std::cout <<
SIMTIME <<
" rsl=" << rs->
getID() <<
" insertion constraint '" << c->
getDescription() <<
"' for vehicle '" << veh->
getID() <<
"' not cleared\n";
516 myUniqueDriveWay =
false;
517 myLastRerouteTime = -1;
518 myLastRerouteVehicle =
nullptr;
521 dummyRoute.push_back(&myLink->getLane()->getEdge());
522 DriveWay dw = buildDriveWay(dummyRoute.begin(), dummyRoute.end());
523 myDriveways.push_back(dw);
529 return myLink->getTLLogic()->getID() +
"_" +
toString(myLink->getTLIndex());
535 if (myUniqueDriveWay) {
536 return myDriveways.front();
538 MSEdge* first = &myLink->getLane()->getEdge();
547 while (lookBack > 0 && routeIndex > 0) {
549 if (prevEdge == first) {
560 return myDriveways.front();
565 auto itRoute = firstIt;
566 auto itDwRoute = dw.myRoute.begin();
568 while (itRoute != veh->
getRoute().
end() && itDwRoute != dw.myRoute.end()) {
569 if (*itRoute != *itDwRoute) {
583 myDriveways.push_back(dw);
584 return myDriveways.back();
615 std::vector<MSLane*> before;
616 visited[myLink->getLaneBefore()] = (int)visited.size();
618 if (fromBidi !=
nullptr) {
620 visited[fromBidi] = (int)visited.size();
621 before.push_back(fromBidi);
623 dw.
buildRoute(myLink, 0., first, end, visited);
636 #ifdef DEBUG_BUILD_DRIVEWAY
638 std::cout <<
" buildDriveWay railSignal=" <<
getID()
669 && (myLastRerouteVehicle != veh
673 myLastRerouteVehicle = veh;
674 myLastRerouteTime = now;
679 std::cout <<
SIMTIME <<
" reroute veh=" << veh->
getID() <<
" rs=" <<
getID() <<
" occupied=" <<
toString(occupied) <<
"\n";
687 std::cout <<
" rerouting successful\n";
701 std::string joinVehicle =
"";
704 if (stop !=
nullptr) {
705 joinVehicle = stop->
join;
708 if (conflictLaneOccupied(joinVehicle)) {
709 for (
MSLane* bidi : myBidi) {
710 if (!bidi->empty() && bidi->getBidiLane() !=
nullptr) {
711 occupied.push_back(&bidi->getBidiLane()->getEdge());
714 #ifdef DEBUG_SIGNALSTATE
716 std::cout <<
" conflictLaneOccupied\n";
721 for (
MSLink* link : myProtectingSwitches) {
722 if (!findProtection(closest, link)) {
723 #ifdef DEBUG_SIGNALSTATE
725 std::cout <<
" no protection at switch " << link->getDescription() <<
"\n";
731 for (
MSLink* foeLink : myConflictLinks) {
732 if (hasLinkConflict(closest, foeLink)) {
733 #ifdef DEBUG_SIGNALSTATE
735 std::cout <<
" linkConflict with " <<
getTLLinkID(foeLink) <<
"\n";
741 if (deadlockLaneOccupied()) {
744 myActive = closest.first;
751 for (
MSLink* foeLink : myConflictLinks) {
752 if (foeLink->getApproaching().size() > 0) {
762 #ifdef DEBUG_SIGNALSTATE_PRIORITY
764 std::cout <<
" checkLinkConflict foeLink=" <<
getTLLinkID(foeLink) <<
"\n";
769 #ifdef DEBUG_SIGNALSTATE_PRIORITY
771 std::cout <<
" approaching foe=" << foe.first->getID() <<
"\n";
775 assert(foeTLL !=
nullptr);
778 if (foeRS !=
nullptr) {
783 !overlap(foeDriveWay)) {
784 #ifdef DEBUG_SIGNALSTATE_PRIORITY
787 std::cout <<
" foe blocked\n";
789 std::cout <<
" foe constrained\n";
791 std::cout <<
" no overlap\n";
797 #ifdef DEBUG_SIGNALSTATE_PRIORITY
800 <<
" aSB=" << veh.second.arrivalSpeedBraking <<
" foeASB=" << foe.second.arrivalSpeedBraking
801 <<
" aT=" << veh.second.arrivalTime <<
" foeAT=" << foe.second.arrivalTime
802 <<
" aS=" << veh.first->getSpeed() <<
" foeS=" << foe.first->getSpeed()
803 <<
" aD=" << veh.second.dist <<
" foeD=" << foe.second.dist
804 <<
" aW=" << veh.first->getWaitingTime() <<
" foeW=" << foe.first->getWaitingTime()
805 <<
" aN=" << veh.first->getNumericalID() <<
" foeN=" << foe.first->getNumericalID()
809 const bool yield = mustYield(veh, foe);
825 if (foe.second.arrivalSpeedBraking == veh.second.arrivalSpeedBraking) {
826 if (foe.second.arrivalTime == veh.second.arrivalTime) {
827 if (foe.first->getSpeed() == veh.first->getSpeed()) {
828 if (foe.second.dist == veh.second.dist) {
829 if (foe.first->getWaitingTime() == veh.first->getWaitingTime()) {
830 return foe.first->getNumericalID() < veh.first->getNumericalID();
832 return foe.first->getWaitingTime() > veh.first->getWaitingTime();
835 return foe.second.dist < veh.second.dist;
838 return foe.first->getSpeed() > veh.first->getSpeed();
841 return foe.second.arrivalTime < veh.second.arrivalTime;
844 return foe.second.arrivalSpeedBraking > veh.second.arrivalSpeedBraking;
851 for (
const MSLane* lane : myConflictLanes) {
852 if (!lane->isEmpty()) {
853 #ifdef DEBUG_SIGNALSTATE
855 std::cout <<
SIMTIME <<
" conflictLane " << lane->getID() <<
" occupied\n";
856 if (joinVehicle !=
"") {
857 std::cout <<
" joinVehicle=" << joinVehicle <<
" occupant=" <<
toString(lane->getVehiclesSecure()) <<
"\n";
858 lane->releaseVehicles();
862 if (lane->getVehicleNumber() == 1 && joinVehicle !=
"") {
863 std::vector<MSVehicle*> vehs = lane->getVehiclesSecure();
864 const bool ignoreJoinTarget = vehs.front()->getID() == joinVehicle && vehs.front()->isStopped();
865 lane->releaseVehicles();
866 if (ignoreJoinTarget) {
867 #ifdef DEBUG_SIGNALSTATE
869 std::cout <<
" ignore join-target '" << joinVehicle <<
";\n";
886 for (
MSLane* lane : myBidiExtended) {
887 if (!lane->empty()) {
888 assert(myBidi.size() != 0);
889 const MSEdge* lastBidi = myBidi.back()->getNextNormal();
890 MSVehicle* foe = lane->getVehiclesSecure().front();
891 #ifdef DEBUG_SIGNALSTATE
893 std::cout <<
" check for deadlock with " << foe->
getID() <<
"\n";
898 const int minEdges = (int)myBidiExtended.size();
901 bool conflict =
false;
902 for (
int i = 0; i < minEdges && foeIt != foeEnd; i++) {
903 if ((*foeIt) == lastBidi) {
904 #ifdef DEBUG_SIGNALSTATE
906 std::cout <<
" vehicle will enter " << lastBidi->
getID() <<
"\n";
914 lane->releaseVehicles();
929 double flankApproachingDist = std::numeric_limits<double>::max();
932 flankApproachingDist = closest.second.dist;
934 #ifdef DEBUG_FIND_PROTECTION
936 std::cout <<
SIMTIME <<
" findProtection for link=" << link->
getDescription() <<
" flankApproachingDist=" << flankApproachingDist <<
"\n";
940 if (l2->getLane() != link->
getLane()) {
941 #ifdef DEBUG_FIND_PROTECTION
943 std::cout <<
" protectionCandidate=" << l2->getDescription() <<
" l2Via=" <<
Named::getIDSecure(l2->getViaLane())
944 <<
" occupied=" << (l2->getViaLane() !=
nullptr && !l2->getViaLane()->isEmpty()) <<
"\n";
947 if (l2->getViaLane() !=
nullptr && !l2->getViaLane()->isEmpty()) {
948 #ifdef DEBUG_FIND_PROTECTION
950 std::cout <<
" protection from internal=" << l2->getViaLane()->getID() <<
"\n";
955 if (l2->getApproaching().size() > 0) {
957 if (closest2.second.dist < flankApproachingDist) {
958 #ifdef DEBUG_FIND_PROTECTION
960 std::cout <<
" protection from veh=" << closest2.first->getID() <<
"\n";
985 return tmp.
reserve(veh, occupied);
992 for (
int i = 0; i < myCoreSize; i++) {
994 const MSEdge* edge = myRoute[i];
1008 for (
const MSLane* lane : myForward) {
1010 if (lane == lane2) {
1015 if (lane == lane2) {
1027 if (myCoreSize != (
int)myRoute.size()) {
1035 if (myBidiExtended.size() > 0) {
1045 od.
openTag(
"protectingSwitches");
1046 std::vector<std::string> links;
1047 for (
MSLink* link : myProtectingSwitches) {
1054 std::vector<std::string> signals;
1055 for (
MSLink* link : myConflictLinks) {
1068 bool seekForwardSignal =
true;
1069 bool seekBidiSwitch =
true;
1070 bool foundUnsafeSwitch =
false;
1072 #ifdef DEBUG_DRIVEWAY_BUILDROUTE
1077 while ((seekForwardSignal || seekBidiSwitch)) {
1081 " exceeds maximum length (stopped searching after edge '" + toLane->
getEdge().
getID() +
"' (length=" +
toString(length) +
"m).");
1087 #ifdef DEBUG_DRIVEWAY_BUILDROUTE
1092 if (visited.count(toLane) != 0) {
1098 myRoute.push_back(&toLane->
getEdge());
1103 visited[toLane] = (int)visited.size();
1106 if (seekForwardSignal) {
1107 if (!foundUnsafeSwitch) {
1108 myForward.push_back(toLane);
1110 }
else if (bidi ==
nullptr) {
1111 seekBidiSwitch =
false;
1112 #ifdef DEBUG_DRIVEWAY_BUILDROUTE
1114 std::cout <<
" noBidi, abort search for bidiSwitch\n";
1118 if (bidi !=
nullptr) {
1119 if (foundUnsafeSwitch) {
1120 myBidiExtended.push_back(bidi);
1122 myBidi.push_back(bidi);
1124 visited[bidi] = (int)visited.size();
1125 if (!seekForwardSignal) {
1131 for (
const MSLink*
const link : ili.lane->getLinkCont()) {
1135 if (link->getViaLaneOrLane() != bidi) {
1139 myCoreSize = (int)myRoute.size();
1141 #ifdef DEBUG_DRIVEWAY_BUILDROUTE
1143 std::cout <<
" abort: found protecting switch " << ili.viaLink->getDescription() <<
"\n";
1148 myProtectedBidi = bidiNext;
1151 #ifdef DEBUG_DRIVEWAY_BUILDROUTE
1153 std::cout <<
" found unsafe switch " << ili.viaLink->getDescription() <<
" (used=" << bidiNext->
getID() <<
")\n";
1158 foundUnsafeSwitch =
true;
1162 myFlankSwitches.push_back(ili.viaLink);
1171 const std::vector<MSLink*>& links = toLane->
getLinkCont();
1174 for (
const MSLink*
const link : links) {
1175 if (((next != end && &link->getLane()->getEdge() == *next) ||
1177 &&
isRailway(link->getViaLaneOrLane()->getPermissions())) {
1178 toLane = link->getViaLaneOrLane();
1179 if (link->getLane()->getBidiLane() !=
nullptr && &link->getLane()->getEdge() == current->
getBidiEdge()) {
1181 #ifdef DEBUG_DRIVEWAY_BUILDROUTE
1183 std::cout <<
" abort: turn-around\n";
1188 if (link->getTLLogic() !=
nullptr) {
1189 if (link->getTLLogic() == origin->
getTLLogic()) {
1194 seekForwardSignal =
false;
1195 seekBidiSwitch = bidi !=
nullptr;
1196 #ifdef DEBUG_DRIVEWAY_BUILDROUTE
1198 std::cout <<
" found forwardSignal " << link->getTLLogic()->
getID() <<
" seekBidiSwitch=" << seekBidiSwitch <<
"\n";
1205 if (toLane ==
nullptr) {
1208 toLane = (*next)->getLanes()[0];
1210 #ifdef DEBUG_DRIVEWAY_BUILDROUTE
1212 std::cout <<
" abort: no next lane available\n";
1224 #ifdef DEBUG_CHECK_FLANKS
1225 std::cout <<
" checkFlanks lanes=" <<
toString(lanes) <<
"\n visited=" <<
formatVisitedMap(visited) <<
" allFoes=" << allFoes <<
"\n";
1227 for (
MSLane* lane : lanes) {
1228 if (lane->isInternal()) {
1231 for (
auto ili : lane->getIncomingLanes()) {
1232 if (visited.count(ili.lane->getNormalPredecessorLane()) == 0) {
1233 #ifdef DEBUG_CHECK_FLANKS
1234 std::cout <<
" add flankSwitch junction=" << ili.viaLink->getJunction()->getID() <<
" index=" << ili.viaLink->getIndex() <<
"\n";
1236 myFlankSwitches.push_back(ili.viaLink);
1237 }
else if (allFoes) {
1239 checkCrossingFlanks(ili.viaLink, visited);
1248 #ifdef DEBUG_CHECK_FLANKS
1252 if (junction ==
nullptr) {
1256 if (logic ==
nullptr) {
1260 if (in->isInternal()) {
1263 for (
MSLane* inLane : in->getLanes()) {
1264 if (
isRailway(inLane->getPermissions()) && visited.count(inLane) == 0) {
1265 for (
MSLink* link : inLane->getLinkCont()) {
1266 if (link->getIndex() >= 0 && logic->
getFoesFor(dwLink->
getIndex()).test(link->getIndex())
1267 && visited.count(link->getLane()) == 0) {
1268 #ifdef DEBUG_CHECK_FLANKS
1269 std::cout <<
" add crossing flankSwitch junction=" << junction->
getID() <<
" index=" << link->getIndex() <<
"\n";
1271 if (link->getViaLane() ==
nullptr) {
1272 myFlankSwitches.push_back(link);
1274 myFlankSwitches.push_back(link->getViaLane()->getLinkCont().front());
1285 #ifdef DEBUG_CHECK_FLANKS
1286 std::cout <<
" findFlankProtection link=" << link->
getDescription() <<
" length=" << length <<
" origLink=" << origLink->
getDescription() <<
"\n";
1290 #ifdef DEBUG_CHECK_FLANKS
1291 std::cout <<
" flank guarded by " << link->
getTLLogic()->
getID() <<
"\n";
1293 myConflictLinks.push_back(link);
1303 const bool isNew = visited.count(lane) == 0;
1304 if (isNew || (visited[lane] > visited[origLink->
getLane()] && std::find(myForward.begin(), myForward.end(), lane) == myForward.end())) {
1306 visited[lane] = (int)visited.size();
1310 myFlank.push_back(lane);
1311 findFlankProtection(lane->
getIncomingLanes().front().viaLink, length, visited, origLink);
1313 bool foundPSwitch =
false;
1315 #ifdef DEBUG_CHECK_FLANKS
1316 std::cout <<
" lane=" << lane->
getID() <<
" visitedIndex=" << visited[lane] <<
" origIndex=" << visited[origLink->
getLane()] <<
" cand=" << l2->getDescription() <<
"\n";
1319 foundPSwitch =
true;
1321 #ifdef DEBUG_CHECK_FLANKS
1322 std::cout <<
" protectingSwitch=" << l2->getDescription() <<
" for flank=" << link->
getDescription() <<
"\n";
1324 myProtectingSwitches.push_back(link);
1327 if (!foundPSwitch) {
1328 myFlank.push_back(lane);
1332 findFlankProtection(ili.viaLink, length, visited, origLink);
1338 #ifdef DEBUG_CHECK_FLANKS
1339 std::cout <<
" laneBefore=" << lane->
getID() <<
" already visited. index=" << visited[lane] <<
" origAfter=" << origLink->
getLane()->
getID() <<
" origIndex=" << visited[origLink->
getLane()] <<
"\n";
1343 myMaxFlankLength =
MAX2(myMaxFlankLength, length);
1359 driveway.
reserve(closest, occupied);
1394 for (
const DriveWay& dw : li.myDriveways) {
1409 if (item.second < item2.second) {
1410 bool conflict =
false;
1411 std::pair<int, int> code(item.second, item2.second);
1414 conflict = it->second;
1424 #ifdef DEBUG_RECHECKGREEN
1435 state[item.first->getTLIndex()] =
'r';
1438 #ifdef DEBUG_RECHECKGREEN
1440 <<
" (" << veh.first->getID() <<
" yields to " << veh2.first->getID() <<
"\n";
1442 #ifdef DEBUG_SIGNALSTATE
1445 <<
" (" << veh.first->getID() <<
" yields to " << veh2.first->getID() <<
"\n";
1450 state[item2.first->getTLIndex()] =
'r';
1453 #ifdef DEBUG_RECHECKGREEN
1455 <<
" (" << veh2.first->getID() <<
" yields to " << veh.first->getID() <<
"\n";
1457 #ifdef DEBUG_SIGNALSTATE
1460 <<
" (" << veh2.first->getID() <<
" yields to " << veh.first->getID() <<
"\n";
1475 for (
auto it = li.myDriveways.begin(); it != li.myDriveways.end(); it++) {
1478 #ifdef DEBUG_DRIVEWAY_UPDATE
1479 std::cout <<
SIMTIME <<
" rail signal junction '" <<
getID() <<
"' requires update for driveway " << numericalID <<
"\n";
1481 std::vector<const MSEdge*> route = dw.
myRoute;
1482 li.myDriveways.erase(it);
1483 if (li.myDriveways.size() == 0) {
1485 li.myDriveways.push_back(li.buildDriveWay(route.begin(), route.end()));
1500 for (
int i = 0; i < (int)
myLinkInfos.size(); i++) {
1513 for (
int i = 0; i < (int)
myLinkInfos.size(); i++) {
1526 for (
int i = 0; i < (int)
myLinkInfos.size(); i++) {
1539 for (
int i = 0; i < (int)
myLinkInfos.size(); i++) {
1549 if (key ==
"moving-block") {
std::vector< const MSEdge * > ConstMSEdgeVector
std::vector< MSEdge * > MSEdgeVector
#define DEBUG_COND_LINKINFO
#define DEBUG_HELPER(obj)
#define MAX_SIGNAL_WARNINGS
ConstMSEdgeVector::const_iterator MSRouteIterator
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t)
convert SUMOTime to string
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
@ TURN
The link is a 180 degree turn.
@ LINKSTATE_TL_RED
The link has red light (must brake)
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_TLLINKINDEX
link: the index of the link within the traffic light
#define SUMO_MAX_CONNECTIONS
the maximum number of connections across an intersection
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
const MSRoute & getRoute() const
Returns the current route.
A device that performs vehicle rerouting based on current edge speeds.
SUMOTime getPeriod() const
bool mayRerouteRailSignal() const
return whether the equipped vehicle may receive dispatch information at a rail signal
A road/street connecting two junctions.
bool isNormal() const
return whether this edge is an internal edge
const MSJunction * getFromJunction() const
double getLength() const
return the length of the edge
const MSJunction * getToJunction() const
const MSEdge * getBidiEdge() const
return opposite superposable/congruent edge, if it exist and 0 else
The base class for an intersection.
const ConstMSEdgeVector & getIncoming() const
SumoXMLNodeType getType() const
return the type of this Junction
virtual const MSJunctionLogic * getLogic() const
virtual const MSLogicJunction::LinkBits & getFoesFor(int linkIndex) const
Returns the foes for the given link.
Representation of a lane in the micro simulation.
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
MSVehicle * getFirstAnyVehicle() const
returns the first vehicle that is fully or partially on this lane
const MSEdge * getNextNormal() const
Returns the lane's follower if it is an internal lane, the edge of the lane otherwise.
double getLength() const
Returns the lane's length.
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
MSEdge & getEdge() const
Returns the lane's edge.
MSLane * getBidiLane() const
retrieve bidirectional lane or nullptr
LinkState getState() const
Returns the current state of the link.
MSLane * getLane() const
Returns the connected lane.
MSLane * getViaLaneOrLane() const
return the via lane if it exists and the lane otherwise
int getIndex() const
Returns the respond index (for visualization)
int getTLIndex() const
Returns the TLS index.
ApproachingVehicleInformation getApproaching(const SUMOVehicle *veh) const
const MSLane * getLaneBefore() const
return the internalLaneBefore if it exists and the laneBefore otherwise
std::string getDescription() const
get string description for this link
const MSTrafficLightLogic * getTLLogic() const
Returns the TLS index.
MSJunction * getJunction() const
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
The definition of a single phase of a tls logic.
const std::string & getState() const
Returns the state within this phase.
void setState(const std::string &_state)
A base class for constraints.
virtual std::string getDescription() const
virtual bool cleared() const =0
whether the constraint has been met
void addSignal(MSRailSignal *signal)
const std::set< const MSEdge * > & getUsedEdges() const
static MSRailSignalControl & getInstance()
void registerProtectedDriveway(MSRailSignal *rs, int driveWayID, const MSEdge *protectedBidi)
mark driveway that must receive additional checks if protectedBidi is ever used by a train route
bool constraintsAllow(const SUMOVehicle *veh) const
whether the given vehicle is free to drive
static VehicleVector myRivalVehicles
std::string getBlockingVehicleIDs() const
int getIndexFromOffset(SUMOTime offset) const
Returns the step (the phasenumber) of a given position of the cycle.
Phases myPhases
The list of phases this logic uses.
std::string getConstraintInfo(int linkIndex)
return information regarding active rail signal constraints for the closest approaching vehicle
std::map< std::string, std::vector< MSRailSignalConstraint * > > myInsertionConstraints
static VehicleVector myPriorityVehicles
int myPhaseIndex
MSTrafficLightLogic requires that the phase index changes whenever signals change their state.
int getPhaseNumber() const
Returns the number of phases.
static std::string myConstraintInfo
MSPhaseDefinition myCurrentPhase
The current phase.
void addConstraint(const std::string &tripId, MSRailSignalConstraint *constraint)
register contraint for signal switching
static std::string getClickableTLLinkID(MSLink *link)
return logicID_linkIndex in a way that allows clicking in sumo-gui
std::vector< LinkInfo > myLinkInfos
data storage for every link at this node (more than one when directly guarding a switch)
std::string getPriorityVehicleIDs() const
static int myDriveWayIndex
static std::string describeLinks(std::vector< MSLink * > links)
print link descriptions
VehicleVector getRivalVehicles(int linkIndex)
return vehicles that approach the intersection/rail signal and are in conflict with vehicles that wis...
void writeBlocks(OutputDevice &od) const
write rail signal block output for all links and driveways
~MSRailSignal()
Destructor.
VehicleVector getPriorityVehicles(int linkIndex)
return vehicles that approach the intersection/rail signal and have priority over vehicles that wish ...
const Phases & getPhases() const
Returns the phases of this tls program.
static VehicleVector myBlockingVehicles
void storeTraCIVehicles(int linkIndex)
update vehicle lists for traci calls
SUMOTime getOffsetFromIndex(int index) const
Returns the position (start of a phase during a cycle) from of a given step.
static Approaching getClosest(MSLink *link)
get the closest vehicle approaching the given link
void setParameter(const std::string &key, const std::string &value)
Sets a parameter and updates internal constants.
std::map< std::string, std::vector< MSRailSignalConstraint * > > myConstraints
map from tripId to constraint list
static std::map< std::pair< int, int >, bool > myDriveWayCompatibility
std::pair< const SUMOVehicle *const, const MSLink::ApproachingVehicleInformation > Approaching
SUMOTime trySwitch()
Switches to the next phase.
static void recheckGreen()
final check for driveway compatibility of signals that switched green in this step
static std::string getJunctionLinkID(MSLink *link)
return junctionID_junctionLinkIndex
const DriveWay & retrieveDriveWay(int numericalID) const
static bool myStoreVehicles
void addInsertionConstraint(const std::string &tripId, MSRailSignalConstraint *constraint)
register contraint for vehicle insertion
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
std::map< const MSLane *, int, ComparatorNumericalIdLess > LaneVisitedMap
bool myMovingBlock
whether the signal is in moving block mode (only protects from oncoming and flanking trains)
bool removeConstraint(const std::string &tripId, MSRailSignalConstraint *constraint)
remove contraint for signal switching
static std::vector< std::pair< MSLink *, int > > mySwitchedGreenFlanks
list of signals that switched green along with driveway index
void addLink(MSLink *link, MSLane *lane, int pos)
Adds a link on building.
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const
Returns the index of the logic at the given simulation step.
MSRailSignal(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, SUMOTime delay, const std::map< std::string, std::string > ¶meters)
Constructor.
void init(NLDetectorBuilder &nb)
Initialises the rail signal with information about adjacent rail signals.
void updateDriveway(int numericalID)
update driveway for extended deadlock protection
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
std::string getConstraintInfo() const
static std::string formatVisitedMap(const LaneVisitedMap &visited)
print link descriptions
void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
VehicleVector getBlockingVehicles(int linkIndex)
return vehicles that block the intersection/rail signal for vehicles that wish to pass the given link...
void updateCurrentPhase()
returns the state of the signal that actually required
static bool hasOncomingRailTraffic(MSLink *link)
std::string getRivalVehicleIDs() const
int getCurrentPhaseIndex() const
Returns the current index within the program.
static bool hasInsertionConstraint(MSLink *link, const MSVehicle *veh, std::string &info)
static std::string getTLLinkID(MSLink *link)
return logicID_linkIndex
MSRouteIterator end() const
Returns the end of the list of edges to pass.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
const ConstMSEdgeVector & getEdges() const
static void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const std::string &info, const bool onInit=false, const bool silent=false, const MSEdgeVector &prohibited=MSEdgeVector())
initiate the rerouting, create router / thread pool on first use
A class that stores and controls tls and switching of their programs.
The parent class for traffic light logics.
virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
std::vector< const SUMOVehicle * > VehicleVector
list of vehicles
SUMOTime myDefaultCycleTime
The cycle time (without changes)
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
int myNumLinks
number of controlled links
bool setTrafficLightSignals(SUMOTime t) const
Applies the current signal states to controlled links.
virtual void addLink(MSLink *link, MSLane *lane, int pos)
Adds a link on building.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index.
Representation of a vehicle in the micro simulation.
Builds detectors for microsim.
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
const std::string & getID() const
Returns the id.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
void lf()
writes a line feed if applicable
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
Representation of a vehicle.
virtual const MSRoute & getRoute() const =0
Returns the current route.
virtual MSVehicleDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or 0.
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
virtual int getRoutePosition() const =0
return index of edge within route
Definition of vehicle stop (position and duration)
std::string join
the id of the vehicle (train portion) to which this vehicle shall be joined
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
void checkFlanks(const std::vector< MSLane * > &lanes, const LaneVisitedMap &visited, bool allFoes)
find switches that threathen this driveway
void writeBlocks(OutputDevice &od) const
Write block items for this driveway.
void buildRoute(MSLink *origin, double length, MSRouteIterator next, MSRouteIterator end, LaneVisitedMap &visited)
std::vector< MSLink * > myFlankSwitches
int myCoreSize
number of edges in myRoute where overlap with other driveways is forbidden
bool deadlockLaneOccupied(bool store=true) const
whether any of myBidiExtended is occupied by a vehicle that targets myBidi
const MSEdge * myProtectedBidi
switch assumed safe from bidi-traffic
std::vector< const MSLane * > myConflictLanes
the lanes that must be clear of trains before this signal can switch to green
bool overlap(const DriveWay &other) const
Wether this driveway (route) overlaps with the given one.
int myNumericalID
global driveway index
std::vector< MSLink * > myConflictLinks
void checkCrossingFlanks(MSLink *dwLink, const LaneVisitedMap &visited)
find links that cross the driveway without entering it
std::vector< MSLane * > myBidi
void findFlankProtection(MSLink *link, double length, LaneVisitedMap &visited, MSLink *origLink)
find upstream protection from the given link
bool conflictLaneOccupied(const std::string &joinVehicle="", bool store=true) const
whether any of myConflictLanes is occupied (vehicles that are the target of a join must be ignored)
std::vector< const MSLane * > myFlank
std::vector< const MSEdge * > myRoute
list of edges for matching against train routes
bool hasLinkConflict(const Approaching &closest, MSLink *foeLink) const
Whether the approaching vehicle is prevent from driving by another vehicle approaching the given link...
bool findProtection(const Approaching &veh, MSLink *link) const
find protection for the given vehicle starting at a switch
std::vector< MSLink * > myProtectingSwitches
std::vector< MSLane * > myForward
bool conflictLinkApproached() const
Whether any of the conflict linkes have approaching vehicles.
bool reserve(const Approaching &closest, MSEdgeVector &occupied)
attempt reserve this driveway for the given vehicle
bool flankConflict(const DriveWay &other) const
Wether there is a flank conflict with the given driveway.
static bool mustYield(const Approaching &veh, const Approaching &foe)
Whether veh must yield to the foe train.
void reroute(SUMOVehicle *veh, const MSEdgeVector &occupied)
try rerouting vehicle if reservation failed
DriveWay buildDriveWay(MSRouteIterator first, MSRouteIterator end)
construct a new driveway by searching along the given route until all block structures are found
DriveWay & getDriveWay(const SUMOVehicle *)
retrieve an existing Driveway or construct a new driveway based on the vehicles route
void reset()
init LinkInfo
LinkInfo(MSLink *link)
constructor
std::vector< DriveWay > myDriveways
all driveways immediately following this link
std::string getID() const
return id for this railsignal-link