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()) {
88 const std::string& name,
89 const std::vector<int>& next,
101 if (std::string::npos != illegal) {
105 if (index < 0 || index >= (
int)
myPhases.size()) {
109 myPhases.insert(
myPhases.begin() + index,
PhaseDefinition(duration, state, minDur, maxDur, earliestEnd, latestEnd, vehExt, yellow, red, next, name));
115 if (index >= (
int)
myPhases.size()) {
125 if (indexPhaseA >= (
int)
myPhases.size()) {
129 if (indexPhaseB >= (
int)
myPhases.size()) {
134 const auto auxPhase =
myPhases.at(indexPhaseA);
136 myPhases.at(indexPhaseB) = auxPhase;
142 const auto firstPhase =
myPhases.front();
150 const auto lastPhase =
myPhases.back();
159 p.state = p.state.substr(0, numLinks);
162 std::string add(numLinks -
myNumLinks, (
char)fill);
164 p.state = p.state + add;
176 p.state.erase(index, 1);
192 for (PhaseDefinitionVector::const_iterator i =
myPhases.begin(); i !=
myPhases.end(); ++i) {
193 duration += (*i).duration;
201 for (
int i = 0; i < (int)
myPhases.size() - 1;) {
224 if (checkVarDurations) {
244 assert(phaseIndex < (
int)
myPhases.size());
245 std::string& phaseState =
myPhases[phaseIndex].state;
246 assert(tlIndex < (
int)phaseState.size());
247 phaseState[tlIndex] = (char)linkState;
253 assert(phaseIndex < (
int)
myPhases.size());
254 myPhases[phaseIndex].duration = duration;
260 assert(phaseIndex < (
int)
myPhases.size());
261 myPhases[phaseIndex].minDur = duration;
267 assert(phaseIndex < (
int)
myPhases.size());
268 myPhases[phaseIndex].maxDur = duration;
274 assert(phaseIndex < (
int)
myPhases.size());
275 myPhases[phaseIndex].earliestEnd = duration;
281 assert(phaseIndex < (
int)
myPhases.size());
282 myPhases[phaseIndex].latestEnd = duration;
288 assert(phaseIndex < (
int)
myPhases.size());
289 myPhases[phaseIndex].vehExt = duration;
295 assert(phaseIndex < (
int)
myPhases.size());
296 myPhases[phaseIndex].yellow = duration;
302 assert(phaseIndex < (
int)
myPhases.size());
303 myPhases[phaseIndex].red = duration;
309 assert(phaseIndex < (
int)
myPhases.size());
316 assert(phaseIndex < (
int)
myPhases.size());
323 assert(phaseIndex < (
int)
myPhases.size());
324 for (
int i = 0; i < (int)
myPhases[phaseIndex].state.size(); i++) {
#define WRITE_WARNINGF(...)
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.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void updateParameters(const Parameterised::Map &mapArg)
Adds or updates all given parameters from the map.
static const std::string ALLOWED_TLS_LINKSTATES
all allowed characters for phase state