48#define INVALID_POSITION std::numeric_limits<double>::max()
58 const std::string&
id,
const std::string& programID,
62 const std::map<std::string, std::string>& parameter,
63 const std::string& basePath) :
65 myPhase(phases[0]->duration, phases[0]->getState()) {
95 if (barrierPhases.size() != 2) {
96 throw ProcessError(
TLF(
"At NEMA tlLogic '%', barrierPhases needs one phase per ring (2 values), got '%'.",
getID(), barriers));
98 if (coordinatePhases.size() != 2) {
99 throw ProcessError(
TLF(
"At NEMA tlLogic '%', coordinatePhases (or barrier2Phases) needs one phase per ring (2 values), got '%'.",
getID(), coordinates));
108 for (
int i = 0; i < (int)
rings.size(); i++) {
110 std::cout <<
"Ring" << i + 1 <<
" includes phases: \t";
111 for (
auto j :
rings[i]) {
113 std::cout << j <<
" ";
114 if (count == 2 || count == 4) {
118 std::cout << std::endl;
127 std::cout <<
"minRecall: ";
128 for (
int i = 0; i < 8; i++) {
131 std::cout << std::endl;
133 std::cout <<
"maxRecall: ";
134 for (
int i = 0; i < 8; i++) {
137 std::cout << std::endl;
143 int lastPhaseIter = 0;
145 for (
const auto& r :
rings) {
147 lastPhaseIter = phaseIter;
149 for (
const auto& p : r) {
160 if (tempPhase ==
nullptr) {
165 std::string state = tempPhase->
getState();
171 throw ProcessError(
TLF(
"At NEMA tlLogic '%', different sizes of NEMA phase states. Please check the NEMA XML",
getID()));
179 std::vector<std::string> laneIDs_vector;
180 for (std::string laneID : laneIDs) {
181 laneIDs_vector.push_back(laneID);
189 bool barrierPhase =
true;
190 for (
int i = ringIter + 1; i < (int)r.size() && i / 2 == ringIter / 2; i++) {
192 barrierPhase =
false;
201 bool phaseGreenRest = ((VecMaxRecall.size() + VecMinRecall.size()) < 1);
202 if (!phaseGreenRest) {
203 bool recallActive = minRecall || maxRecall;
205 for (
const auto& pO : r) {
209 recallActive =
false;
215 phaseGreenRest = recallActive;
220 int barrierNum = ringIter / 2;
224 new NEMAPhase(p, barrierPhase, phaseGreenRest, coordinatePhase, minRecall, maxRecall,
fixForceOff, barrierNum, ringNum, controlledStateIndexes, tempPhase)
245 bool barrierMismatch =
false;
246 for (
int i = 0; i < 2; i++) {
255 throw ProcessError(
"At traffic signal " +
myID +
" the barrier and coordinated phases " +
257 " are located on the same side of a barrier." +
258 " Please check your configuration file");
262 barrierMismatch =
true;
265 if (barrierMismatch) {
266 WRITE_WARNINGF(
TL(
"At NEMA tlLogic '%', barrierPhases or barrier2Phases name a phase that is not the last on its side of the barrier. Ring order decides which phase ends at the barrier, while these parameters still choose the default phase entered after a crossing."),
getID());
273 if (phase->phaseName == p && phase->coordinatePhase && !phase->isAtBarrier) {
274 phase->reservice =
true;
279 WRITE_WARNINGF(
TL(
"At NEMA tlLogic '%', reservicePhases names phase %, which is not a coordinated phase followed by a lagging phase; it is ignored."),
getID(),
toString(p));
285 std::vector<std::pair<int, int>> cp;
287 std::string cps =
"crossPhaseSwitching:";
289 if (crossPhase > 0) {
290 cp.push_back({ p->phaseName, crossPhase });
299 for (
auto& cp_pair : cp) {
300 if (cp_pair.first == p->phaseName || cp_pair.second == p->phaseName) {
301 cpTarget = cp_pair.first;
302 cpSource = cp_pair.second;
305 p->init(
this, cpTarget, cpSource, latching);
331 std::cout <<
"Print to check NEMA phase definitions\n";
333 std::cout <<
"index = " << p->phaseName <<
"; ";
334 std::cout <<
"minDur = " << std::to_string(p->minDuration) <<
"; ";
335 std::cout <<
"maxDur = " << std::to_string(p->maxDuration) <<
"; ";
336 std::cout <<
"vehext = " << std::to_string(p->vehExt) <<
"; ";
337 std::cout <<
"yellow = " << std::to_string(p->yellow) <<
"; ";
338 std::cout <<
"red = " << std::to_string(p->red) <<
"; ";
339 std::cout <<
"state = " << std::to_string((
int)p->getCurrentState()) << std::endl;
367 if (std::find(v.begin(), v.end(), phaseNum) != v.end()) {
379 std::string barriers =
getParameter(
"barrierPhases",
"");
401 std::cout <<
"JunctionID = " <<
myID << std::endl;
402 std::cout <<
"All parameters after calling constructor are: " << std::endl;
405 std::cout <<
"ring1 = " << ring1 << std::endl;
406 std::cout <<
"ring2 = " << ring2 << std::endl;
407 std::cout <<
"barriers = " << barriers << std::endl;
408 std::cout <<
"coordinates = " << coordinates << std::endl;
409 std::cout <<
"offset = " <<
offset << std::endl;
414 std::cout <<
"fixForceOff = " <<
fixForceOff << std::endl;
415 std::cout <<
"You reach the end of constructor" << std::endl;
416 std::cout <<
"****************************************\n";
426 for (
MSLane*
const lane : lanes) {
428 double detector_length = 0;
441 const std::string customID =
getParameter(lane->getID());
442 if (customID !=
"") {
444 if (det ==
nullptr) {
445 throw ProcessError(
"Unknown laneAreaDetector '" + customID +
"' given as custom detector for NEMA tlLogic '" +
getID() +
"', program '" +
getProgramID() +
".");
454 int index = lane->getIndex();
494 int NEMAPhaseIndex = item.first;
495 std::vector<std::string> laneIDs = item.second;
496 std::vector<MSE2Collector*> detectors;
498 for (std::string laneID : laneIDs) {
501 detectors.push_back(detector);
505 for (
int i = 0; i < 2; i++) {
515 std::map<int, std::set<MSE2Collector*>> linkToDetectors;
516 std::set<int> actuatedLinks;
518 const int numLinks = (int)
myLinks.size();
519 std::vector<bool> neverMajor(numLinks,
true);
521 const std::string& state = phase->getState();
522 for (
int i = 0; i < numLinks; i++) {
524 neverMajor[i] =
false;
528 std::vector<bool> oneLane(numLinks,
false);
529 for (
int i = 0; i < numLinks; i++) {
531 int numMotorized = 0;
532 for (
MSLane* l : lane->getEdge().getLanes()) {
533 if ((l->getPermissions() & motorized) != 0) {
537 if (numMotorized == 1) {
546 std::set<MSE2Collector*> detectors;
547 if (phase->isActuated()) {
548 const std::string& state = phase->getState();
549 std::set<int> greenLinks;
550 std::map<MSE2Collector*, std::set<int>> detectorLinks;
552 for (
int i = 0; i < numLinks; i++) {
559 greenLinks.insert(i);
560 actuatedLinks.insert(i);
569 for (
auto& item : detectorLinks) {
574 for (
int j : item.second) {
575 if (greenLinks.count(j) == 0) {
583 MSLane* next = link->getLane();
586 for (
int j : detectorLinks[nextDet]) {
587 if (greenLinks.count(j) == 0) {
597 detectors.insert(item.first);
598 for (
int j : item.second) {
599 linkToDetectors[j].insert(item.first);
603 if (detectors.size() == 0) {
607 std::vector<DetectorInfo*> detectorInfos;
611 if (detInfo.det == det) {
613 detInfo.servedPhase[phaseIndex] =
true;
619 for (
int i : actuatedLinks) {
620 if (linkToDetectors[i].size() == 0 &&
myLinks[i].size() > 0
621 && (
myLinks[i].front()->getLaneBefore()->getPermissions() & motorized) != 0) {
630 for (
int ringIndex = 0; ringIndex < 2; ringIndex++) {
633 cycleLengthCalculated += (p->maxDuration + p->yellow + p->red);
636 int ringNumber = ringIndex + 1;
637 const std::string error =
"At NEMA tlLogic '" +
getID() +
"', Ring " +
toString(ringNumber) +
" does not add to cycle length.";
646 SUMOTime cycleLengths[2][2] = { {0, 0}, {0, 0} };
647 for (
int ringIndex = 0; ringIndex < 2; ringIndex++) {
650 cycleLengths[ringIndex][p->barrierNum] += p->maxDuration + p->yellow + p->red;
654 for (
int barrierNum = 0; barrierNum < 2; barrierNum++) {
655 if (cycleLengths[0][barrierNum] != cycleLengths[1][barrierNum]) {
656 const std::string error =
"At NEMA tlLogic '" +
getID() +
"', the phases before barrier " +
toString(barrierNum + 1) +
" from both rings do not add up. (ring1="
674 assert(newSplits.size() == 8);
676 if (newSplits[p->phaseName - 1] > 0) {
678 p->nextMaxDuration =
TIME2STEPS(newSplits[p->phaseName - 1]) - p->yellow - p->red;
687 if (newMaxGreens[p->phaseName - 1] > 0) {
689 p->nextMaxDuration =
TIME2STEPS(newMaxGreens[p->phaseName - 1]);
710 std::vector<int> output;
712 if (c >=
'0' && c <=
'9') {
714 output.push_back(temp);
733 int length = (int)
rings[ringNum].size();
737 for (
int i = 0; i < (length * 2); i++) {
738 if (
rings[ringNum][i % length] > 0) {
741 if (
rings[ringNum][i % length] == p2) {
744 }
else if (
rings[ringNum][i % length] == p1) {
769 std::set<std::string> output;
770 for (
int i = 0; i < (int)
myLinks.size(); i++) {
778 stateIndex.push_back(i);
780 const MSLane* incoming = link->getLaneBefore();
782 laneIDs.push_back(incoming->
getID());
790 const std::vector<MSLink*> links = lane->
getLinkCont();
799 for (
int i = 0; i < (int)state.size(); i++) {
802 for (
MSLane* lane : lanes) {
818 item.second->setVisible(
true);
826 item.second->setVisible(
false);
839 std::stringstream ss(s);
849 if (key ==
"NEMA.phaseCall") {
850 int activeCalls[8] = { 0 };
853 if (!activeCalls[p->phaseName - 1]) {
854 activeCalls[p->phaseName - 1] = 1 * p->lastDetectActive;
857 std::string outStr =
"";
858 for (
int i = 0; i < 8; i++) {
859 outStr += std::to_string(activeCalls[i]);
866 throw InvalidArgument(
"Unsupported parameter '" + key +
"' for NEMA controller '" +
getID() +
"'");
878 if (key ==
"NEMA.splits" || key ==
"NEMA.maxGreens") {
881 if (tmp.size() != 8) {
883 throw InvalidArgument(
"Parameter '" + key +
"' for NEMA controller '" +
getID() +
"' requires 8 space or comma separated values");
885 std::vector<double> timing;
886 for (
const std::string& s : tmp) {
889 if (key ==
"NEMA.maxGreens") {
894 }
else if (key ==
"NEMA.cycleLength") {
896 }
else if (key ==
"NEMA.offset") {
900 throw InvalidArgument(
"Unsupported parameter '" + key +
"' for NEMA controller '" +
getID() +
"'");
908 if (param_variable ==
"") {
916 for (
int i = 0; i < 2; i++) {
920 runningTime += p->maxDuration + p->getTransitionTimeStateless();
923 if (p->coordinatePhase) {
924 zeroTime[i] = runningTime;
926 p->forceOffTime = runningTime - p->getTransitionTimeStateless();
927 p->greatestStartTime = p->forceOffTime - p->minDuration;
932 SUMOTime minCoordYellow =
MIN2(zeroTime[0], zeroTime[1]);
939 std::ios_base::fmtflags oldflags = std::cout.flags();
940 std::streamsize oldprecision = std::cout.precision();
941 for (
int i = 0; i < 2; i++) {
942 std::cout <<
"Ring" << i + 1 <<
" force offs: \t";
943 for (
auto& p :
rings[i]) {
948 std::cout << std::to_string(0) <<
"\t";
951 std::cout << std::endl;
953 std::cout.flags(oldflags);
954 std::cout.precision(oldprecision);
977 SUMOTime minCoordTime =
MIN2(coordStart[0], coordStart[1]);
981 if ((p->forceOffTime - minCoordTime) >= 0) {
982 p->forceOffTime -= (minCoordTime);
984 p->forceOffTime = (
myCycleLength + (p->forceOffTime - (minCoordTime)));
995 for (
int i = 0; i < 2; i++) {
998 std::sort(ringCopy.begin(), ringCopy.end(),
1000 return p->greatestStartTime <= p1->greatestStartTime;
1005 for (
auto& p : ringCopy) {
1012 activePhases[i] = p;
1018 const std::string error =
"I can't find the correct phase for NEMA tlLogic '" +
getID() +
"' Ring " +
toString(i) +
" to start in.";
1028 if (activePhases[0]->barrierNum != activePhases[1]->barrierNum) {
1047 std::string cleanString;
1048 for (
const char& c : inputType) {
1049 if (isalpha(c) || isdigit(c)) {
1050 cleanString += (char)::tolower(c);
1053 if (cleanString ==
"type170") {
1055 }
else if (cleanString ==
"ts2") {
1058 throw InvalidArgument(
"Please set controllerType for NEMA tlLogic " +
myID +
" to either Type170 or TS2");
1062std::vector<NEMAPhase*>
1064 std::vector<NEMAPhase*> phases;
1066 if (p->ringNum == ringNum) {
1067 phases.push_back(p);
1078std::map<std::string, double>
1080 std::map<std::string, double> result;
1082 result[item.first->getID()] = item.first->getCurrentVehicleNumber();
1097 for (
auto& p : iterRing) {
1098 if (p->phaseName == phaseNum) {
1135 std::vector<std::vector<PhaseTransitionLogic* >> potentialPhases;
1139 potentialPhases.push_back(p->trySwitch(
this));
1143 for (
const auto& r1_t : potentialPhases[0]) {
1144 for (
const auto& r2_t : potentialPhases[1]) {
1146 if (r1_t->getToPhase()->barrierNum == r2_t->getToPhase()->barrierNum) {
1147 transitions.push_back({ r1_t, r2_t, (float)(r1_t->getDistance(r2_t) + r2_t->getDistance(r1_t)) / 2 });
1151 if (r1_t->getFromPhase()->readyToSwitch) {
1156 transitions.push_back({ r1_t, r2_t_temp, (float)(r2_t_temp->getDistance(r1_t) + r1_t->getDistance(r2_t_temp)) / 2 });
1159 if (r2_t->getFromPhase()->readyToSwitch) {
1164 transitions.push_back({ r1_t_temp, r2_t, (float)(r2_t->getDistance(r1_t_temp) + r1_t_temp->
getDistance(r2_t)) / 2 });
1169 if (!transitions.empty()) {
1170 if (transitions.back().distance < 1) {
1185 bool controlled =
false;
1186 std::string phaseChars =
"";
1188 phaseChars += p->getNEMAChar(i);
1189 if (p->controlledIndex(i)) {
1190 out[i] = p->getNEMAChar(i);
1197 if (std::count(phaseChars.begin(), phaseChars.end(), priority_char)) {
1198 out[i] = priority_char;
1210#ifdef DEBUG_NEMA_SWITCH
1211 std::cout <<
SIMTIME <<
" trySwitch tls=" <<
getID() <<
"\n";
1220 p->checkMyDetectors();
1237 if (transitions.size() > 1) {
1238 std::sort(transitions.begin(), transitions.end(),
1240 return i.distance < j.distance;
1245 nextPhases[0] = transitions.front().p1;
1246 nextPhases[1] = transitions.front().p2;
1251 if (p->readyToSwitch) {
1252 p->exit(
this, nextPhases);
1269 p->clearMyDetectors();
1288 p->maxDuration = p->nextMaxDuration;
1303 bool minRecall,
bool maxRecall,
bool fixForceOff,
int barrierNum,
int ringNum,
1306 phaseName(phaseName),
1307 isAtBarrier(isBarrier),
1308 isGreenRest(isGreenRest),
1309 barrierNum(barrierNum),
1310 coordinatePhase(isCoordinated),
1311 minRecall(minRecall),
1312 maxRecall(maxRecall),
1313 fixForceOff(fixForceOff),
1316 myPhaseStringInds(phaseStringInds) {
1362 return i->distance < j->distance;
1367 crossPhaseSource > 0 ? controller->
getPhaseObj(crossPhaseSource) :
nullptr,
1368 crossPhaseTarget > 0 ? controller->
getPhaseObj(crossPhaseTarget) : nullptr
1404 if (ch ==
'G' || ch ==
'g') {
1436 if (d->getCurrentVehicleNumber() > 0) {
1445 if (d->getCurrentVehicleNumber() > 0) {
1457#ifdef DEBUG_NEMA_SWITCH
1525 if (nextPhases[
ringNum]->getToPhase() !=
this) {
1559 bool barrierCrossButOkay = barrierCross && (
1563 if (!barrierCross) {
1568 if (barrierCrossButOkay) {
1589 if ((isOtherPhaseReady || isOtherPhaseInGreenRest) && !
holdsForLag(controller)) {
1602 if (windowLeft > 0) {
1644 enter(controller,
this);
1657 bool vehicleActive =
false;
1661 && p->callActive()) {
1663 vehicleActive =
true;
1673 if (!vehicleActive) {
1698 enter(controller,
this);
1714 if (p->isAtBarrier && p->barrierNum ==
barrierNum) {
1730 const bool inWindow = windowLeft >= 0 ? windowLeft > 0
1741 if (p->coordinatePhase && !p->isAtBarrier && p->barrierNum ==
barrierNum) {
1746 return sinceForceOff < windowLength ? windowLength - sinceForceOff : 0;
1755 if (t->getToPhase()->phaseName == toPhase) {
1765std::vector<PhaseTransitionLogic*>
1768 std::vector<PhaseTransitionLogic*> nextTransitions;
1773 if (t->okay(controller)) {
1778 nextTransitions.push_back(t);
1782 nextTransitions.push_back(t);
1792 bool sameBarrier =
false;
1793 for (
auto& t : nextTransitions) {
1804 if (!found && !sameBarrier) {
1809 if (nextTransitions.size() < 1) {
1813 return nextTransitions;
1822 fromPhase(fromPhase),
1970 if (tillForceOff > 0 && tillForceOff < fromPhase->maxDuration) {
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
std::vector< std::string > StringVector
Definition of a vector of strings.
std::vector< int > IntVector
Definition of a vector of ints.
constexpr SUMOTime TIME2STEPS(double x)
bool noVehicles(SVCPermissions permissions)
Returns whether an edge with the given permissions forbids vehicles.
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_PEDESTRIAN
pedestrian
@ SUMO_TAG_LANE_AREA_DETECTOR
alternative tag for e2 detector
@ LEFT
The link is a (hard) left direction.
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
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 accessible from the current working directory.
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
An areal detector corresponding to a sequence of consecutive lanes.
virtual void setVisible(bool)
Representation of a lane in the micro simulation.
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
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).
The definition of a single phase of a tls logic.
SUMOTime maxDuration
The maximum duration of the phase.
SUMOTime vehext
for NEMA phase
SUMOTime minDuration
The minimum duration of the phase.
SUMOTime yellow
for NEMA phase
SUMOTime red
for NEMA phase
SUMOTime myLastSwitch
Stores the timestep of the last on-switched of the phase.
const std::string & getState() const
Returns the state within this phase.
void setState(const std::string &_state)
void setName(const std::string &_name)
A fixed traffic light logic.
Phases myPhases
The list of phases this logic uses.
int myStep
The current step.
A class that stores and controls tls and switching of their programs.
SUMOTime myOffset
the offset parameter of the current program
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 myDefaultCycleTime
The cycle time (without changes)
const std::string & getProgramID() const
Returns this tl-logic's id.
const std::string myProgramID
The id of the logic.
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
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.
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.
A NEMA (adaptive) traffic light logic based on E2Detector.
std::map< std::string, double > getDetectorStates() const override
retrieve all detectors used by this program
int measureRingDistance(int p1, int p2, int ringNum)
return the ring distance between two phases
SUMOTime getTimeInCycle() const
override Function to Simplify Accessing Offset Cycle Time
void getLaneInfoFromNEMAState(std::string state, StringVector &laneIDs, IntVector &stateIndex)
returns the IDs of the phase's controlled lanes. Found by looking for the "G" in the light state stri...
void getNextPhases(TransitionPairs &transitions)
extends the transitions vector with valid Transitions given the current traffic light state
void setNewMaxGreens(std::vector< double > newMaxGreens)
Set the max green of all phases.
void calculateForceOffs170()
calculate the forceOffs for a Type 170 style offset From https://ops.fhwa.dot.gov/publications/fhwaho...
void calculateInitialPhases()
directs the controller to the correct calculate phases function
const std::string lightHeadPriority
constant for storing the priority order for light heads. Iterates left to right and stops when finds ...
const std::string getParameter(const std::string &key, const std::string defaultValue="") const override
try to get the value of the given parameter. Parameters prefixed with 'NEMA.' control functionality
std::vector< DetectorInfo > myDetectorInfoVector
storing the detector info in a vector
SUMOTime myNextCycleLength
the next cycle length (set by traci)
void init(NLDetectorBuilder &nb) override
Initialises the tls with information about incoming lanes.
void resetLastSwitch(SUMOTime t) override
void calculateInitialPhasesTS2()
calculate the initial phases for the TS2 style controller to start in
std::string myVehicleTypes
Whether detector output separates by vType.
std::string myFile
The output file for generated detectors.
double myDetectorLength
store the generated detector length
SUMOTime getCurrentCycleLength()
Get the current cycle length.
std::vector< std::vector< int > > rings
SUMOTime myFreq
The frequency for aggregating detector output.
DetectorLaneMap myDetectorLaneMap
A map from detectors to lanes.
SUMOTime trySwitch() override
overrides the MSSimpleTrafficLightLogic trySwitch method
bool isType170(void) const
checks if the controller is of type170
void validate_timing()
validates the NEMA timing. Writes warnings if ignoreError set to true else throws ProcessError
bool queuedTraciChanges
flag to keep track of whether a timing change has been requested via traci
NEMALogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const SUMOTime offset, const MSSimpleTrafficLightLogic::Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > ¶meter, const std::string &basePath)
Constructor.
void activateProgram() override
called when switching programs
void setShowDetectors(bool show)
void constructTimingAndPhaseDefs(std::string &barriers, std::string &coordinates, std::string &ring1, std::string &ring2)
constructs phase using the configuration file
int myPhaseStrLen
stores the length of phase string for the controller "GGrrrrs" = 6. Must be the same length for all p...
int myNumberRings
stores controllers # of rings
PhasePtr defaultBarrierPhases[2][2]
an array to store the phases located at a barrier for each ring
bool hasLaggingPhase() const
whether the controller is in coordinated mode and a coordinated phase is followed by a lagging phase
SUMOTime getCurrentTime(void) const
Wrapper Function to Simplify Accessing Time.
std::vector< PhasePtr > myPhaseObjs
a vector that stores a pointer to the instantiated NEMAPhase objects
void setParameter(const std::string &key, const std::string &value) override
try to set the given parameter. Parameters prefixed with 'NEMA.' control functionality
void error_handle_not_set(std::string param_variable, std::string param_name)
throw an InvalidArgument error if the param_name is not set
void implementTraciChanges(void)
implement any pending traci changes This function is called once per cycle
PhasePtr getPhaseObj(int phaseNum, int ringNum=-1)
get the phase object matching the phaseNum If ringNum is passed, it will only search for the phase in...
void setNewOffset(double newOffset)
Set the new offset for the controller.
std::vector< PhasePtr > getPhasesByRing(int ringNum)
get all phases for a given ring
controllerType parseControllerType(std::string inputType)
parse the controllerType from the tllogic description
SUMOTime myCycleLength
the coordinated cycle length
SUMOTime offset
the controller's offset
void calculateInitialPhases170()
calculate the initial phases for Type 170
SUMOTime myNextOffset
the next offset to implement
SUMOTime ModeCycle(SUMOTime a, SUMOTime b)
Calculates the modulus a / b, normally used to calculate the cycle time between two times....
void calculateForceOffs()
directs the code to the correct force off function accorifing to its cabinet type
std::vector< int > readParaFromString(std::string s)
converts a comma separated string into a integer vector "1,2,3,4" -> {1,2,3,4}
std::vector< PhasePtr > getPhaseObjs(void)
get a vector of all phase objects
bool myShowDetectors
Whether the detectors shall be shown in the GUI.
detectorMap myDetectorForPhase
int string2int(std::string s)
convert a string to an integer
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
bool coordinateMode
whether the controller is in coordinated mode or not
PhasePtr myActivePhaseObjs[2]
variable to store the active phases
void deactivateProgram() override
void setCurrentTime(void)
Set the simTime.
MSPhaseDefinition myPhase
virtual phase that holds the current state
PhaseTransitionLogic * getDefaultTransition(PhaseTransitionLogic *t, PhaseTransitionLogic *ot)
return the default transition for t give its and the ot's state
bool vectorContainsPhase(std::vector< int > v, int phaseNum)
check if a vector contains an element
void calculateForceOffsTS2()
calculate the forceOffs for a TS2 style offset From https://ops.fhwa.dot.gov/publications/fhwahop0802...
PhasePtr getOtherPhase(PhasePtr p)
Get the opposite active phase.
double myDetectorLengthLeftTurnLane
store the left turn lane detestor length
controllerType myControllerType
bool isLeftTurnLane(const MSLane *const lane) const
decide whether the detector is for left turn lane if it is, use the detector length for left turn lan...
LaneDetectorMap myLaneDetectorMap
A map from lanes to detectors.
PhasePtr coordinatePhaseObjs[2]
a store of the coordinated phase objects. Only used meaningfully when the controller is in coordinate...
std::map< std::string, int > myLanePhaseMap
A map from lanes names to phases.
std::string composeLightString()
iterates over the two active phases (myActivePhaseObjs) and merges the two active phases
void setNewCycleLength(double newCycleLength)
set the new cycle length for the controller
void setActivePhase(PhasePtr phase)
set the active phase
std::vector< transitionInfo > TransitionPairs
const MSPhaseDefinition & getCurrentPhaseDef() const override
Returns myPhase, which doesn't correspond to a NEMA phase, but rather the composite light string.
std::map< int, std::vector< std::string > > phase2ControllerLanesMap
void setNewSplits(std::vector< double > newSplits)
Set the new splits of all phases.
One phase in the NEMAController.
bool lastDetectActive
store the last detect check for traci purposes
std::string myYellowString
bool myReserviced
whether this coordinated phase was entered from its lagging phase past its force off (served again in...
void setDetectors(std::vector< MSE2Collector * > detectors)
sets the detectors for the phase
NEMAPhase(int phaseName, bool isBarrier, bool isGreenRest, bool isCoordinated, bool minRecall, bool maxRecall, bool fixForceOff, int barrierNum, int ringNum, IntVector phaseStringInds, MSPhaseDefinition *phase)
Construct a new NEMAPhase object.
void cleanupExit(void)
public method to set whether phase is active or not
bool holdsForLag(NEMALogic *controller)
whether a coordinated phase that is followed by a lagging phase is past its force off but has not rea...
MSPhaseDefinition * myCorePhase
A reference to the core phase of which NEMAPhase wraps.
std::string myGreenString
LightState getCurrentState() const
gets the current light state
SUMOTime myExpectedDuration
void setMyNEMAStates(void)
this function replaces getNEMAStates calculation at every call It sets my myGreenString,...
PhasePtr getSequentialPriorPhase(void)
get the prior phase
SUMOTime greenRestTimer
a count down timer to track green rest transition time
void clearMyDetectors(void)
Clear My Detectors. Called on all phases at every step.
void checkMyDetectors(void)
Check Detectors. Called on all phases at every step.
bool reservice
whether this coordinated phase is served again in the same cycle when its lagging phase gaps out (res...
PhaseDetectorInfo myDetectorInfo
PhasePtr sequentialPriorPhase
SUMOTime greatestStartTime
bool isReserviced() const
whether this coordinated phase is being served again in this cycle after its lagging phase gapped out
std::vector< PhaseTransitionLogic * > trySwitch(NEMALogic *controller)
calculate a vector of potention next phases
std::vector< MSE2Collector * > getDetectors() const
returns a vector of the phases detectors
char getNEMAChar(int i)
Return the ryg light string for the phase.
SUMOTime forceOffTime
stores the force off time in coordinated mode
void recalculateTiming(void)
accessory function to recalculate timing
void handleRedXferOrNextPhase(NEMALogic *controller, PhaseTransitionLogic *nextPhases[2])
handles the transition into a red xfer state, which is roughly the same as green rest
SUMOTime getTransitionTimeStateless(void)
Get the Transition time given.
SUMOTime calcVehicleExtension(SUMOTime duration)
}
bool okay2ForceSwitch(NEMALogic *controller)
simple internal check to see if done okay to transition
void init(NEMALogic *controller, int crossPhaseTarget, int crossPhaseSource, bool latching)
initializes the object
bool isTransitionActive() const
check if a transition is active
void enterYellow(NEMALogic *controller)
handles the transition into yellow
PhaseTransitionLogic * getTransition(int toPhase)
return the PhaseTransitionLogic matching the toPhase
void handleGreenRestOrTransfer(NEMALogic *controller, PhaseTransitionLogic *nextPhases[2])
handles the transition into a green rest state
bool readyToSwitch
flag to for the supervisory controller to denote whether phase is ready to switch or not.
bool transitionActive
variable to store whether a transition is active or not
std::vector< PhaseTransitionLogic * > myTransitions
stores a sorted list of potential transitions
bool crossFits(NEMALogic *controller, NEMAPhase *toPhase)
for a coordinated or lagging phase in a plan with a lagging phase: whether this ring may cross the ba...
SUMOTime lagWindowLeft(NEMALogic *controller)
for a lagging phase (the barrier phase after a coordinated phase on its side of the barrier): the tim...
void forceEnter(NEMALogic *controller)
Force Enter. This Should only be called at initialization time.
PhasePtr myLastPhaseInstance
bool callActive(void)
simple method to check if there is either a recall or an active detector
void update(NEMALogic *controller)
update is called on the active phases by the NEMAController at every time step
SUMOTime getTransitionTime(NEMALogic *controller)
Get the Transition Time.
PhaseTransitionLogic * lastTransitionDecision
pointer to save the last transition
void enter(NEMALogic *controller, PhasePtr lastPhase)
handles entry to the phase during simulation Sets the color to green and determines maximum duration
void exit(NEMALogic *controller, PhaseTransitionLogic *nextPhases[2])
handles the transition out of a phase into the next (puts the phase through (G -> Y -> R) transition
Builds detectors for microsim.
Parameterised * buildE2Detector(const std::string &id, MSLane *lane, double pos, double endPos, double length, const std::string &device, SUMOTime frequency, SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold, const std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons, bool friendlyPos, bool showDetector, MSTLLogicControl::TLSLogicVariants *tlls=0, MSLane *toLane=0)
Builds a new E2 detector and adds it to the net's detector control. Also performs some consistency ch...
std::string myID
The name of the object.
const std::string & getID() const
Returns the id.
T get(const std::string &id) const
Retrieves an item.
static OptionsCont & getOptions()
Retrieves the options.
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.
This class handles the transition logic between two phases.
int getDistance(PhaseTransitionLogic *otherTrans)
return the ring distance that this transition represents
bool okay(NEMALogic *controller)
This function is the main PhaseTransitionLogic function It is called by the fromPhase to check if a t...
bool freeBase(NEMALogic *controller)
this represents the bare minimum logic, that the toPhase has an active detector and that the fromPhas...
bool coordBase(NEMALogic *controller)
represents the bare minimum coordinate mode logic. Requires that the toPhase can fit its minimum gree...
bool fromBarrier(NEMALogic *controller)
If the fromPhase is at a barrier, then this function will be called to check whether the transition i...
bool fromCoord(NEMALogic *controller)
if the fromPhase is a coordinated phase, then this logic will be checked
PhaseTransitionLogic(PhasePtr fromPhase, PhasePtr toPhase)
Construct a new Phase Transition Logic object.
PhasePtr getFromPhase(void) const
get the from phase
PhasePtr getToPhase(void) const
get the to phase
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
stores information about the phase's detector(s)
bool detectActive
where any of my detectors are active or not
std::vector< MSE2Collector * > detectors
a vector of pointers to the phase's detectors
PhasePtr cpdSource
the cross-phase switching source for myself (1 if 6 should check 1 if 6 is green and I am phase 6)
PhasePtr cpdTarget
the cross-phase switching target for myself (6 if 6 should check 1 if 6 is green and I am phase 1)
bool latching
whether the detectors are latching or not