50 const std::string& subid,
int noLinks,
52 Named(id), myNumLinks(noLinks), mySubID(subid),
58 Named(logic->getID()),
59 myNumLinks(logic->myNumLinks),
60 mySubID(logic->getProgramID()),
61 myOffset(logic->getOffset()),
62 myPhases(logic->myPhases.begin(), logic->myPhases.end()),
63 myType(logic->getType()) {}
86 const std::string& name,
87 const std::vector<int>& next,
99 if (std::string::npos != illegal) {
100 throw ProcessError(
"When adding phase: illegal character '" +
toString(state[illegal]) +
"' in state");
103 if (index < 0 || index >= (
int)
myPhases.size()) {
107 myPhases.insert(
myPhases.begin() + index,
PhaseDefinition(duration, state, minDur, maxDur, earliestEnd, latestEnd, vehExt, yellow, red, next, name));
113 if (index >= (
int)
myPhases.size()) {
123 if (indexPhaseA >= (
int)
myPhases.size()) {
127 if (indexPhaseB >= (
int)
myPhases.size()) {
132 const auto auxPhase =
myPhases.at(indexPhaseA);
134 myPhases.at(indexPhaseB) = auxPhase;
140 const auto firstPhase =
myPhases.front();
148 const auto lastPhase =
myPhases.back();
157 p.state = p.state.substr(0, numLinks);
160 std::string add(numLinks -
myNumLinks, (
char)fill);
162 p.state = p.state + add;
174 p.state.erase(index, 1);
190 for (PhaseDefinitionVector::const_iterator i =
myPhases.begin(); i !=
myPhases.end(); ++i) {
191 duration += (*i).duration;
199 for (
int i = 0; i < (int)
myPhases.size() - 1;) {
222 if (checkVarDurations) {
233 WRITE_WARNING(
"Non-static traffic light '" +
getID() +
"' does not define variable phase length.");
242 assert(phaseIndex < (
int)
myPhases.size());
243 std::string& phaseState =
myPhases[phaseIndex].state;
244 assert(tlIndex < (
int)phaseState.size());
245 phaseState[tlIndex] = (char)linkState;
251 assert(phaseIndex < (
int)
myPhases.size());
252 myPhases[phaseIndex].duration = duration;
258 assert(phaseIndex < (
int)
myPhases.size());
259 myPhases[phaseIndex].minDur = duration;
265 assert(phaseIndex < (
int)
myPhases.size());
266 myPhases[phaseIndex].maxDur = duration;
272 assert(phaseIndex < (
int)
myPhases.size());
273 myPhases[phaseIndex].earliestEnd = duration;
279 assert(phaseIndex < (
int)
myPhases.size());
280 myPhases[phaseIndex].latestEnd = duration;
286 assert(phaseIndex < (
int)
myPhases.size());
287 myPhases[phaseIndex].vehExt = duration;
293 assert(phaseIndex < (
int)
myPhases.size());
294 myPhases[phaseIndex].yellow = duration;
300 assert(phaseIndex < (
int)
myPhases.size());
301 myPhases[phaseIndex].red = duration;
307 assert(phaseIndex < (
int)
myPhases.size());
314 assert(phaseIndex < (
int)
myPhases.size());
321 assert(phaseIndex < (
int)
myPhases.size());
322 for (
int i = 0; i < (int)
myPhases[phaseIndex].state.size(); i++) {
#define WRITE_WARNING(msg)
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static const SUMOTime UNSPECIFIED_DURATION
The definition of a single phase of the logic.
A SUMO-compliant built logic for a traffic light.
SUMOTime getDuration() const
Returns the duration of the complete cycle.
void setPhaseVehExt(int phaseIndex, SUMOTime duration)
Modifies the veh ex for an existing phase (used by NETEDIT)
void deleteStateIndex(int index)
remove the index from all phase states
void resetPhases()
deletes all phases and reset the expect number of links
void setPhaseEarliestEnd(int phaseIndex, SUMOTime duration)
Modifies the min duration for an existing phase (used by NETEDIT)
void setPhaseRed(int phaseIndex, SUMOTime duration)
Modifies the veh ex for an existing phase (used by NETEDIT)
int myNumLinks
The number of participating links.
void setPhaseMinDuration(int phaseIndex, SUMOTime duration)
Modifies the min duration for an existing phase (used by NETEDIT)
void swaplastPhase()
swap first phase
NBTrafficLightLogic(const std::string &id, const std::string &subid, int noLinks, SUMOTime offset=0, TrafficLightType type=TrafficLightType::STATIC)
Constructor.
void closeBuilding(bool checkVarDurations=true)
closes the building process
void swapPhase(int indexPhaseA, int indexPhaseB)
void overrideState(int phaseIndex, const char c)
override state with the given character(used by NETEDIT)
PhaseDefinitionVector myPhases
The junction logic's storage for traffic light phase list.
void setPhaseName(int phaseIndex, const std::string &name)
Modifies the phase name (used by NETEDIT)
void setPhaseDuration(int phaseIndex, SUMOTime duration)
Modifies the duration for an existing phase (used by NETEDIT)
void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState)
Modifies the state for an existing phase (used by NETEDIT)
void setPhaseMaxDuration(int phaseIndex, SUMOTime duration)
Modifies the max duration for an existing phase (used by NETEDIT)
void setPhaseYellow(int phaseIndex, SUMOTime duration)
Modifies the veh ex for an existing phase (used by NETEDIT)
void setPhaseLatestEnd(int phaseIndex, SUMOTime duration)
Modifies the max duration for an existing phase (used by NETEDIT)
void setPhaseNext(int phaseIndex, const std::vector< int > &next)
Modifies the next phase (used by NETEDIT)
~NBTrafficLightLogic()
Destructor.
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
void deletePhase(int index)
void swapfirstPhase()
swap first phase
TrafficLightType myType
The algorithm type for the traffic light.
void addStep(const SUMOTime duration, const std::string &state, const std::vector< int > &next=std::vector< int >(), const std::string &name="", const int index=-1)
Adds a phase to the logic (static)
Base class for objects which have an id.
const std::string & getID() const
Returns the id.
static const std::string ALLOWED_TLS_LINKSTATES
all allowed characters for phase state