50 const std::string& subid,
int noLinks,
52 Named(id), myNumLinks(noLinks), mySubID(subid),
57 Named(logic->getID()),
58 myNumLinks(logic->myNumLinks),
59 mySubID(logic->getProgramID()),
60 myOffset(logic->getOffset()),
61 myPhases(logic->myPhases.begin(), logic->myPhases.end()),
62 myType(logic->getType()) {}
87 if (std::string::npos != illegal) {
88 throw ProcessError(
"When adding phase: illegal character '" +
toString(state[illegal]) +
"' in state");
91 if (index < 0 || index >= (
int)
myPhases.size()) {
101 if (index >= (
int)
myPhases.size()) {
113 p.state = p.state.substr(0, numLinks);
116 std::string add(numLinks -
myNumLinks, (
char)fill);
118 p.state = p.state + add;
129 p.state.erase(index, 1);
145 for (PhaseDefinitionVector::const_iterator i =
myPhases.begin(); i !=
myPhases.end(); ++i) {
146 duration += (*i).duration;
154 for (
int i = 0; i < (int)
myPhases.size() - 1;) {
177 if (checkVarDurations) {
188 WRITE_WARNING(
"Non-static traffic light '" +
getID() +
"' does not define variable phase length.");
197 assert(phaseIndex < (
int)
myPhases.size());
198 std::string& phaseState =
myPhases[phaseIndex].state;
199 assert(tlIndex < (
int)phaseState.size());
200 phaseState[tlIndex] = (char)linkState;
206 assert(phaseIndex < (
int)
myPhases.size());
207 myPhases[phaseIndex].duration = duration;
212 assert(phaseIndex < (
int)
myPhases.size());
213 myPhases[phaseIndex].minDur = duration;
218 assert(phaseIndex < (
int)
myPhases.size());
219 myPhases[phaseIndex].maxDur = duration;
224 assert(phaseIndex < (
int)
myPhases.size());
230 assert(phaseIndex < (
int)
myPhases.size());
#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 deleteStateIndex(int index)
remove the index from all phase states
int myNumLinks
The number of participating links.
void setPhaseMinDuration(int phaseIndex, SUMOTime duration)
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
PhaseDefinitionVector myPhases
The junction logic's storage for traffic light phase list.
void setPhaseName(int phaseIndex, const std::string &name)
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)
void addStep(SUMOTime duration, const std::string &state, const std::vector< int > &next=std::vector< int >(), const std::string &name="", int index=-1)
Adds a phase to the logic.
void setPhaseNext(int phaseIndex, const std::vector< int > &next)
~NBTrafficLightLogic()
Destructor.
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
void deletePhase(int index)
TrafficLightType myType
The algorithm type for the traffic light.
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