38 #define HEIGH_WEIGHT 2
39 #define LOW_WEIGHT .5;
41 #define MIN_GREEN_TIME 5
54 const std::vector<NBNode*>& junctions,
SUMOTime offset,
57 myHaveSinglePhase(false),
65 myHaveSinglePhase(false),
73 myHaveSinglePhase(false),
106 for (
int e1l = 0; e1l < e1->
getNumLanes(); e1l++) {
108 for (
int e2l = 0; e2l < e2->
getNumLanes(); e2l++) {
110 for (std::vector<NBEdge::Connection>::iterator e1c = approached1.begin(); e1c != approached1.end(); ++e1c) {
114 for (std::vector<NBEdge::Connection>::iterator e2c = approached2.begin(); e2c != approached2.end(); ++e2c) {
118 const double sign = (
forbids(e1, (*e1c).toEdge, e2, (*e2c).toEdge,
true)
119 ||
forbids(e2, (*e2c).toEdge, e1, (*e1c).toEdge,
true)) ? -1 : 1;
141 #ifdef DEBUG_STREAM_ORDERING
142 if (
DEBUGCOND && DEBUGEDGE(e2) && DEBUGEDGE(e1)) {
143 std::cout <<
" sign=" << sign <<
" w1=" << w1 <<
" w2=" << w2 <<
" val=" << val
144 <<
" c1=" << (*e1c).getDescription(e1)
145 <<
" c2=" << (*e2c).getDescription(e2)
153 #ifdef DEBUG_STREAM_ORDERING
154 if (
DEBUGCOND && DEBUGEDGE(e2) && DEBUGEDGE(e1)) {
155 std::cout <<
" computeUnblockedWeightedStreamNumber e1=" << e1->
getID() <<
" e2=" << e2->
getID() <<
" val=" << val <<
"\n";
162 std::pair<NBEdge*, NBEdge*>
164 std::pair<NBEdge*, NBEdge*> bestPair(
static_cast<NBEdge*
>(
nullptr),
static_cast<NBEdge*
>(
nullptr));
165 double bestValue = -std::numeric_limits<double>::max();
166 for (EdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
167 for (EdgeVector::const_iterator j = i + 1; j != edges.end(); ++j) {
169 if (value > bestValue) {
171 bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
172 }
else if (value == bestValue) {
174 const double oa =
GeomHelper::getMinAngleDiff(bestPair.first->getAngleAtNode(bestPair.first->getToNode()), bestPair.second->getAngleAtNode(bestPair.second->getToNode()));
175 if (fabs(oa - ca) < NUMERICAL_EPS) {
176 if (bestPair.first->getID() < (*i)->getID()) {
177 bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
179 }
else if (oa < ca) {
180 bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
185 if (bestValue <= 0) {
187 bestPair.second =
nullptr;
190 #ifdef DEBUG_STREAM_ORDERING
199 std::pair<NBEdge*, NBEdge*>
201 if (incoming.size() == 1) {
203 std::pair<NBEdge*, NBEdge*> ret(*incoming.begin(),
static_cast<NBEdge*
>(
nullptr));
211 used.push_back(*incoming.begin());
214 for (EdgeVector::iterator i = incoming.begin() + 1; i != incoming.end() && prio ==
getToPrio(*i); ++i) {
218 if (used.size() < 2) {
222 #ifdef DEBUG_STREAM_ORDERING
228 incoming.erase(find(incoming.begin(), incoming.end(), ret.first));
229 if (ret.second !=
nullptr) {
230 incoming.erase(find(incoming.begin(), incoming.end(), ret.second));
252 std::vector<bool> isTurnaround;
253 std::vector<bool> hasTurnLane;
254 std::vector<int> fromLanes;
255 std::vector<int> toLanes;
257 for (
NBEdge*
const fromEdge : incoming) {
258 const int numLanes = fromEdge->getNumLanes();
259 for (
int i2 = 0; i2 < numLanes; i2++) {
260 bool hasLeft =
false;
261 bool hasStraight =
false;
262 bool hasRight =
false;
263 bool hasTurnaround =
false;
265 if (!fromEdge->mayBeTLSControlled(i2, approached.toEdge, approached.toLane)) {
268 fromEdges.push_back(fromEdge);
269 fromLanes.push_back(i2);
270 toLanes.push_back(approached.toLane);
271 toEdges.push_back(approached.toEdge);
272 if (approached.toEdge !=
nullptr) {
273 isTurnaround.push_back(fromEdge->isTurningDirectionAt(approached.toEdge));
275 isTurnaround.push_back(
true);
277 LinkDirection dir = fromEdge->getToNode()->getDirection(fromEdge, approached.toEdge);
285 hasTurnaround =
true;
290 if (!fromEdge->mayBeTLSControlled(i2, approached.toEdge, approached.toLane)) {
293 hasTurnLane.push_back(
294 (hasLeft && !hasStraight && !hasRight)
295 || (!hasLeft && !hasTurnaround && hasRight));
301 std::vector<NBNode::Crossing*> crossings;
303 const std::vector<NBNode::Crossing*>& c = node->getCrossings();
306 node->setCrossingTLIndices(
getID(), noLinksAll);
308 copy(c.begin(), c.end(), std::back_inserter(crossings));
309 noLinksAll += (int)c.size();
325 std::vector<int> greenPhases;
326 std::vector<bool> hadGreenMajor(noLinksAll,
false);
327 while (toProc.size() > 0) {
328 bool groupTram =
false;
329 bool groupOther =
false;
330 std::pair<NBEdge*, NBEdge*> chosen;
331 if (groupOpposites) {
332 if (incoming.size() == 2) {
335 double angle = fabs(
NBHelpers::relAngle(incoming[0]->getAngleAtNode(incoming[0]->getToNode()), incoming[1]->getAngleAtNode(incoming[1]->getToNode())));
338 chosen = std::pair<NBEdge*, NBEdge*>(toProc[0],
static_cast<NBEdge*
>(
nullptr));
339 toProc.erase(toProc.begin());
345 if (chosen.second ==
nullptr && chosen.first->getPermissions() ==
SVC_TRAM) {
347 for (
auto it = toProc.begin(); it != toProc.end();) {
348 if ((*it)->getPermissions() ==
SVC_TRAM) {
349 it = toProc.erase(it);
357 NBEdge* chosenEdge = toProc[0];
358 chosen = std::pair<NBEdge*, NBEdge*>(chosenEdge,
static_cast<NBEdge*
>(
nullptr));
359 toProc.erase(toProc.begin());
367 if (groupTram || groupOther) {
368 for (
auto it = toProc.begin(); it != toProc.end();) {
369 if ((*it)->getPermissions() == perms) {
370 it = toProc.erase(it);
378 std::string state((
int) noLinksAll,
'r');
386 bool haveGreen =
false;
387 for (
const NBEdge*
const fromEdge : incoming) {
388 const bool inChosen = fromEdge == chosen.first || fromEdge == chosen.second;
389 const int numLanes = fromEdge->getNumLanes();
390 for (
int i2 = 0; i2 < numLanes; i2++) {
392 if (!fromEdge->mayBeTLSControlled(i2, approached.toEdge, approached.toLane)) {
398 maxSpeed =
MAX2(maxSpeed, fromEdge->getSpeed());
412 std::cout <<
" state after plain straight movers " << state <<
"\n";
416 state =
allowCompatible(state, fromEdges, toEdges, fromLanes, toLanes);
419 }
else if (groupOther) {
424 std::cout <<
" state after grouping by vClass " << state <<
"\n";
428 state =
allowUnrelated(state, fromEdges, toEdges, isTurnaround, crossings);
432 std::cout <<
" state after finding allowUnrelated " << state <<
"\n";
436 bool haveForbiddenLeftMover =
false;
437 std::vector<bool> rightTurnConflicts(pos,
false);
438 std::vector<bool> mergeConflicts(pos,
false);
439 state =
correctConflicting(state, fromEdges, toEdges, isTurnaround, fromLanes, toLanes, hadGreenMajor, haveForbiddenLeftMover, rightTurnConflicts, mergeConflicts);
440 for (
int i1 = 0; i1 < pos; ++i1) {
441 if (state[i1] ==
'G') {
442 hadGreenMajor[i1] =
true;
447 std::cout <<
" state after correcting left movers=" << state <<
"\n";
451 std::vector<bool> leftGreen(pos,
false);
453 bool foundLeftTurnLane =
false;
454 for (
int i1 = 0; i1 < pos; ++i1) {
455 if (state[i1] ==
'g' && !rightTurnConflicts[i1] && !mergeConflicts[i1] && hasTurnLane[i1]) {
456 foundLeftTurnLane =
true;
459 const bool buildLeftGreenPhase = (haveForbiddenLeftMover && !
myHaveSinglePhase && leftTurnTime > 0 && foundLeftTurnLane
460 && groupOpposites && !groupTram && !groupOther);
463 for (
int i1 = 0; i1 < pos; ++i1) {
464 if (state[i1] ==
'g' && !rightTurnConflicts[i1] && !mergeConflicts[i1]
466 && (!isTurnaround[i1] || (i1 > 0 && leftGreen[i1 - 1]))) {
467 leftGreen[i1] =
true;
468 if (fromEdges[i1]->getSpeed() > minorLeftSpeedThreshold) {
469 if (buildLeftGreenPhase) {
472 }
else if (!isTurnaround[i1]) {
473 WRITE_WARNINGF(
"Minor green from edge '%' to edge '%' exceeds %m/s. Maybe a left-turn lane is missing.",
474 fromEdges[i1]->
getID(), toEdges[i1]->
getID(), minorLeftSpeedThreshold);
482 std::cout <<
getID() <<
" state=" << state <<
" buildLeft=" << buildLeftGreenPhase <<
" hFLM=" << haveForbiddenLeftMover <<
" turnLane=" << foundLeftTurnLane
483 <<
" \nrtC=" <<
toString(rightTurnConflicts)
484 <<
" \nmC=" <<
toString(mergeConflicts)
485 <<
" \nhTL=" <<
toString(hasTurnLane)
491 const std::string vehicleState = state;
492 greenPhases.push_back((
int)logic->
getPhases().size());
495 const double minDurBySpeed = maxSpeed * 3.6 / 6 - 3.3;
497 if (chosen.first->getPermissions() ==
SVC_TRAM && (chosen.second ==
nullptr || chosen.second->getPermissions() ==
SVC_TRAM)) {
500 bool tramExclusive =
true;
501 for (
int i1 = 0; i1 < (int)fromEdges.size(); ++i1) {
502 if (state[i1] ==
'G') {
503 SVCPermissions linkPerm = (fromEdges[i1]->getPermissions() & toEdges[i1]->getPermissions());
505 tramExclusive =
false;
516 state =
addPedestrianPhases(logic, greenTime, minDur, maxDur, state, crossings, fromEdges, toEdges);
518 for (
int i1 = pos; i1 < pos + (int)crossings.size(); ++i1) {
521 if (brakingTime > 0) {
523 for (
int i1 = 0; i1 < pos; ++i1) {
524 if (state[i1] !=
'G' && state[i1] !=
'g') {
527 if ((vehicleState[i1] >=
'a' && vehicleState[i1] <=
'z')
528 && buildLeftGreenPhase
529 && !rightTurnConflicts[i1]
530 && !mergeConflicts[i1]
537 logic->
addStep(brakingTime, state);
546 if (buildLeftGreenPhase) {
548 for (
int i1 = 0; i1 < pos; ++i1) {
549 if (state[i1] ==
'Y' || state[i1] ==
'y') {
557 state =
allowCompatible(state, fromEdges, toEdges, fromLanes, toLanes);
558 state =
correctConflicting(state, fromEdges, toEdges, isTurnaround, fromLanes, toLanes, hadGreenMajor, haveForbiddenLeftMover, rightTurnConflicts, mergeConflicts);
561 logic->
addStep(leftTurnTime, state, minDur, maxDur);
564 if (brakingTime > 0) {
565 for (
int i1 = 0; i1 < pos; ++i1) {
566 if (state[i1] !=
'G' && state[i1] !=
'g') {
572 logic->
addStep(brakingTime, state);
579 if (crossings.size() > 0) {
583 if (logic->
getPhases().size() == 2 && brakingTime > 0
586 logic->
addStep(redTime, std::string(noLinksAll,
'r'));
589 if (crossings.size() > 0 && !onlyConts) {
604 for (std::vector<int>::const_iterator it = greenPhases.begin(); it != greenPhases.end(); ++it) {
606 greenPhaseTime += dur;
607 minGreenDuration =
MIN2(minGreenDuration, dur);
609 const int patchSeconds = (int)(
STEPS2TIME(cycleTime - totalDuration) / greenPhases.size());
610 const int patchSecondsRest = (int)(
STEPS2TIME(cycleTime - totalDuration)) - patchSeconds * (
int)greenPhases.size();
614 || greenPhases.size() == 0) {
620 for (std::vector<int>::const_iterator it = greenPhases.begin(); it != greenPhases.end(); ++it) {
623 if (greenPhases.size() > 0) {
633 if (totalDuration > 0) {
634 if (totalDuration > 3 * (greenTime + 2 * brakingTime + leftTurnTime)) {
649 for (
auto c : crossings) {
653 for (EdgeVector::const_iterator it_e = cross.
edges.begin(); it_e != cross.
edges.end(); ++it_e) {
654 const NBEdge* edge = *it_e;
655 if (edge == from || edge == to) {
668 std::string state,
const std::vector<NBNode::Crossing*>& crossings,
const EdgeVector& fromEdges,
const EdgeVector& toEdges) {
673 const std::string orig = state;
677 logic->
addStep(greenTime, state, minDur, maxDur);
679 const SUMOTime pedTime = greenTime - pedClearingTime;
680 if (pedTime >= minPedTime) {
682 const int pedStates = (int)crossings.size();
683 logic->
addStep(pedTime, state, minDur, maxDur);
684 state = state.substr(0, state.size() - pedStates) + std::string(pedStates,
'r');
685 logic->
addStep(pedClearingTime, state);
689 logic->
addStep(greenTime, state, minDur, maxDur);
698 std::string result = state;
699 const int pos = (int)(state.size() - crossings.size());
700 for (
int ic = 0; ic < (int)crossings.size(); ++ic) {
701 const int i1 = pos + ic;
706 if (fromEdges[i2] != 0 && toEdges[i2] != 0 && fromEdges[i2]->getToNode() == cross.
node) {
707 for (EdgeVector::const_iterator it = cross.
edges.begin(); it != cross.
edges.end(); ++it) {
710 if (state[i2] !=
'r' && state[i2] !=
's' && (edge == fromEdges[i2] ||
726 for (
int i1 = 0; i1 < pos; ++i1) {
727 if (result[i1] ==
'G') {
728 for (
int ic = 0; ic < (int)crossings.size(); ++ic) {
730 if (fromEdges[i1] != 0 && toEdges[i1] != 0 && fromEdges[i1]->getToNode() == crossing.
node) {
731 const int i2 = pos + ic;
785 (*i)->removeTrafficLight(&dummy);
796 for (EdgeVector::iterator it = result.begin(); it != result.end();) {
797 if ((*it)->getConnections().size() == 0 || (*it)->isInsideTLS()) {
798 it = result.erase(it);
809 const std::vector<int>& fromLanes,
const std::vector<int>& toLanes) {
820 const int size = (int)fromEdges.size();
821 NBEdge* greenEdge =
nullptr;
822 for (
int i1 = 0; i1 < size; ++i1) {
823 if (state[i1] ==
'G') {
824 if (greenEdge ==
nullptr) {
825 greenEdge = fromEdges[i1];
826 }
else if (greenEdge != fromEdges[i1]) {
831 if (greenEdge !=
nullptr) {
832 for (
int i1 = 0; i1 < size; ++i1) {
833 if (fromEdges[i1] == greenEdge) {
848 for (
int i1 = 0; i1 < (int)fromEdges.size(); ++i1) {
849 if (state[i1] ==
'G') {
855 bool followsChosen =
false;
856 for (
int i2 = 0; i2 < (int)fromEdges.size(); ++i2) {
857 if (state[i2] ==
'G' && fromEdges[i1] == toEdges[i2]) {
858 followsChosen =
true;
874 const std::vector<int>& fromLanes,
const std::vector<int>& toLanes) {
880 for (
int i1 = 0; i1 < (int)fromEdges.size(); ++i1) {
881 if (state[i1] ==
'G') {
884 if (
forbidden(state, i1, fromEdges, toEdges)) {
887 bool preceedsChosen =
false;
888 for (
int i2 = 0; i2 < (int)fromEdges.size(); ++i2) {
889 if (state[i2] ==
'G' && fromEdges[i2] == toEdges[i1]
890 && fromLanes[i2] == toLanes[i1]) {
891 preceedsChosen =
true;
895 if (preceedsChosen) {
907 const std::vector<bool>& isTurnaround,
908 const std::vector<NBNode::Crossing*>& crossings) {
909 for (
int i1 = 0; i1 < (int)fromEdges.size(); ++i1) {
910 if (state[i1] ==
'G') {
914 for (
int i2 = 0; i2 < (int)fromEdges.size(); ++i2) {
915 if (state[i2] ==
'G' && !isTurnaround[i2] &&
916 (
forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1],
true) ||
forbids(fromEdges[i1], toEdges[i1], fromEdges[i2], toEdges[i2],
true))) {
931 for (
int i1 = 0; i1 < (int)fromEdges.size(); ++i1) {
932 SVCPermissions linkPerm = (fromEdges[i1]->getPermissions() & toEdges[i1]->getPermissions());
933 if ((linkPerm & ~perm) == 0) {
943 for (
int i2 = 0; i2 < (int)fromEdges.size(); ++i2) {
944 if (state[i2] ==
'G' &&
foes(fromEdges[i2], toEdges[i2], fromEdges[index], toEdges[index])) {
954 const std::vector<bool>& isTurnaround,
955 const std::vector<int>& fromLanes,
956 const std::vector<int>& toLanes,
957 const std::vector<bool>& hadGreenMajor,
958 bool& haveForbiddenLeftMover,
959 std::vector<bool>& rightTurnConflicts,
960 std::vector<bool>& mergeConflicts) {
962 for (
int i1 = 0; i1 < (int)fromEdges.size(); ++i1) {
963 if (state[i1] ==
'G') {
964 for (
int i2 = 0; i2 < (int)fromEdges.size(); ++i2) {
965 if ((state[i2] ==
'G' || state[i2] ==
'g')) {
967 fromEdges[i1], toEdges[i1], fromLanes[i1], fromEdges[i2], toEdges[i2], fromLanes[i2])) {
968 rightTurnConflicts[i1] =
true;
970 if (
forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1],
true, controlledWithin) || rightTurnConflicts[i1]) {
973 if (!isTurnaround[i1] && !hadGreenMajor[i1] && !rightTurnConflicts[i1]) {
974 haveForbiddenLeftMover =
true;
976 }
else if (fromEdges[i1] == fromEdges[i2]
977 && fromLanes[i1] != fromLanes[i2]
978 && toEdges[i1] == toEdges[i2]
979 && toLanes[i1] == toLanes[i2]
980 && fromEdges[i1]->getToNode()->mergeConflictYields(fromEdges[i1], fromLanes[i1], fromLanes[i2], toEdges[i1], toLanes[i1])) {
981 mergeConflicts[i1] =
true;
987 if (state[i1] ==
'r') {
992 for (
int i2 = 0; i2 < (int)fromEdges.size(); ++i2) {
993 if (state[i2] ==
'G' && !isTurnaround[i2] &&
994 (
forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1],
true) ||
995 forbids(fromEdges[i1], toEdges[i1], fromEdges[i2], toEdges[i2],
true))) {
996 const LinkDirection foeDir = fromEdges[i2]->getToNode()->getDirection(fromEdges[i2], toEdges[i2]);
1003 if (state[i1] ==
's') {
1005 for (
int i2 = 0; i2 < (int)fromEdges.size(); ++i2) {
1006 if (state[i2] ==
'G' && !isTurnaround[i2] &&
1007 (
forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1],
true) ||
1008 forbids(fromEdges[i1], toEdges[i1], fromEdges[i2], toEdges[i2],
true))) {
1022 const std::vector<NBNode::Crossing*>& crossings,
const EdgeVector& fromEdges,
const EdgeVector& toEdges) {
1023 const int vehLinks = noLinksAll - (int)crossings.size();
1024 std::vector<bool> foundGreen(crossings.size(),
false);
1025 const std::vector<NBTrafficLightLogic::PhaseDefinition>& phases = logic->
getPhases();
1026 for (
int i = 0; i < (int)phases.size(); ++i) {
1027 const std::string state = phases[i].state;
1028 for (
int j = 0; j < (int)crossings.size(); ++j) {
1031 foundGreen[j] =
true;
1035 for (
int j = 0; j < (int)foundGreen.size(); ++j) {
1036 if (!foundGreen[j]) {
1039 if (phases.size() > 0) {
1040 bool needYellowPhase =
false;
1041 std::string state = phases.back().state;
1042 for (
int i1 = 0; i1 < vehLinks; ++i1) {
1043 if (state[i1] ==
'G' || state[i1] ==
'g') {
1045 needYellowPhase =
true;
1049 if (needYellowPhase && brakingTime > 0) {
1050 logic->
addStep(brakingTime, state);
1064 if (allRedTime > 0) {
1066 std::string allRedState = state;
1067 for (
int i1 = 0; i1 < (int)state.size(); ++i1) {
1068 if (allRedState[i1] ==
'Y' || allRedState[i1] ==
'y') {
1069 allRedState[i1] =
'r';
1072 logic->
addStep(allRedTime, allRedState);
1078 int minCustomIndex = -1;
1079 int maxCustomIndex = -1;
1082 const std::vector<NBNode::Crossing*>& c = (*i)->getCrossings();
1083 for (
auto crossing : c) {
1084 minCustomIndex =
MIN2(minCustomIndex, crossing->customTLIndex);
1085 minCustomIndex =
MIN2(minCustomIndex, crossing->customTLIndex2);
1086 maxCustomIndex =
MAX2(maxCustomIndex, crossing->customTLIndex);
1087 maxCustomIndex =
MAX2(maxCustomIndex, crossing->customTLIndex2);
1103 const int p = (int)logic->
getPhases().size();
1104 for (
int i1 = 0; i1 < n; ++i1) {
1106 for (
int i2 = 0; i2 < p; ++i2) {
1123 std::vector<bool> alwaysGreen(n,
true);
1124 for (
int i1 = 0; i1 < n; ++i1) {
1125 for (
const auto& phase : logic->
getPhases()) {
1126 if (phase.state[i1] !=
'G') {
1127 alwaysGreen[i1] =
false;
1132 const int p = (int)logic->
getPhases().size();
1133 for (
int i1 = 0; i1 < n; ++i1) {
1134 if (alwaysGreen[i1]) {
1135 for (
int i2 = 0; i2 < p; ++i2) {
1146 const int p = (int)logic->
getPhases().size();
1147 for (
int i1 = 0; i1 < n; ++i1) {
1148 if (fromEdges[i1]->isInsideTLS()) {
1149 for (
int i2 = 0; i2 < p; ++i2) {
1159 const int n = (int)state.size();
1161 for (
int i1 = 0; i1 < n; ++i1) {
1162 if (state[i1] ==
'y' && !fromEdges[i1]->isInsideTLS()) {
1163 for (
int i2 = 0; i2 < n; ++i2) {
1164 if (fromEdges[i2]->isInsideTLS()) {
1165 double gapSpeed = (toEdges[i1]->getSpeed() + fromEdges[i2]->getSpeed()) / 2;
1166 double time = fromEdges[i1]->getGeometry().back().distanceTo2D(fromEdges[i2]->getGeometry().back()) / gapSpeed;
1167 maxTime =
MAX2(maxTime, time);
1181 if (logic !=
nullptr) {
1199 int greenPhases = 0;
1200 for (
const auto& phase : tllDummy->
getPhases()) {
1201 if (phase.state.find_first_of(
"gG") != std::string::npos) {
1207 (*i)->removeTrafficLight(&dummy);
1209 return greenPhases <= 2;
#define WRITE_WARNINGF(...)
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
std::string time2string(SUMOTime t)
convert SUMOTime to string
bool isForbidden(SVCPermissions permissions)
Returns whether an edge with the given permission is a forbidden edge.
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_DELIVERY
vehicle is a small delivery vehicle
@ SVC_TRAM
vehicle is a light rail
@ SVC_PEDESTRIAN
pedestrian
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ DEFAULT
No information given; use default.
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ PARTLEFT
The link is a partial left direction.
@ RIGHT
The link is a (hard) right direction.
@ TURN
The link is a 180 degree turn.
@ LEFT
The link is a (hard) left direction.
@ STRAIGHT
The link is a straight direction.
@ PARTRIGHT
The link is a partial right direction.
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_YELLOW_MINOR
The link has yellow light, has to brake anyway.
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
@ LINKSTATE_TL_OFF_NOSIGNAL
The link is controlled by a tls which is off, not blinking, may pass.
@ TRAFFIC_LIGHT_RIGHT_ON_RED
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static double getMinAngleDiff(double angle1, double angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
The representation of a single edge during network building.
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
const std::string & getID() const
NBNode * getToNode() const
Returns the destination node of the edge.
bool setControllingTLInformation(const NBConnection &c, const std::string &tlID)
Returns if the link could be set as to be controlled.
std::vector< Connection > getConnectionsFromLane(int lane, NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
int getNumLanes() const
Returns the number of lanes.
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
NBEdge * getTurnDestination(bool possibleDestination=false) const
NBNode * getFromNode() const
Returns the origin node of the edge.
static double relAngle(double angle1, double angle2)
computes the relative angle between the two angles
A definition of a pedestrian crossing.
const NBNode * node
The parent node of this crossing.
EdgeVector edges
The edges being crossed.
Represents a single node (junction) during network building.
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
static bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane)
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
bool mustBrakeForCrossing(const NBEdge *const from, const NBEdge *const to, const Crossing &crossing) const
Returns the information whether the described flow must brake for the given crossing.
Sorts edges by their priority within the node they end at.
A traffic light logics which must be computed (only nodes/edges are given)
bool forbidden(const std::string &state, int index, const EdgeVector &fromEdges, const EdgeVector &toEdges)
whether the given index is forbidden by a green link in the current state
void fixSuperfluousYellow(NBTrafficLightLogic *logic) const
avoid yellow signal between successive green (major) phases
std::string correctConflicting(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, const std::vector< bool > &isTurnaround, const std::vector< int > &fromLanes, const std::vector< int > &toLanes, const std::vector< bool > &hadGreenMajor, bool &haveForbiddenLeftMover, std::vector< bool > &rightTurnConflicts, std::vector< bool > &mergeConflicts)
change 'G' to 'g' for conflicting connections
void checkCustomCrossingIndices(NBTrafficLightLogic *logic) const
fix states in regard to custom crossing indices
static std::string patchStateForCrossings(const std::string &state, const std::vector< NBNode::Crossing * > &crossings, const EdgeVector &fromEdges, const EdgeVector &toEdges)
compute phase state in regard to pedestrian crossings
std::string allowByVClass(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, SVCPermissions perm)
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
bool myHaveSinglePhase
Whether left-mover should not have an additional phase.
bool corridorLike() const
test whether a joined tls with layout 'opposites' would be built without dedicated left-turn phase
SUMOTime computeEscapeTime(const std::string &state, const EdgeVector &fromEdges, const EdgeVector &toEdges) const
compute time to clear all vehicles from within an alternateOneWay layout
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane, bool incoming)
Replaces a removed edge/lane.
std::pair< NBEdge *, NBEdge * > getBestPair(EdgeVector &incoming)
Returns the combination of two edges from the given which has most unblocked streams.
void collectLinks()
Collects the links participating in this traffic light.
void deactivateAlwaysGreen(NBTrafficLightLogic *logic) const
switch of signal for links that are always green
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
static bool hasCrossing(const NBEdge *from, const NBEdge *to, const std::vector< NBNode::Crossing * > &crossings)
compute whether the given connection is crossed by pedestrians
std::string allowPredecessors(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, const std::vector< int > &fromLanes, const std::vector< int > &toLanes)
void deactivateInsideEdges(NBTrafficLightLogic *logic, const EdgeVector &fromEdges) const
switch of signal for links that are inside a joined tls
double computeUnblockedWeightedStreamNumber(const NBEdge *const e1, const NBEdge *const e2)
Returns how many streams outgoing from the edges can pass the junction without being blocked.
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
int getToPrio(const NBEdge *const e)
Returns this edge's priority at the node it ends at.
std::string allowCompatible(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, const std::vector< int > &fromLanes, const std::vector< int > &toLanes)
allow connections that are compatible with the chosen edges
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
static std::string addPedestrianPhases(NBTrafficLightLogic *logic, SUMOTime greenTime, SUMOTime minDur, SUMOTime maxDur, std::string state, const std::vector< NBNode::Crossing * > &crossings, const EdgeVector &fromEdges, const EdgeVector &toEdges)
add 1 or 2 phases depending on the presence of pedestrian crossings
std::string allowFollowers(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges)
void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic *logic, const std::string &state)
double getDirectionalWeight(LinkDirection dir)
Returns the weight of a stream given its direction.
std::string allowSingleEdge(std::string state, const EdgeVector &fromEdges)
std::pair< NBEdge *, NBEdge * > getBestCombination(const EdgeVector &edges)
Returns the combination of two edges from the given which has most unblocked streams.
void initNeedsContRelation() const
NBOwnTLDef(const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
static EdgeVector getConnectedOuterEdges(const EdgeVector &incoming)
get edges that have connections
static void addPedestrianScramble(NBTrafficLightLogic *logic, int noLinksAll, SUMOTime greenTime, SUMOTime yellowTime, const std::vector< NBNode::Crossing * > &crossings, const EdgeVector &fromEdges, const EdgeVector &toEdges)
add an additional pedestrian phase if there are crossings that did not get green yet
TrafficLightLayout myLayout
the layout for generated signal plans
std::string allowUnrelated(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, const std::vector< bool > &isTurnaround, const std::vector< NBNode::Crossing * > &crossings)
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
The base class for traffic light logic definitions.
const std::string & getProgramID() const
Returns the ProgramID.
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
RightOnRedConflicts myRightOnRedConflicts
TrafficLightType myType
The algorithm type for the traffic light.
static const std::string DummyID
id for temporary definitions
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority, bool sameNodeOnly=false) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
NBConnectionVector myControlledLinks
The list of controlled links.
bool myNeedsContRelationReady
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
void collectAllLinks(NBConnectionVector &into)
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
SUMOTime myOffset
The offset in the program.
static const SUMOTime UNSPECIFIED_DURATION
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
bool myRightOnRedConflictsReady
NeedsContRelation myNeedsContRelation
A SUMO-compliant built logic for a traffic light.
SUMOTime getDuration() const
Returns the duration of the complete cycle.
void closeBuilding(bool checkVarDurations=true)
closes the building process
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
void setPhaseDuration(int phaseIndex, SUMOTime duration)
Modifies the duration for an existing phase (used by NETEDIT)
void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState)
Modifies the state for an existing phase (used by NETEDIT)
int getNumLinks()
Returns the number of participating links.
void addStep(SUMOTime duration, const std::string &state, const std::vector< int > &next=std::vector< int >(), const std::string &name="", int index=-1)
Adds a phase to the logic.
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
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.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
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 StringBijection< TrafficLightLayout > TrafficLightLayouts
traffic light layouts
T get(const std::string &str) const
A structure which describes a connection between edges or lanes.
data structure for caching needsCont information