40#define DEBUG_COND (getID()=="C")
134 assert((
int)
myPhases.size() > givenStep);
157 for (
int i = 0; i <
myStep; i++) {
170 assert(index < (
int)
myPhases.size());
175 for (
int i = 0; i < index; i++) {
189 for (
int i = 0; i < (int)
myPhases.size(); i++) {
191 if (testPos > offset) {
194 if (testPos == offset) {
195 assert((
int)
myPhases.size() > (i + 1));
223#ifdef DEBUG_COORDINATION
236 if (latest > earliest && latest < minEnd) {
239 }
else if (latest < earliest && latest >= minEnd) {
243#ifdef DEBUG_COORDINATION
270#ifdef DEBUG_COORDINATION
292 if (step >= 0 && step !=
myStep) {
305 assert(step < (
int)phases.size());
315 for (
int i = 0; i < (int)
myPhases.size(); i++) {
332 if (key ==
"cycleTime") {
334 }
else if (key ==
"offset") {
336 }
else if (key ==
"coordinated") {
338 }
else if (key ==
"cycleSecond") {
340 }
else if (key ==
"typeName") {
348 if (key ==
"cycleTime") {
351 }
else if (key ==
"cycleSecond" || key ==
"typeName") {
352 throw InvalidArgument(key +
" cannot be changed dynamically for traffic light '" +
getID() +
"'");
353 }
else if (key ==
"offset") {
355 }
else if (key ==
"coordinated") {
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
@ SUMO_TAG_TLLOGIC
a traffic light logic
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
The definition of a single phase of a tls logic.
static const SUMOTime UNSPECIFIED_DURATION
SUMOTime myLastSwitch
Stores the timestep of the last on-switched of the phase.
SUMOTime duration
The duration of the phase.
SUMOTime getLatest() const
the maximum duration for keeping the current phase when considering 'latestEnd'
int getIndexFromOffset(SUMOTime offset) const override
Returns the step (the phasenumber) of a given position of the cycle.
virtual void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration) override
Changes the current phase and her duration.
Phases myPhases
The list of phases this logic uses.
virtual void saveState(OutputDevice &out) const override
Saves the current tls states into the given stream.
const MSPhaseDefinition & getPhase(int givenstep) const override
Returns the definition of the phase from the given position within the plan.
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const override
Returns the index of the logic at the given simulation step.
SUMOTime getOffsetFromIndex(int index) const override
Returns the position (start of a phase during a cycle) from of a given step.
int getPhaseNumber() const override
Returns the number of phases.
SUMOTime getEarliest(SUMOTime prevStart) const
the minimum duration for keeping the current phase when considering 'earliestEnd'
void setPhases(const Phases &phases, int index)
Replaces the phases and set the phase index.
~MSSimpleTrafficLightLogic()
Destructor.
MSSimpleTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const SUMOTime offset, const TrafficLightType logicType, const Phases &phases, int step, SUMOTime delay, const Parameterised::Map ¶meters)
Constructor.
virtual SUMOTime mapTimeInCycle(SUMOTime t) const override
map the given time into the current cycle
int myStep
The current step.
bool myCoordinated
whether coordination parameters earliestEnd, latestEnd are
int getCurrentPhaseIndex() const override
Returns the current index within the program.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const override
gets a parameter
void deletePhases()
frees memory responsibilities
const Phases & getPhases() const override
Returns the phases of this tls program.
virtual void setParameter(const std::string &key, const std::string &value) override
Sets a parameter and updates internal constants.
virtual SUMOTime trySwitch() override
Switches to the next phase.
const MSPhaseDefinition & getCurrentPhaseDef() const override
Returns the definition of the current phase.
void executeOnSwitchActions() const
A class that stores and controls tls and switching of their programs.
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
Class realising the switch between the traffic light phases.
void deschedule(MSTrafficLightLogic *tlLogic)
Marks this swicth as invalid (if the phase duration has changed, f.e.)
The parent class for traffic light logics.
SUMOTime myOffset
the offset parameter of the current program
SUMOTime computeCycleTime(const Phases &phases)
virtual SUMOTime getLatestEnd(int step=-1) const
std::vector< SUMOTime > myOverridingTimes
A list of duration overrides.
virtual SUMOTime getMinDur(int step=-1) const
SUMOTime myDefaultCycleTime
The cycle time (without changes)
SUMOTime getTimeInCycle() const
return time within the current cycle
const std::string & getProgramID() const
Returns this tl-logic's id.
TrafficLightType getLogicType() const
Returns the type of the logic.
virtual SUMOTime getEarliestEnd(int step=-1) const
SwitchCommand * mySwitchCommand
The current switch command.
SUMOTime myCurrentDurationIncrement
A value for enlarge the current duration.
virtual SUMOTime getMaxDur(int step=-1) const
SUMOTime getNextSwitchTime() const
Returns the assumed next switch time.
SUMOTime getSpentDuration(SUMOTime simStep=-1) const
Returns the duration spent in the current phase.
bool setTrafficLightSignals(SUMOTime t) const
Applies the current signal states to controlled links.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
const std::string & getID() const
Returns the id.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
std::map< std::string, std::string > Map
parameters map
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter