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) <<
"; ";
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;
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="
637 assert(newSplits.size() == 8);
639 if (newSplits[p->phaseName - 1] > 0) {
641 p->nextMaxDuration =
TIME2STEPS(newSplits[p->phaseName - 1]) - p->yellow - p->red;
650 if (newMaxGreens[p->phaseName - 1] > 0) {
652 p->nextMaxDuration =
TIME2STEPS(newMaxGreens[p->phaseName - 1]);
673 std::vector<int> output;
675 if (c >=
'0' && c <=
'9') {
677 output.push_back(temp);
689 int length = (int)
rings[ringNum].size();
693 for (
int i = 0; i < (length * 2); i++) {
694 if (
rings[ringNum][i % length] > 0) {
697 if (
rings[ringNum][i % length] == p2) {
700 }
else if (
rings[ringNum][i % length] == p1) {
725 std::set<std::string> output;
726 for (
int i = 0; i < (int)state.size(); i++) {
730 stateIndex.push_back(i);
732 laneIDs.push_back(link->getLaneBefore()->getID());
739 const std::vector<MSLink*> links = lane->
getLinkCont();
748 for (
int i = 0; i < (int)state.size(); i++) {
751 for (
MSLane* lane : lanes) {
767 item.second->setVisible(
true);
775 item.second->setVisible(
false);
788 std::stringstream ss(s);
798 if (key ==
"NEMA.phaseCall") {
799 int activeCalls[8] = {0};
802 if (!activeCalls[p->phaseName - 1]) {
803 activeCalls[p->phaseName - 1] = 1 * p->lastDetectActive;
806 std::string outStr =
"";
807 for (
int i = 0; i < 8; i++) {
815 throw InvalidArgument(
"Unsupported parameter '" + key +
"' for NEMA controller '" +
getID() +
"'");
827 if (key ==
"NEMA.splits" || key ==
"NEMA.maxGreens") {
830 if (tmp.size() != 8) {
832 throw InvalidArgument(
"Parameter '" + key +
"' for NEMA controller '" +
getID() +
"' requires 8 space or comma separated values");
834 std::vector<double> timing;
835 for (
const std::string& s : tmp) {
838 if (key ==
"NEMA.maxGreens") {
843 }
else if (key ==
"NEMA.cycleLength") {
845 }
else if (key ==
"NEMA.offset") {
849 throw InvalidArgument(
"Unsupported parameter '" + key +
"' for NEMA controller '" +
getID() +
"'");
857 if (param_variable ==
"") {
865 for (
int i = 0; i < 2; i++) {
869 runningTime += p->maxDuration + p->getTransitionTime(
this);
872 if (p->coordinatePhase) {
873 zeroTime[i] = runningTime;
875 p->forceOffTime = runningTime - p->getTransitionTime(
this);
876 p->greatestStartTime = p->forceOffTime - p->minDuration;
881 SUMOTime minCoordYellow =
MIN2(zeroTime[0], zeroTime[1]);
888 std::ios_base::fmtflags oldflags = std::cout.flags();
889 std::streamsize oldprecision = std::cout.precision();
890 for (
int i = 0; i < 2; i++) {
891 std::cout <<
"Ring" << i + 1 <<
" force offs: \t";
892 for (
auto& p :
rings[i]) {
900 std::cout << std::endl;
902 std::cout.flags(oldflags);
903 std::cout.precision(oldprecision);
920 if ((p->forceOffTime - minCoordTime) >= 0) {
921 p->forceOffTime -= (minCoordTime);
923 p->forceOffTime = (
myCycleLength + (p->forceOffTime - (minCoordTime)));
934 for (
int i = 0; i < 2; i++) {
937 std::sort(ringCopy.begin(), ringCopy.end(),
939 return p->greatestStartTime <= p1->greatestStartTime;
944 for (
auto& p : ringCopy) {
957 const std::string error =
"I can't find the correct phase for NEMA tlLogic '" +
getID() +
"' Ring " +
toString(i) +
" to start in.";
967 if (activePhases[0]->barrierNum != activePhases[1]->barrierNum) {
986 std::string cleanString;
987 for (
const char& c : inputType) {
988 if (isalpha(c) || isdigit(c)) {
989 cleanString += (char)::tolower(c);
992 if (cleanString ==
"type170") {
994 }
else if (cleanString ==
"ts2") {
997 throw InvalidArgument(
"Please set controllerType for NEMA tlLogic " +
myID +
" to either Type170 or TS2");
1001std::vector<NEMAPhase*>
1003 std::vector<NEMAPhase*> phases;
1005 if (p->ringNum == ringNum) {
1006 phases.push_back(p);
1017std::map<std::string, double>
1019 std::map<std::string, double> result;
1021 result[item.first->getID()] = item.first->getCurrentVehicleNumber();
1036 for (
auto& p : iterRing) {
1037 if (p->phaseName == phaseNum) {
1064 std::vector<std::vector<PhaseTransitionLogic* >> potentialPhases;
1068 potentialPhases.push_back(p->trySwitch(
this));
1072 for (
const auto& r1_t : potentialPhases[0]) {
1073 for (
const auto& r2_t : potentialPhases[1]) {
1075 if (r1_t->getToPhase()->barrierNum == r2_t->getToPhase()->barrierNum) {
1076 transitions.push_back({ r1_t, r2_t, (float)(r1_t->getDistance(r2_t) + r2_t->getDistance(r1_t)) / 2 });
1080 if (r1_t->getFromPhase()->readyToSwitch) {
1085 transitions.push_back({ r1_t, r2_t_temp, (float)(r2_t_temp->getDistance(r1_t) + r1_t->getDistance(r2_t_temp)) / 2 });
1088 if (r2_t->getFromPhase()->readyToSwitch) {
1093 transitions.push_back({ r1_t_temp, r2_t, (float)(r2_t->getDistance(r1_t_temp) + r1_t_temp->
getDistance(r2_t)) / 2 });
1098 if (!transitions.empty()) {
1099 if (transitions.back().distance < 1) {
1114 bool controlled =
false;
1115 std::string phaseChars =
"";
1117 phaseChars += p->getNEMAChar(i);
1118 if (p->controlledIndex(i)) {
1119 out[i] = p->getNEMAChar(i);
1126 if (std::count(phaseChars.begin(), phaseChars.end(), priority_char)) {
1127 out[i] = priority_char;
1139#ifdef DEBUG_NEMA_SWITCH
1140 std::cout <<
SIMTIME <<
" trySwitch tls=" <<
getID() <<
"\n";
1149 p->checkMyDetectors();
1166 if (transitions.size() > 1) {
1167 std::sort(transitions.begin(), transitions.end(),
1169 return i.distance < j.distance;
1174 nextPhases[0] = transitions.front().p1;
1175 nextPhases[1] = transitions.front().p2;
1180 if (p->readyToSwitch) {
1181 p->exit(
this, nextPhases);
1198 p->clearMyDetectors();
1217 p->maxDuration = p->nextMaxDuration;
1233 bool minRecall,
bool maxRecall,
bool fixForceOff,
int barrierNum,
int ringNum,
1236 phaseName(phaseName),
1237 isAtBarrier(isBarrier),
1238 isGreenRest(isGreenRest),
1239 barrierNum(barrierNum),
1240 coordinatePhase(isCoordinated),
1241 minRecall(minRecall),
1242 maxRecall(maxRecall),
1243 fixForceOff(fixForceOff),
1246 myPhaseStringInds(phaseStringInds) {
1290 return i->distance < j->distance;
1295 crossPhaseSource > 0 ? controller->
getPhaseObj(crossPhaseSource) :
nullptr,
1296 crossPhaseTarget > 0 ? controller->
getPhaseObj(crossPhaseTarget) :
nullptr
1332 if (ch ==
'G' || ch ==
'g') {
1364 if (d->getCurrentVehicleNumber() > 0) {
1373 if (d->getCurrentVehicleNumber() > 0) {
1385#ifdef DEBUG_NEMA_SWITCH
1439 if (nextPhases[
ringNum]->getToPhase() !=
this) {
1460 otherPhase->
exit(controller, nextPhases);
1539 bool vehicleActive =
false;
1543 && p->callActive()) {
1545 vehicleActive =
true;
1555 if (!vehicleActive) {
1578 enter(controller,
this);
1591 if (t->getToPhase()->phaseName == toPhase) {
1601std::vector<PhaseTransitionLogic*>
1604 std::vector<PhaseTransitionLogic*> nextTransitions;
1609 if (t->okay(controller)) {
1614 nextTransitions.push_back(t);
1618 nextTransitions.push_back(t);
1628 bool sameBarrier =
false;
1629 for (
auto& t : nextTransitions) {
1640 if (!found && !sameBarrier) {
1645 if (nextTransitions.size() < 1) {
1649 return nextTransitions;
1658 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 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_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)
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Representation of a lane in the micro simulation.
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
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).
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 it's 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.
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
PhaseDetectorInfo PhaseDetectorInfo
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
SUMOTime calcVehicleExtension(SUMOTime duration)
}
void init(NEMALogic *controller, int crossPhaseTarget, int crossPhaseSource, bool latching)
initializes the object
bool isTransitionActive() const
check if a transition is active
PhaseTransitionLogic * getTransition(int toPhase)
return the PhaseTransitionLogic matching the toPhase
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
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
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