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()) {
101 for (
int i = 0; i < (int)
rings.size(); i++) {
103 std::cout <<
"Ring" << i + 1 <<
" includes phases: \t";
104 for (
auto j :
rings[i]) {
106 std::cout << j <<
" ";
107 if (count == 2 || count == 4) {
111 std::cout << std::endl;
120 std::cout <<
"minRecall: ";
121 for (
int i = 0; i < 8; i++) {
124 std::cout << std::endl;
126 std::cout <<
"maxRecall: ";
127 for (
int i = 0; i < 8; i++) {
130 std::cout << std::endl;
136 int lastPhaseIter = 0;
138 for (
const auto& r :
rings) {
140 lastPhaseIter = phaseIter;
142 for (
const auto& p : r) {
153 if (tempPhase ==
nullptr) {
158 std::string state = tempPhase->
getState();
164 throw ProcessError(
TLF(
"At NEMA tlLogic '%', different sizes of NEMA phase states. Please check the NEMA XML",
getID()));
172 std::vector<std::string> laneIDs_vector;
173 for (std::string laneID : laneIDs) {
174 laneIDs_vector.push_back(laneID);
188 bool phaseGreenRest = ((VecMaxRecall.size() + VecMinRecall.size()) < 1);
189 if (!phaseGreenRest) {
190 bool recallActive = minRecall || maxRecall;
192 for (
const auto& pO : r) {
196 recallActive =
false;
202 phaseGreenRest = recallActive;
207 int barrierNum = ringIter / 2;
211 new NEMAPhase(p, barrierPhase, phaseGreenRest, coordinatePhase, minRecall, maxRecall,
fixForceOff, barrierNum, ringNum, controlledStateIndexes, tempPhase)
229 for (
int i = 0; i < 2; i++) {
238 throw ProcessError(
"At traffic signal " +
myID +
" the barrier and coordinated phases " +
240 " are located on the same side of a barrier." +
241 " Please check your configuration file");
247 std::vector<std::pair<int, int>> cp;
249 std::string cps =
"crossPhaseSwitching:";
251 if (crossPhase > 0) {
252 cp.push_back({ p->phaseName, crossPhase });
261 for (
auto& cp_pair : cp) {
262 if (cp_pair.first == p->phaseName || cp_pair.second == p->phaseName) {
263 cpTarget = cp_pair.first;
264 cpSource = cp_pair.second;
267 p->init(
this, cpTarget, cpSource, latching);
293 std::cout <<
"Print to check NEMA phase definitions\n";
295 std::cout <<
"index = " << p->phaseName <<
"; ";
296 std::cout <<
"minDur = " << std::to_string(p->minDuration) <<
"; ";
297 std::cout <<
"maxDur = " << std::to_string(p->maxDuration) <<
"; ";
298 std::cout <<
"vehext = " << std::to_string(p->vehExt) <<
"; ";
299 std::cout <<
"yellow = " << std::to_string(p->yellow) <<
"; ";
300 std::cout <<
"red = " << std::to_string(p->red) <<
"; ";
301 std::cout <<
"state = " << std::to_string((
int)p->getCurrentState()) << std::endl;
329 if (std::find(v.begin(), v.end(), phaseNum) != v.end()) {
341 std::string barriers =
getParameter(
"barrierPhases",
"");
363 std::cout <<
"JunctionID = " <<
myID << std::endl;
364 std::cout <<
"All parameters after calling constructor are: " << std::endl;
367 std::cout <<
"ring1 = " << ring1 << std::endl;
368 std::cout <<
"ring2 = " << ring2 << std::endl;
369 std::cout <<
"barriers = " << barriers << std::endl;
370 std::cout <<
"coordinates = " << coordinates << std::endl;
371 std::cout <<
"offset = " <<
offset << std::endl;
376 std::cout <<
"fixForceOff = " <<
fixForceOff << std::endl;
377 std::cout <<
"You reach the end of constructor" << std::endl;
378 std::cout <<
"****************************************\n";
388 for (
MSLane*
const lane : lanes) {
390 double detector_length = 0;
403 const std::string customID =
getParameter(lane->getID());
404 if (customID !=
"") {
406 if (det ==
nullptr) {
407 throw ProcessError(
"Unknown laneAreaDetector '" + customID +
"' given as custom detector for NEMA tlLogic '" +
getID() +
"', program '" +
getProgramID() +
".");
416 int index = lane->getIndex();
456 int NEMAPhaseIndex = item.first;
457 std::vector<std::string> laneIDs = item.second;
458 std::vector<MSE2Collector*> detectors;
460 for (std::string laneID : laneIDs) {
463 detectors.push_back(detector);
467 for (
int i = 0; i < 2; i++) {
477 std::map<int, std::set<MSE2Collector*>> linkToDetectors;
478 std::set<int> actuatedLinks;
480 const int numLinks = (int)
myLinks.size();
481 std::vector<bool> neverMajor(numLinks,
true);
483 const std::string& state = phase->getState();
484 for (
int i = 0; i < numLinks; i++) {
486 neverMajor[i] =
false;
490 std::vector<bool> oneLane(numLinks,
false);
491 for (
int i = 0; i < numLinks; i++) {
493 int numMotorized = 0;
494 for (
MSLane* l : lane->getEdge().getLanes()) {
495 if ((l->getPermissions() & motorized) != 0) {
499 if (numMotorized == 1) {
508 std::set<MSE2Collector*> detectors;
509 if (phase->isActuated()) {
510 const std::string& state = phase->getState();
511 std::set<int> greenLinks;
512 std::map<MSE2Collector*, std::set<int>> detectorLinks;
514 for (
int i = 0; i < numLinks; i++) {
521 greenLinks.insert(i);
522 actuatedLinks.insert(i);
531 for (
auto& item : detectorLinks) {
536 for (
int j : item.second) {
537 if (greenLinks.count(j) == 0) {
545 MSLane* next = link->getLane();
548 for (
int j : detectorLinks[nextDet]) {
549 if (greenLinks.count(j) == 0) {
559 detectors.insert(item.first);
560 for (
int j : item.second) {
561 linkToDetectors[j].insert(item.first);
565 if (detectors.size() == 0) {
569 std::vector<DetectorInfo*> detectorInfos;
573 if (detInfo.det == det) {
575 detInfo.servedPhase[phaseIndex] =
true;
581 for (
int i : actuatedLinks) {
582 if (linkToDetectors[i].size() == 0 &&
myLinks[i].size() > 0
583 && (
myLinks[i].front()->getLaneBefore()->getPermissions() & motorized) != 0) {
592 for (
int ringIndex = 0; ringIndex < 2; ringIndex++) {
595 cycleLengthCalculated += (p->maxDuration + p->yellow + p->red);
598 int ringNumber = ringIndex + 1;
599 const std::string error =
"At NEMA tlLogic '" +
getID() +
"', Ring " +
toString(ringNumber) +
" does not add to cycle length.";
608 SUMOTime cycleLengths[2][2] = { {0, 0}, {0, 0} };
609 for (
int ringIndex = 0; ringIndex < 2; ringIndex++) {
612 cycleLengths[ringIndex][p->barrierNum] += p->maxDuration + p->yellow + p->red;
616 for (
int barrierNum = 0; barrierNum < 2; barrierNum++) {
617 if (cycleLengths[0][barrierNum] != cycleLengths[1][barrierNum]) {
618 const std::string error =
"At NEMA tlLogic '" +
getID() +
"', the phases before barrier " +
toString(barrierNum + 1) +
" from both rings do not add up. (ring1="
636 assert(newSplits.size() == 8);
638 if (newSplits[p->phaseName - 1] > 0) {
640 p->nextMaxDuration =
TIME2STEPS(newSplits[p->phaseName - 1]) - p->yellow - p->red;
649 if (newMaxGreens[p->phaseName - 1] > 0) {
651 p->nextMaxDuration =
TIME2STEPS(newMaxGreens[p->phaseName - 1]);
672 std::vector<int> output;
674 if (c >=
'0' && c <=
'9') {
676 output.push_back(temp);
688 int length = (int)
rings[ringNum].size();
692 for (
int i = 0; i < (length * 2); i++) {
693 if (
rings[ringNum][i % length] > 0) {
696 if (
rings[ringNum][i % length] == p2) {
699 }
else if (
rings[ringNum][i % length] == p1) {
724 std::set<std::string> output;
725 for (
int i = 0; i < (int)
myLinks.size(); i++) {
733 stateIndex.push_back(i);
735 const MSLane* incoming = link->getLaneBefore();
737 laneIDs.push_back(incoming->
getID());
745 const std::vector<MSLink*> links = lane->
getLinkCont();
754 for (
int i = 0; i < (int)state.size(); i++) {
757 for (
MSLane* lane : lanes) {
773 item.second->setVisible(
true);
781 item.second->setVisible(
false);
794 std::stringstream ss(s);
804 if (key ==
"NEMA.phaseCall") {
805 int activeCalls[8] = { 0 };
808 if (!activeCalls[p->phaseName - 1]) {
809 activeCalls[p->phaseName - 1] = 1 * p->lastDetectActive;
812 std::string outStr =
"";
813 for (
int i = 0; i < 8; i++) {
814 outStr += std::to_string(activeCalls[i]);
821 throw InvalidArgument(
"Unsupported parameter '" + key +
"' for NEMA controller '" +
getID() +
"'");
833 if (key ==
"NEMA.splits" || key ==
"NEMA.maxGreens") {
836 if (tmp.size() != 8) {
838 throw InvalidArgument(
"Parameter '" + key +
"' for NEMA controller '" +
getID() +
"' requires 8 space or comma separated values");
840 std::vector<double> timing;
841 for (
const std::string& s : tmp) {
844 if (key ==
"NEMA.maxGreens") {
849 }
else if (key ==
"NEMA.cycleLength") {
851 }
else if (key ==
"NEMA.offset") {
855 throw InvalidArgument(
"Unsupported parameter '" + key +
"' for NEMA controller '" +
getID() +
"'");
863 if (param_variable ==
"") {
871 for (
int i = 0; i < 2; i++) {
875 runningTime += p->maxDuration + p->getTransitionTimeStateless();
878 if (p->coordinatePhase) {
879 zeroTime[i] = runningTime;
881 p->forceOffTime = runningTime - p->getTransitionTimeStateless();
882 p->greatestStartTime = p->forceOffTime - p->minDuration;
887 SUMOTime minCoordYellow =
MIN2(zeroTime[0], zeroTime[1]);
894 std::ios_base::fmtflags oldflags = std::cout.flags();
895 std::streamsize oldprecision = std::cout.precision();
896 for (
int i = 0; i < 2; i++) {
897 std::cout <<
"Ring" << i + 1 <<
" force offs: \t";
898 for (
auto& p :
rings[i]) {
903 std::cout << std::to_string(0) <<
"\t";
906 std::cout << std::endl;
908 std::cout.flags(oldflags);
909 std::cout.precision(oldprecision);
926 if ((p->forceOffTime - minCoordTime) >= 0) {
927 p->forceOffTime -= (minCoordTime);
929 p->forceOffTime = (
myCycleLength + (p->forceOffTime - (minCoordTime)));
940 for (
int i = 0; i < 2; i++) {
943 std::sort(ringCopy.begin(), ringCopy.end(),
945 return p->greatestStartTime <= p1->greatestStartTime;
950 for (
auto& p : ringCopy) {
963 const std::string error =
"I can't find the correct phase for NEMA tlLogic '" +
getID() +
"' Ring " +
toString(i) +
" to start in.";
973 if (activePhases[0]->barrierNum != activePhases[1]->barrierNum) {
992 std::string cleanString;
993 for (
const char& c : inputType) {
994 if (isalpha(c) || isdigit(c)) {
995 cleanString += (char)::tolower(c);
998 if (cleanString ==
"type170") {
1000 }
else if (cleanString ==
"ts2") {
1003 throw InvalidArgument(
"Please set controllerType for NEMA tlLogic " +
myID +
" to either Type170 or TS2");
1007std::vector<NEMAPhase*>
1009 std::vector<NEMAPhase*> phases;
1011 if (p->ringNum == ringNum) {
1012 phases.push_back(p);
1023std::map<std::string, double>
1025 std::map<std::string, double> result;
1027 result[item.first->getID()] = item.first->getCurrentVehicleNumber();
1042 for (
auto& p : iterRing) {
1043 if (p->phaseName == phaseNum) {
1068 std::vector<std::vector<PhaseTransitionLogic* >> potentialPhases;
1072 potentialPhases.push_back(p->trySwitch(
this));
1076 for (
const auto& r1_t : potentialPhases[0]) {
1077 for (
const auto& r2_t : potentialPhases[1]) {
1079 if (r1_t->getToPhase()->barrierNum == r2_t->getToPhase()->barrierNum) {
1080 transitions.push_back({ r1_t, r2_t, (float)(r1_t->getDistance(r2_t) + r2_t->getDistance(r1_t)) / 2 });
1084 if (r1_t->getFromPhase()->readyToSwitch) {
1089 transitions.push_back({ r1_t, r2_t_temp, (float)(r2_t_temp->getDistance(r1_t) + r1_t->getDistance(r2_t_temp)) / 2 });
1092 if (r2_t->getFromPhase()->readyToSwitch) {
1097 transitions.push_back({ r1_t_temp, r2_t, (float)(r2_t->getDistance(r1_t_temp) + r1_t_temp->
getDistance(r2_t)) / 2 });
1102 if (!transitions.empty()) {
1103 if (transitions.back().distance < 1) {
1118 bool controlled =
false;
1119 std::string phaseChars =
"";
1121 phaseChars += p->getNEMAChar(i);
1122 if (p->controlledIndex(i)) {
1123 out[i] = p->getNEMAChar(i);
1130 if (std::count(phaseChars.begin(), phaseChars.end(), priority_char)) {
1131 out[i] = priority_char;
1143#ifdef DEBUG_NEMA_SWITCH
1144 std::cout <<
SIMTIME <<
" trySwitch tls=" <<
getID() <<
"\n";
1153 p->checkMyDetectors();
1170 if (transitions.size() > 1) {
1171 std::sort(transitions.begin(), transitions.end(),
1173 return i.distance < j.distance;
1178 nextPhases[0] = transitions.front().p1;
1179 nextPhases[1] = transitions.front().p2;
1184 if (p->readyToSwitch) {
1185 p->exit(
this, nextPhases);
1202 p->clearMyDetectors();
1221 p->maxDuration = p->nextMaxDuration;
1236 bool minRecall,
bool maxRecall,
bool fixForceOff,
int barrierNum,
int ringNum,
1239 phaseName(phaseName),
1240 isAtBarrier(isBarrier),
1241 isGreenRest(isGreenRest),
1242 barrierNum(barrierNum),
1243 coordinatePhase(isCoordinated),
1244 minRecall(minRecall),
1245 maxRecall(maxRecall),
1246 fixForceOff(fixForceOff),
1249 myPhaseStringInds(phaseStringInds) {
1293 return i->distance < j->distance;
1298 crossPhaseSource > 0 ? controller->
getPhaseObj(crossPhaseSource) :
nullptr,
1299 crossPhaseTarget > 0 ? controller->
getPhaseObj(crossPhaseTarget) : nullptr
1335 if (ch ==
'G' || ch ==
'g') {
1367 if (d->getCurrentVehicleNumber() > 0) {
1376 if (d->getCurrentVehicleNumber() > 0) {
1388#ifdef DEBUG_NEMA_SWITCH
1440 if (nextPhases[
ringNum]->getToPhase() !=
this) {
1474 bool barrierCrossButOkay = barrierCross && (
1478 if (!barrierCross) {
1483 if (barrierCrossButOkay) {
1503 if (isOtherPhaseReady || isOtherPhaseInGreenRest) {
1559 bool vehicleActive =
false;
1563 && p->callActive()) {
1565 vehicleActive =
true;
1575 if (!vehicleActive) {
1598 enter(controller,
this);
1611 if (t->getToPhase()->phaseName == toPhase) {
1621std::vector<PhaseTransitionLogic*>
1624 std::vector<PhaseTransitionLogic*> nextTransitions;
1629 if (t->okay(controller)) {
1634 nextTransitions.push_back(t);
1638 nextTransitions.push_back(t);
1648 bool sameBarrier =
false;
1649 for (
auto& t : nextTransitions) {
1660 if (!found && !sameBarrier) {
1665 if (nextTransitions.size() < 1) {
1669 return nextTransitions;
1678 fromPhase(fromPhase),
#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.
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 accessable 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
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 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
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
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
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.
PhaseDetectorInfo myDetectorInfo
PhasePtr sequentialPriorPhase
SUMOTime greatestStartTime
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
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