70 const std::string& subid,
int noLinks,
72 Named(id), myNumLinks(noLinks), mySubID(subid),
106 const std::string::size_type illegal = state.find_first_not_of(
ALLOWED_STATES);
107 if (std::string::npos != illegal) {
108 throw ProcessError(
"When adding phase: illegal character '" +
toString(state[illegal]) +
"' in state");
111 if (index < 0 || index >= (
int)
myPhases.size()) {
121 if (index >= (
int)
myPhases.size()) {
133 p.state = p.state.substr(0, numLinks);
136 std::string add(numLinks -
myNumLinks, (
char)fill);
138 p.state = p.state + add;
155 for (PhaseDefinitionVector::const_iterator i =
myPhases.begin(); i !=
myPhases.end(); ++i) {
156 duration += (*i).duration;
164 for (
int i = 0; i < (int)
myPhases.size() - 1;) {
187 if (checkVarDurations) {
198 WRITE_WARNING(
"Non-static traffic light '" +
getID() +
"' does not define variable phase length.");
207 assert(phaseIndex < (
int)
myPhases.size());
208 std::string& phaseState =
myPhases[phaseIndex].state;
209 assert(tlIndex < (
int)phaseState.size());
210 phaseState[tlIndex] = (char)linkState;
216 assert(phaseIndex < (
int)
myPhases.size());
217 myPhases[phaseIndex].duration = duration;
222 assert(phaseIndex < (
int)
myPhases.size());
223 myPhases[phaseIndex].minDur = duration;
228 assert(phaseIndex < (
int)
myPhases.size());
229 myPhases[phaseIndex].maxDur = duration;
The link has green light, may pass.
static const std::string ALLOWED_STATES
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.
The link has green light, has to brake.
This is an uncontrolled, minor link, has to stop.
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.
The link is controlled by a tls which is off, not blinking, may pass.
#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
The link has yellow light, may pass.
The link is controlled by a tls which is off and blinks, has to brake.
TrafficLightType getType() const
get the algorithm type (static etc..)
const std::string mySubID
The tls program's subid.
~NBTrafficLightLogic()
Destructor.
The link has red light (must brake)
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.
The link has yellow light, has to brake anyway.
void addStep(SUMOTime duration, const std::string &state, int index=-1)
Adds a phase to the logic.
The link has red light (must brake) but indicates upcoming green.
PhaseDefinitionVector myPhases
The junction logic's storage for traffic light phase list.
static const char allowedStatesInitializer[]
all allowed characters for phase state (see SUMOXMLDefinitions)