52 const std::string& subid,
int noLinks,
54 Named(id), myNumLinks(noLinks), mySubID(subid),
89 if (std::string::npos != illegal) {
90 throw ProcessError(
"When adding phase: illegal character '" +
toString(state[illegal]) +
"' in state");
93 if (index < 0 || index >= (
int)
myPhases.size()) {
103 if (index >= (
int)
myPhases.size()) {
115 p.state = p.state.substr(0, numLinks);
118 std::string add(numLinks -
myNumLinks, (
char)fill);
120 p.state = p.state + add;
137 for (PhaseDefinitionVector::const_iterator i =
myPhases.begin(); i !=
myPhases.end(); ++i) {
138 duration += (*i).duration;
146 for (
int i = 0; i < (int)
myPhases.size() - 1;) {
169 if (checkVarDurations) {
180 WRITE_WARNING(
"Non-static traffic light '" +
getID() +
"' does not define variable phase length.");
189 assert(phaseIndex < (
int)
myPhases.size());
190 std::string& phaseState =
myPhases[phaseIndex].state;
191 assert(tlIndex < (
int)phaseState.size());
192 phaseState[tlIndex] = (char)linkState;
198 assert(phaseIndex < (
int)
myPhases.size());
199 myPhases[phaseIndex].duration = duration;
204 assert(phaseIndex < (
int)
myPhases.size());
205 myPhases[phaseIndex].minDur = duration;
210 assert(phaseIndex < (
int)
myPhases.size());
211 myPhases[phaseIndex].maxDur = duration;
SUMOTime getOffset() const
Returns the offset of first switch.
void setPhaseMaxDuration(int phaseIndex, SUMOTime duration)
void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState)
Modifies the state for an existing phase (used by NETEDIT)
A SUMO-compliant built logic for a traffic light.
static const std::string ALLOWED_TLS_LINKSTATES
all allowed characters for phase state
int myNumLinks
The number of participating links.
void deletePhase(int index)
NBTrafficLightLogic(const std::string &id, const std::string &subid, int noLinks, SUMOTime offset=0, TrafficLightType type=TLTYPE_STATIC)
Constructor.
void setPhaseMinDuration(int phaseIndex, SUMOTime duration)
static const SUMOTime UNSPECIFIED_DURATION
const std::string & getProgramID() const
Returns the ProgramID.
const std::string & getID() const
Returns the id.
The definition of a single phase of the logic.
#define WRITE_WARNING(msg)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
SUMOTime myOffset
The tls program's offset.
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
Base class for objects which have an id.
SUMOTime getDuration() const
Returns the duration of the complete cycle.
void closeBuilding(bool checkVarDurations=true)
closes the building process
TrafficLightType getType() const
get the algorithm type (static etc..)
const std::string mySubID
The tls program's subid.
~NBTrafficLightLogic()
Destructor.
void setPhaseDuration(int phaseIndex, SUMOTime duration)
Modifies the duration for an existing phase (used by NETEDIT)
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
TrafficLightType myType
The algorithm type for the traffic light.
void addStep(SUMOTime duration, const std::string &state, int index=-1)
Adds a phase to the logic.
PhaseDefinitionVector myPhases
The junction logic's storage for traffic light phase list.