43#define DEBUG_COND (getID()=="C")
49 "**",
"^",
"*",
"/",
"+",
"-",
"%",
50 "=",
"==",
"!=",
"<",
">",
"<=",
">=",
51 "and",
"&&",
"or",
"||",
57#define DEFAULT_MAX_GAP "3.0"
58#define DEFAULT_PASSING_TIME "1.9"
59#define DEFAULT_DETECTOR_GAP "2.0"
60#define DEFAULT_INACTIVE_THRESHOLD "180"
61#define DEFAULT_CURRENT_PRIORITY 10
63#define DEFAULT_LENGTH_WITH_GAP 7.5
65#define NO_DETECTOR "NO_DETECTOR"
71 const std::string&
id,
const std::string& programID,
76 const std::string& basePath,
81 myLastTrySwitchTime(0),
82 myConditions(conditions),
83 myAssignments(assignments),
84 myFunctions(functions),
86 myDetectorPrefix(id +
"_" + programID +
"_") {
99 std::set<std::string> hiddenSet(hidden.begin(), hidden.end());
101 if (hiddenSet.count(item.first) == 0) {
106 const bool showAll =
getParameter(
"show-conditions",
"") ==
"";
108 std::set<std::string> shownSet(shown.begin(), shown.end());
110 if (showAll || shownSet.count(item.first) != 0) {
116 const std::string extraIDs =
getParameter(
"extra-detectors",
"");
119 myExtraLoops.push_back(retrieveDetExpression<MSInductLoop, SUMO_TAG_INDUCTION_LOOP>(customID, extraIDs,
true));
121 myExtraE2.push_back(retrieveDetExpression<MSE2Collector, SUMO_TAG_LANE_AREA_DETECTOR>(customID, extraIDs,
true));
125 myStack.push_back(std::map<std::string, double>());
141 const int numLinks = (int)
myLinks.size();
164 std::map<const MSLane*, MSInductLoop*> laneInductLoopMap;
165 std::map<MSInductLoop*, int> inductLoopInfoMap;
166 int detEdgeIndex = -1;
167 int detLaneIndex = 0;
170 MSEdge* prevDetEdge =
nullptr;
172 for (
MSLane* lane : lanes) {
173 const std::string customID =
getParameter(lane->getID());
174 if (
noVehicles(lane->getPermissions()) && customID ==
"") {
178 if (laneInductLoopMap.find(lane) != laneInductLoopMap.end()) {
183 if (minDur == std::numeric_limits<SUMOTime>::max() && customID ==
"") {
187 double length = lane->getLength();
189 double inductLoopPosition;
191 if (&lane->getEdge() != prevDetEdge) {
194 prevDetEdge = &lane->getEdge();
198 if (customID ==
"") {
200 inductLoopPosition =
MIN2(
205 ilpos = length - inductLoopPosition;
206 MSLane* placementLane = lane;
207 while (ilpos < 0 && placementLane->getIncomingLanes().size() == 1
208 && placementLane->
getIncomingLanes().front().viaLink->getCorrespondingEntryLink()->getTLLogic() ==
nullptr) {
216 const double detLength =
getDouble(
"detector-length:" + lane->getID(), detDefaultLength);
224 if (loop ==
nullptr) {
225 WRITE_ERROR(
"Unknown inductionLoop '" + customID +
"' given as custom detector for actuated tlLogic '" +
getID() +
"', program '" +
getProgramID() +
".");
229 inductLoopPosition = length - ilpos;
233 laneInductLoopMap[lane] = loop;
262 std::map<int, std::set<MSInductLoop*> > linkToLoops;
263 std::set<int> actuatedLinks;
265 std::vector<bool> neverMajor(numLinks,
true);
267 const std::string& state = phase->getState();
268 for (
int i = 0; i < numLinks; i++) {
270 neverMajor[i] =
false;
274 std::vector<bool> oneLane(numLinks,
false);
275 std::vector<bool> turnaround(numLinks,
true);
276 for (
int i = 0; i < numLinks; i++) {
279 int numMotorized = 0;
281 if ((l->getPermissions() & motorized) != 0) {
285 if (numMotorized == 1) {
291 if (!link->isTurnaround()) {
292 turnaround[i] =
false;
301 std::set<MSInductLoop*> loops;
302 if (phase->isActuated()) {
303 const std::string& state = phase->getState();
305 std::set<int> greenLinks;
307 std::set<int> greenLinksPermissive;
309 std::map<MSInductLoop*, std::set<int> > loopLinks;
311 for (
int i = 0; i < numLinks; i++) {
313 greenLinks.insert(i);
314 actuatedLinks.insert(i);
316 if (((neverMajor[i] || turnaround[i])
319 greenLinks.insert(i);
320 if (!turnaround[i]) {
321 actuatedLinks.insert(i);
324 greenLinksPermissive.insert(i);
327#ifdef DEBUG_DETECTORS
329 std::cout <<
" phase=" << phaseIndex <<
" i=" << i <<
" state=" << state[i] <<
" green=" << greenLinks.count(i) <<
" oneLane=" << oneLane[i]
330 <<
" turn=" << turnaround[i] <<
" loopLanes=";
332 if (laneInductLoopMap.count(lane) != 0) {
333 std::cout << lane->getID() <<
" ";
340 if (laneInductLoopMap.count(lane) != 0) {
341 loopLinks[laneInductLoopMap[lane]].insert(i);
345 for (
auto& item : loopLinks) {
350 bool foundUsable =
false;
352 for (
int j : item.second) {
353 if (greenLinks.count(j) == 0 && (info.
jamThreshold <= 0 || greenLinksPermissive.count(j) == 0)) {
355#ifdef DEBUG_DETECTORS
357 std::cout <<
" phase=" << phaseIndex <<
" check1: loopLane=" << loopLane->
getID() <<
" notGreen=" << j <<
" oneLane[j]=" << oneLane[j] <<
"\n";
371 if (link->isTurnaround()) {
374 const MSLane* next = link->getLane();
375 if (laneInductLoopMap.count(next) != 0) {
377 for (
int j : loopLinks[nextLoop]) {
378 if (greenLinks.count(j) == 0) {
380#ifdef DEBUG_DETECTORS
381 if (
DEBUG_COND) std::cout <<
" phase=" << phaseIndex <<
" check2: loopLane=" << loopLane->
getID()
382 <<
" nextLane=" << next->
getID() <<
" nextLink=" << j <<
" nextState=" << state[j] <<
"\n";
392 loops.insert(item.first);
393#ifdef DEBUG_DETECTORS
395 std::cout <<
" phase=" << phaseIndex <<
" usableLoops=" << item.first->getID() <<
" links=" <<
joinToString(item.second,
" ") <<
"\n";
398 for (
int j : item.second) {
399 linkToLoops[j].insert(item.first);
403 if (loops.size() == 0) {
407#ifdef DEBUG_DETECTORS
409 std::cout <<
" phase=" << phaseIndex <<
" loops=" <<
joinNamedToString(loops,
" ") <<
"\n";
412 std::cout <<
" linkToLoops:\n";
413 for (
auto item : linkToLoops) {
414 std::cout <<
" link=" << item.first <<
" loops=" <<
joinNamedToString(item.second,
" ") <<
"\n";
418 std::vector<InductLoopInfo*> loopInfos;
422 if (loopInfo.loop == loop) {
424 loopInfo.servedPhase[phaseIndex] =
true;
429#ifdef DEBUG_DETECTORS
431 std::cout <<
"final linkToLoops:\n";
432 for (
auto item : linkToLoops) {
433 std::cout <<
" link=" << item.first <<
" loops=" <<
joinNamedToString(item.second,
" ") <<
"\n";
437 for (
int i : actuatedLinks) {
438 if (linkToLoops[i].size() == 0 &&
myLinks[i].size() > 0
439 && (
myLinks[i].front()->getLaneBefore()->getPermissions() & motorized) != 0) {
450 WRITE_ERROR(
"Invalid link '" + kv.first.substr(11) +
"' given as linkMaxDur parameter for actuated tlLogic '" +
getID() +
"', program '" +
getProgramID() +
".");
460 WRITE_ERROR(
"Invalid link '" + kv.first.substr(11) +
"' given as linkMinDur parameter for actuated tlLogic '" +
getID() +
"', program '" +
getProgramID() +
".");
478 step = step < 0 ?
myStep : step;
487 step = step < 0 ?
myStep : step;
496 step = step < 0 ?
myStep : step;
505 step = step < 0 ?
myStep : step;
516 for (
int i = 0; i < (int)
myPhases.size(); i++) {
518 const std::string errorSuffix =
"' for overiding attribute in phase " +
toString(i) +
" of tlLogic '" +
getID() +
"' in program '" +
getProgramID() +
"'.";
520 const std::string cond =
"minDur:" +
toString(i);
522 throw ProcessError(
"Missing condition '" + cond + errorSuffix);
526 const std::string cond =
"maxDur:" +
toString(i);
528 throw ProcessError(
"Missing condition '" + cond + errorSuffix);
532 const std::string cond =
"earliestEnd:" +
toString(i);
534 throw ProcessError(
"Missing condition '" + cond + errorSuffix);
538 const std::string cond =
"latestEnd:" +
toString(i);
540 throw ProcessError(
"Missing condition '" + cond + errorSuffix);
549 for (
int i = 0; i < (int)
myPhases.size(); i++) {
552 std::vector<int> nextPhases = phase->
nextPhases;
553 if (nextPhases.size() == 0) {
554 nextPhases.push_back((i + 1) % (int)
myPhases.size());
556 for (
int next : nextPhases) {
557 if (next >= 0 && next < (
int)
myPhases.size()) {
573 SUMOTime result = std::numeric_limits<SUMOTime>::max();
574 for (
int pI = 0; pI < (int)
myPhases.size(); pI++) {
576 const std::string& state = phase->
getState();
577 for (
int i = 0; i < (int)state.size(); i++) {
594 for (
int i = 0; i < (int)state.size(); i++) {
597 for (
MSLane* lane : lanes) {
623 loopInfo.loop->setVisible(
false);
631 if (step >= 0 && step !=
myStep) {
636 }
else if (step < 0) {
649 const SUMOTime lastSwitch = t - spentDuration;
674 if (state[i] ==
'G' || state[i] ==
'g') {
679 if (state[i] ==
'r' || state[i] ==
'u') {
689 const int origStep =
myStep;
699#ifdef DEBUG_PHASE_SELECTION
702 <<
" trySwitch dGap=" << (detectionGap == std::numeric_limits<double>::max() ?
"inf" :
toString(detectionGap))
703 <<
" multi=" << multiTarget <<
"\n";
706 if (detectionGap < std::numeric_limits<double>::max() && !multiTarget && !
myTraCISwitch) {
723 if (linkMinDur > 0) {
726 return multiTarget ?
TIME2STEPS(1) : linkMinDur;
735 myPhases[origStep]->myLastEnd = now;
743 if (loopInfo->isJammed()) {
748 loopInfo->lastGreenTime = now;
752#ifdef DEBUG_PHASE_SELECTION
774 if (newDuration % 1000 != 0) {
775 const SUMOTime totalDur = newDuration + actDuration;
776 newDuration = (totalDur / 1000 + 1) * 1000 - actDuration;
788 double result = std::numeric_limits<double>::max();
795 if (loopInfo.lastGreenTime < loopInfo.loop->getLastDetectionTime()) {
798 loopInfo.loop->setSpecialColor(
nullptr);
809#ifdef DEBUG_PHASE_SELECTION
821 if (loopInfo->isJammed()) {
827 if (actualGap < loopInfo->maxGap && !loopInfo->isJammed()) {
828 result =
MIN2(result, actualGap);
840 int result = cands.front();
848#ifdef DEBUG_PHASE_SELECTION
851 if (currentPrio > maxPrio) {
853 maxPrio = currentPrio;
856 for (
int step : cands) {
859#ifdef DEBUG_PHASE_SELECTION
872 if (prio > maxPrio) {
873 result = cands.front();
876 +
"', starvation at e1Detector '" + loopInfo.loop->getID()
877 +
"' which cannot be reached from the default phase " +
toString(
myStep) +
".");
880#ifdef DEBUG_PHASE_SELECTION
882 std::cout <<
SIMTIME <<
" p=" <<
myStep <<
" loop=" << loopInfo.loop->getID() <<
" prio=" << prio <<
" next=" << result <<
"\n";
896 while (!
myPhases[step]->isGreenPhase()) {
897 if (
myPhases[step]->nextPhases.size() > 0 &&
myPhases[step]->nextPhases.front() >= 0) {
898 if (
myPhases[step]->nextPhases.size() > 1) {
899 WRITE_WARNING(
"At actuated tlLogic '" +
getID() +
"', transition phase " +
toString(step) +
" should not have multiple next phases");
901 step =
myPhases[step]->nextPhases.front();
903 step = (step + 1) % (
int)
myPhases.size();
905 if (step == origStep) {
922#ifdef DEBUG_PHASE_SELECTION
934#ifdef DEBUG_PHASE_SELECTION
936 std::cout <<
" loop=" << loop->
getID()
940 <<
" canExtend=" << canExtend
994 const std::string& targetState =
myPhases[target]->getState();
997 targetState[i] ==
'G' || targetState[i] ==
'g')) {
1010 const std::string& targetState =
myPhases[target]->getState();
1013 && (state[i] ==
'G' || state[i] ==
'g')
1014 && !(targetState[i] ==
'G' || targetState[i] ==
'g')) {
1040 const size_t bracketOpen = condition.find(
'(');
1041 if (bracketOpen != std::string::npos) {
1043 size_t bracketClose = std::string::npos;
1045 for (
size_t i = bracketOpen + 1; i < condition.size(); i++) {
1046 if (condition[i] ==
'(') {
1048 }
else if (condition[i] ==
')') {
1056 if (bracketClose == std::string::npos) {
1057 throw ProcessError(
"Unmatched parentheses in condition " + condition +
"'");
1059 std::string cond2 = condition;
1060 const std::string inBracket = condition.substr(bracketOpen + 1, bracketClose - bracketOpen - 1);
1062 cond2.replace(bracketOpen, bracketClose - bracketOpen + 1,
toString(bracketVal));
1066 throw ProcessError(
"Error when evaluating expression '" + condition +
"':\n " + e.what());
1071 if (tokens.size() == 0) {
1072 throw ProcessError(
"Invalid empty condition '" + condition +
"'");
1073 }
else if (tokens.size() == 1) {
1077 throw ProcessError(
"Error when evaluating expression '" + condition +
"':\n " + e.what());
1079 }
else if (tokens.size() == 2) {
1080 if (tokens[0] ==
"not") {
1084 throw ProcessError(
"Error when evaluating expression '" + condition +
"':\n " + e.what());
1087 throw ProcessError(
"Unsupported condition '" + condition +
"'");
1089 }
else if (tokens.size() == 3) {
1093 const std::string& o = tokens[1];
1098 throw ProcessError(
"Error when evaluating expression '" + condition +
"':\n " + e.what());
1101 const int iEnd = (int)tokens.size() - 1;
1103 for (
int i = 1; i < iEnd; i++) {
1104 if (tokens[i] == o) {
1109 std::vector<std::string> newTokens(tokens.begin(), tokens.begin() + (i - 1));
1110 newTokens.push_back(
toString(val));
1111 newTokens.insert(newTokens.end(), tokens.begin() + (i + 2), tokens.end());
1114 throw ProcessError(
"Error when evaluating expression '" + condition +
"':\n " + e.what());
1119 throw ProcessError(
"Parsing expressions with " +
toString(tokens.size()) +
" elements ('" + condition +
"') is not supported");
1126 if (o ==
"=" || o ==
"==") {
1127 return (
double)(a == b);
1128 }
else if (o ==
"<") {
1129 return (
double)(a < b);
1130 }
else if (o ==
">") {
1131 return (
double)(a > b);
1132 }
else if (o ==
"<=") {
1133 return (
double)(a <= b);
1134 }
else if (o ==
">=") {
1135 return (
double)(a >= b);
1136 }
else if (o ==
"!=") {
1137 return (
double)(a != b);
1138 }
else if (o ==
"or" || o ==
"||") {
1139 return (
double)(a || b);
1140 }
else if (o ==
"and" || o ==
"&&") {
1141 return (
double)(a && b);
1142 }
else if (o ==
"+") {
1144 }
else if (o ==
"-") {
1146 }
else if (o ==
"*") {
1148 }
else if (o ==
"/") {
1150 WRITE_ERROR(
"Division by 0 in condition '" + condition +
"'");
1154 }
else if (o ==
"%") {
1156 }
else if (o ==
"**" || o ==
"^") {
1159 throw ProcessError(
"Unsupported operator '" + o +
"' in condition '" + condition +
"'");
1167 if ((
int)args.size() != f.
nArgs) {
1170 std::vector<double> args2;
1171 for (
auto a : args) {
1176 for (
int i = 0; i < (int)args2.size(); i++) {
1183 throw ProcessError(
"Error when evaluating function '" + fun +
"' with args '" +
joinToString(args2,
",") +
"' (" + e.what() +
")");
1185 double result =
myStack.back()[
"$0"];
1193 for (
const auto& assignment : assignments) {
1195 const std::string&
id = std::get<0>(assignment);
1197 ConditionMap::iterator it = conditions.find(
id);
1198 if (it != conditions.end()) {
1200 }
else if (forbidden.find(
id) != forbidden.end()) {
1201 throw ProcessError(
"Modifying global condition '" +
id +
"' is forbidden");
1212 if (expr.size() == 0) {
1214 }
else if (expr[0] ==
'!') {
1216 }
else if (expr[0] ==
'-') {
1220 const size_t pos = expr.find(
':');
1221 if (pos == std::string::npos) {
1228 auto it2 =
myStack.back().find(expr);
1229 if (it2 !=
myStack.back().end()) {
1236 const std::string fun = expr.substr(0, pos);
1237 const std::string arg = expr.substr(pos + 1);
1239 return retrieveDetExpression<MSInductLoop, SUMO_TAG_INDUCTION_LOOP>(arg, expr,
true)->getTimeSinceLastDetection();
1240 }
else if (fun ==
"a") {
1242 return retrieveDetExpression<MSInductLoop, SUMO_TAG_INDUCTION_LOOP>(arg, expr,
true)->getTimeSinceLastDetection() == 0;
1244 return retrieveDetExpression<MSE2Collector, SUMO_TAG_LANE_AREA_DETECTOR>(arg, expr,
true)->getCurrentVehicleNumber();
1246 }
else if (fun ==
"g" || fun ==
"r") {
1249 if (linkIndex >= 0 && linkIndex <
myNumLinks) {
1251 if (times.empty()) {
1263 return STEPS2TIME(times[linkIndex] + currentGreen);
1272 throw ProcessError(
"Invalid link index '" + arg +
"' in expression '" + expr +
"'");
1273 }
else if (fun ==
"c") {
1277 throw ProcessError(
"Unsupported function '" + fun +
"' in expression '" + expr +
"'");
1286std::map<std::string, double>
1288 std::map<std::string, double> result;
1290 result[li.loop->getID()] = li.loop->getOccupancy() > 0 ? 1 : 0;
1293 result[loop->getID()] = loop->getOccupancy() > 0 ? 1 : 0;
1296 result[loop->getID()] = loop->getCurrentVehicleNumber();
1301std::map<std::string, double>
1303 std::map<std::string, double> result;
1309 WRITE_ERROR(
"Error when retrieving conditions '" + item.first +
"' for tlLogic '" +
getID() +
"' (" + e.what() +
")");
1319 const std::string cond = key.substr(10);
1324 throw InvalidArgument(
"Unknown condition '" + cond +
"' for actuated traffic light '" +
getID() +
"'");
1334 if (key ==
"detector-gap" || key ==
"passing-time" || key ==
"file" || key ==
"freq" || key ==
"vTypes"
1337 throw InvalidArgument(key +
" cannot be changed dynamically for actuated traffic light '" +
getID() +
"'");
1338 }
else if (key ==
"max-gap") {
1346 const std::string laneID = key.substr(8);
1348 if (loopInfo.lane->getID() == laneID) {
1354 throw InvalidArgument(
"Invalid lane '" + laneID +
"' in key '" + key +
"' for actuated traffic light '" +
getID() +
"'");
1355 }
else if (key ==
"jam-threshold") {
1363 const std::string laneID = key.substr(14);
1365 if (loopInfo.lane->getID() == laneID) {
1371 throw InvalidArgument(
"Invalid lane '" + laneID +
"' in key '" + key +
"' for actuated traffic light '" +
getID() +
"'");
1372 }
else if (key ==
"show-detectors") {
1378 }
else if (key ==
"inactive-threshold") {
#define DEFAULT_DETECTOR_GAP
#define DEFAULT_PASSING_TIME
#define DEFAULT_LENGTH_WITH_GAP
#define DEFAULT_INACTIVE_THRESHOLD
#define DEFAULT_CURRENT_PRIORITY
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t)
convert SUMOTime to string
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
bool noVehicles(SVCPermissions permissions)
Returns whether an edge with the given permission forbids vehicles.
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_PEDESTRIAN
pedestrian
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SUMO_TAG_INDUCTION_LOOP
alternative tag for e1 detector
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
@ LINKSTATE_TL_REDYELLOW
The link has red light (must brake) but indicates upcoming green.
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_RED
The link has red light (must brake)
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
std::string joinNamedToString(const std::set< T *, C > &ns, const T_BETWEEN &between)
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)
static std::string checkForRelativity(const std::string &filename, const std::string &basePath)
Returns the path from a configuration so that it is accessable from the current working directory.
double myDetectorGap
The detector distance in seconds.
FunctionMap myFunctions
The loaded functions.
double myJamThreshold
The minimum continuous occupancy time to mark a detector as jammed.
double myMaxGap
The maximum gap to check in seconds.
const std::string getParameter(const std::string &key, const std::string defaultValue="") const override
try to get the value of the given parameter (including prefixed parameters)
std::vector< SwitchingRules > mySwitchingRules
~MSActuatedTrafficLightLogic()
Destructor.
std::vector< std::map< std::string, double > > myStack
The function call stack;.
double evalAtomicExpression(const std::string &expr) const
evaluate atomic expression
int getTarget(int step)
get the green phase following step
SUMOTime trySwitch() override
Switches to the next phase.
SUMOTime myLastTrySwitchTime
last time trySwitch was called
int getDetectorPriority(const InductLoopInfo &loopInfo) const
SUMOTime myFreq
The frequency for aggregating detector output.
SUMOTime getMinimumMinDuration(MSLane *lane) const
get the minimum min duration for all stretchable phases that affect the given lane
std::vector< const MSInductLoop * > myExtraLoops
extra loops for output/tracking
bool myShowDetectors
Whether the detectors shall be shown in the GUI.
std::vector< SUMOTime > myLinkMaxGreenTimes
maximum consecutive time that the given link may remain green
MSActuatedTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const SUMOTime offset, const MSSimpleTrafficLightLogic::Phases &phases, int step, SUMOTime delay, const Parameterised::Map ¶meter, const std::string &basePath, const ConditionMap &conditions=ConditionMap(), const AssignmentMap &assignments=AssignmentMap(), const FunctionMap &functions=FunctionMap())
Constructor.
void loadState(MSTLLogicControl &tlcontrol, SUMOTime t, int step, SUMOTime spentDuration) override
restores the tls state
SUMOTime getMaxDur(int step=-1) const override
AssignmentMap myAssignments
The condition assignments.
std::string myVehicleTypes
Whether detector output separates by vType.
double gapControl()
Return the minimum detection gap of all detectors if the current phase should be extended and double:...
std::vector< std::tuple< std::string, std::string, std::string > > AssignmentMap
std::set< std::string > myListedConditions
the conditions which shall be listed in GUITLLogicPhasesTrackerWindow
double evalExpression(const std::string &condition) const
evaluate custom switching condition
std::vector< SUMOTime > myLinkMinGreenTimes
minimum consecutive time that the given link must remain green
void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration) override
Changes the current phase and her duration.
static const std::vector< std::string > OPERATOR_PRECEDENCE
void deactivateProgram() override
double myPassingTime
The passing time used in seconds.
SUMOTime getLinkMinDuration(int target) const
the minimum duratin for keeping the current phase due to linkMinDur constraints
SUMOTime getMinDur(int step=-1) const override
bool canExtendLinkGreen(int target)
whether the target phase is acceptable in light of linkMaxDur constraints
InductLoopMap myInductLoopsForPhase
A map from phase to induction loops to be used for gap control.
int decideNextPhaseCustom(bool mustSwitch)
select among candidate phases based on detector states and custom switching rules
double evalTernaryExpression(double a, const std::string &o, double b, const std::string &condition) const
evaluate atomic expression
void executeAssignments(const AssignmentMap &assignments, ConditionMap &conditions, const ConditionMap &forbidden=ConditionMap()) const
execute assignemnts of the logic or a custom function
void setShowDetectors(bool show)
bool myTraCISwitch
whether the next switch time was requested via TraCI
int getPhasePriority(int step) const
count the number of active detectors for the given step
SUMOTime duration(const double detectionGap) const
Returns the minimum duration of the current phase.
void activateProgram() override
called when switching programs
std::vector< InductLoopInfo > myInductLoops
bool maxLinkDurationReached()
whether the current phase cannot be continued due to linkMaxDur constraints
double evalCustomFunction(const std::string &fun, const std::string &arg) const
evaluate function expression
void initAttributeOverride()
initialize custom switching rules
std::map< std::string, double > getConditions() const override
return all named conditions defined for this traffic light
bool hasMajor(const std::string &state, const LaneVector &lanes) const
return whether there is a major link from the given lane in the given phase
std::vector< const MSE2Collector * > myExtraE2
SUMOTime getEarliestEnd(int step=-1) const override
std::map< std::string, Function > FunctionMap
std::map< std::string, double > getDetectorStates() const override
retrieve all detectors used by this program
void setParameter(const std::string &key, const std::string &value) override
Sets a parameter and updates internal constants.
std::vector< SUMOTime > myLinkGreenTimes
consecutive time that the given link index has been green
SUMOTime getLatestEnd(int step=-1) const override
std::vector< SUMOTime > myLinkRedTimes
Parameterised::Map ConditionMap
std::string myFile
The output file for generated detectors.
void initSwitchingRules()
ConditionMap myConditions
The custom switching conditions.
const std::string myDetectorPrefix
void init(NLDetectorBuilder &nb) override
Initialises the tls with information about incoming lanes.
int decideNextPhase()
select among candidate phases based on detector states
SUMOTime myInactiveThreshold
The time threshold to avoid starved phases.
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
void add(SumoXMLTag type, MSDetectorFileOutput *d, const std::string &device, SUMOTime interval, SUMOTime begin=-1)
Adds a detector/output combination into the containers.
A road/street connecting two junctions.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
double getSpeedLimit() const
Returns the speed limit of the edge @caution The speed limit of the first lane is retured; should pro...
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
An unextended detector measuring at a fixed position on a fixed lane.
double getPosition() const
Returns the position of the detector on the lane.
virtual void setSpecialColor(const RGBColor *)
allows for special color in the gui version
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
SUMOTime getLastDetectionTime() const
return last time a vehicle was on the detector
Representation of a lane in the micro simulation.
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
double getLength() const
Returns the lane's length.
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
MSEdge & getEdge() const
Returns the lane's edge.
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
MSDetectorControl & getDetectorControl()
Returns the detector control.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
The definition of a single phase of a tls logic.
SUMOTime maxDuration
The maximum duration of the phase.
LinkState getSignalState(int pos) const
Returns the state of the tls signal at the given position.
static const SUMOTime OVERRIDE_DURATION
SUMOTime latestEnd
The maximum time within the cycle for switching (for coordinated actuation)
SUMOTime minDuration
The minimum duration of the phase.
const std::string & getState() const
Returns the state within this phase.
std::vector< int > nextPhases
The index of the phase that suceeds this one (or -1)
std::string finalTarget
The condition expression for switching into this phase when the active phase must end.
std::string earlyTarget
The condition expression for an early switch into this phase.
SUMOTime earliestEnd
The minimum time within the cycle for switching (for coordinated actuation)
A fixed traffic light logic.
SUMOTime getLatest() const
the maximum duration for keeping the current phase when considering 'latestEnd'
Phases myPhases
The list of phases this logic uses.
const MSPhaseDefinition & getPhase(int givenstep) const override
Returns the definition of the phase from the given position within the plan.
SUMOTime getEarliest(SUMOTime prevStart) const
the minimum duration for keeping the current phase when considering 'earliestEnd'
int myStep
The current step.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const override
gets a parameter
virtual void setParameter(const std::string &key, const std::string &value) override
Sets a parameter and updates internal constants.
const MSPhaseDefinition & getCurrentPhaseDef() const override
Returns the definition of the current phase.
void executeOnSwitchActions() const
A class that stores and controls tls and switching of their programs.
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
Class realising the switch between the traffic light phases.
void deschedule(MSTrafficLightLogic *tlLogic)
Marks this swicth as invalid (if the phase duration has changed, f.e.)
const LaneVector & getLanesAt(int i) const
Returns the list of lanes that are controlled by the signals at the given position.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
virtual void deactivateProgram()
SUMOTime getTimeInCycle() const
return time within the current cycle
const std::string & getProgramID() const
Returns this tl-logic's id.
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
SwitchCommand * mySwitchCommand
The current switch command.
int myNumLinks
number of controlled links
virtual void activateProgram()
called when switching programs
bool setTrafficLightSignals(SUMOTime t) const
Applies the current signal states to controlled links.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
const LinkVector & getLinksAt(int i) const
Returns the list of links that are controlled by the signals at the given position.
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index.
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
Builds detectors for microsim.
virtual MSDetectorFileOutput * createInductLoop(const std::string &id, MSLane *lane, double pos, double length, const std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons, bool show)
Creates an instance of an e1 detector using the given values.
const std::string & getID() const
Returns the id.
T get(const std::string &id) const
Retrieves an item.
static OptionsCont & getOptions()
Retrieves the options.
std::map< std::string, std::string > Map
parameters map
double getDouble(const std::string &key, const double defaultValue) const
Returns the value for a given key converted to a double.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
bool knowsParameter(const std::string &key) const
Returns whether the parameter is known.
static const RGBColor ORANGE
static const RGBColor GREEN
static const RGBColor RED
named colors
std::vector< std::string > getVector()
return vector of strings
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
AssignmentMap assignments
std::vector< bool > servedPhase