SUMO - Simulation of Urban MObility
MSTrafficLightLogic Class Reference

The parent class for traffic light logics. More...

#include <MSTrafficLightLogic.h>

Inheritance diagram for MSTrafficLightLogic:
MSOffTrafficLightLogic MSSimpleTrafficLightLogic MSActuatedTrafficLightLogic MSAgentbasedTrafficLightLogic

Data Structures

class  SwitchCommand
 Class realising the switch between the traffic light phases. More...

Public Types

Structure definitions
typedef std::vector
< MSPhaseDefinition * > 
Phases
 Definition of a list of phases, being the junction logic.
typedef std::vector< MSLink * > LinkVector
 Definition of the list of links that participate in this tl-light.
typedef std::vector< LinkVectorLinkVectorVector
 Definition of a list that holds lists of links that do have the same attribute.
typedef std::vector< MSLane * > LaneVector
 Definition of the list of links that participate in this tl-light.
typedef std::vector< LaneVectorLaneVectorVector
 Definition of a list that holds lists of links that do have the same attribute.

Public Member Functions

virtual void init (NLDetectorBuilder &nb)
 Initialises the tls with information about incoming lanes.
 MSTrafficLightLogic (MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, SUMOTime delay)
 Constructor.
virtual ~MSTrafficLightLogic ()
 Destructor.
Handling of controlled links
void addLink (MSLink *link, MSLane *lane, unsigned int pos)
 Adds a link on building.
virtual void adaptLinkInformationFrom (const MSTrafficLightLogic &logic)
 Applies information about controlled links and lanes from the given logic.
std::map< MSLink *, LinkStatecollectLinkStates () const
 Returns the (uncontrolled) states of the controlled links.
void resetLinkStates (const std::map< MSLink *, LinkState > &vals) const
 Resets the states of controlled links.
Switching and setting current rows
virtual SUMOTime trySwitch (bool isActive)=0
 Switches to the next phase.
bool setTrafficLightSignals (SUMOTime t) const
 Applies the current signal states to controlled links.
Static Information Retrieval
const std::string & getID () const
 Returns this tl-logic's id.
const std::string & getProgramID () const
 Returns this tl-logic's id.
const LaneVectorVectorgetLanes () const
 Returns the list of lists of all lanes controlled by this tls.
const LaneVectorgetLanesAt (unsigned int i) const
 Returns the list of lanes that are controlled by the signals at the given position.
const LinkVectorVectorgetLinks () const
 Returns the list of lists of all affected links.
const LinkVectorgetLinksAt (unsigned int i) const
 Returns the list of links that are controlled by the signals at the given position.
int getLinkIndex (const MSLink *const link) const
 Returns the index of the given link.
virtual unsigned int getPhaseNumber () const =0
 Returns the number of phases.
virtual const PhasesgetPhases () const =0
 Returns the phases of this tls program.
virtual const MSPhaseDefinitiongetPhase (unsigned int givenstep) const =0
 Returns the definition of the phase from the given position within the plan.
Dynamic Information Retrieval
virtual unsigned int getCurrentPhaseIndex () const =0
 Returns the current index within the program.
virtual const MSPhaseDefinitiongetCurrentPhaseDef () const =0
 Returns the definition of the current phase.
SUMOTime getDefaultCycleTime () const
 Returns the cycle time (in ms)
SUMOTime getNextSwitchTime () const
 Returns the assumed next switch time.
Conversion between time and phase
virtual SUMOTime getPhaseIndexAtTime (SUMOTime simStep) const =0
 Returns the index of the logic at the given simulation step.
virtual SUMOTime getOffsetFromIndex (unsigned int index) const =0
 Returns the position (start of a phase during a cycle) from of a given step.
virtual unsigned int getIndexFromOffset (SUMOTime offset) const =0
 Returns the step (the phasenumber) of a given position of the cycle.
Changing phases and phase durations
void addOverridingDuration (SUMOTime duration)
 Changes the duration of the next phase.
void setCurrentDurationIncrement (SUMOTime delay)
 Delays current phase by the given delay.
virtual void changeStepAndDuration (MSTLLogicControl &tlcontrol, SUMOTime simStep, unsigned int step, SUMOTime stepDuration)=0
 Changes the current phase and her duration.
Algorithm parameter handling
void setParameter (const std::map< std::string, std::string > &params)
 Inserts read parameter.
std::string getParameterValue (const std::string &key) const
 Returns a named parameter.

Protected Attributes

SUMOTime myCurrentDurationIncrement
 A value for enlarge the current duration.
SUMOTime myDefaultCycleTime
 The cycle time (without changes)
std::string myID
 The id of the logic.
LaneVectorVector myLanes
 The list of links which do participate in this traffic light.
LinkVectorVector myLinks
 The list of links which do participate in this traffic light.
std::vector< SUMOTimemyOverridingTimes
 A list of duration overrides.
std::map< std::string,
std::string > 
myParameter
 Given parameter.
std::string myProgramID
SwitchCommandmySwitchCommand
 The current switch command.

Private Member Functions

 MSTrafficLightLogic (const MSTrafficLightLogic &s)
 invalidated copy constructor
MSTrafficLightLogicoperator= (const MSTrafficLightLogic &s)
 invalidated assignment operator

Detailed Description

The parent class for traffic light logics.

Definition at line 62 of file MSTrafficLightLogic.h.


Member Typedef Documentation

typedef std::vector<MSLane*> MSTrafficLightLogic::LaneVector

Definition of the list of links that participate in this tl-light.

Definition at line 77 of file MSTrafficLightLogic.h.

Definition of a list that holds lists of links that do have the same attribute.

Definition at line 80 of file MSTrafficLightLogic.h.

typedef std::vector<MSLink*> MSTrafficLightLogic::LinkVector

Definition of the list of links that participate in this tl-light.

Definition at line 71 of file MSTrafficLightLogic.h.

Definition of a list that holds lists of links that do have the same attribute.

Definition at line 74 of file MSTrafficLightLogic.h.

Definition of a list of phases, being the junction logic.

Definition at line 68 of file MSTrafficLightLogic.h.


Constructor & Destructor Documentation

MSTrafficLightLogic::MSTrafficLightLogic ( MSTLLogicControl tlcontrol,
const std::string &  id,
const std::string &  programID,
SUMOTime  delay 
)

Constructor.

Parameters:
[in]tlcontrolThe tls control responsible for this tls
[in]idThis tls' id
[in]programIDThis tls' sub-id (program id)
[in]delayThe time to wait before the first switch

Definition at line 102 of file MSTrafficLightLogic.cpp.

References MSEventControl::addEvent(), MSNet::getBeginOfTimestepEvents(), MSNet::getInstance(), mySwitchCommand, and MSEventControl::NO_CHANGE.

invalidated copy constructor


Member Function Documentation

Applies information about controlled links and lanes from the given logic.

If we load a logic after the network has been loaded, we do not get the information about controlled links afterwards. We have to copy them from a previously loaded logic.

Parameters:
[in]logicThe logic to use the information about controlled links/lanes from

Reimplemented in MSOffTrafficLightLogic.

Definition at line 143 of file MSTrafficLightLogic.cpp.

References myLanes, and myLinks.

Referenced by MSTLLogicControl::TLSLogicVariants::addLogic().

void MSTrafficLightLogic::addLink ( MSLink link,
MSLane lane,
unsigned int  pos 
)

Adds a link on building.

Parameters:
[in]linkThe controlled link
[in]laneThe lane this link starts at
[in]posThe link's index (signal group) within this program

Definition at line 125 of file MSTrafficLightLogic.cpp.

References getCurrentPhaseDef(), MSNet::getInstance(), myLanes, myLinks, and MSLink::setTLState().

Changes the duration of the next phase.

Parameters:
[in]durationThe new duration

Definition at line 216 of file MSTrafficLightLogic.cpp.

References myOverridingTimes.

virtual void MSTrafficLightLogic::changeStepAndDuration ( MSTLLogicControl tlcontrol,
SUMOTime  simStep,
unsigned int  step,
SUMOTime  stepDuration 
) [pure virtual]

Changes the current phase and her duration.

Parameters:
[in]tlcontrolThe responsible traffic lights control
[in]simStepThe current simulation step
[in]stepIndex of the phase to use
[in]stepDurationThe left duration of the phase

Implemented in MSOffTrafficLightLogic, and MSSimpleTrafficLightLogic.

Referenced by TraCIServerAPI_TLS::processSet(), and MSTLLogicControl::WAUTSwitchProcedure::switchToPos().

Returns the (uncontrolled) states of the controlled links.

Returns:
The controlled link's states

Definition at line 150 of file MSTrafficLightLogic.cpp.

References myLinks.

Returns the cycle time (in ms)

Returns:
The (maybe changing) cycle time of this tls

Definition at line 263 of file MSTrafficLightLogic.h.

References myDefaultCycleTime.

Referenced by MSTLLogicControl::WAUTSwitchProcedure::isPosAtGSP().

virtual unsigned int MSTrafficLightLogic::getIndexFromOffset ( SUMOTime  offset) const [pure virtual]

Returns the step (the phasenumber) of a given position of the cycle.

Parameters:
[in]offsetThe offset (time) for which the according phase shall be returned
Returns:
The according phase

Implemented in MSOffTrafficLightLogic, and MSSimpleTrafficLightLogic.

Referenced by MSTLLogicControl::WAUTSwitchProcedure::getDiffToStartOfPhase(), and MSTLLogicControl::WAUTSwitchProcedure::switchToPos().

Returns the list of lists of all lanes controlled by this tls.

Returns:
All lanes controlled by this tls, sorted by the signal index

Definition at line 186 of file MSTrafficLightLogic.h.

References myLanes.

Referenced by GUITrafficLightLogicWrapper::getCenteringBoundary(), and TraCIServerAPI_TLS::processGet().

const LaneVector& MSTrafficLightLogic::getLanesAt ( unsigned int  i) const [inline]

Returns the list of lanes that are controlled by the signals at the given position.

Parameters:
[in]iThe index of the signal
Returns:
The lanes controlled by the signal at the given index

Definition at line 195 of file MSTrafficLightLogic.h.

References myLanes.

Referenced by MSAgentbasedTrafficLightLogic::collectData(), GUITrafficLightLogicWrapper::drawGL(), MSActuatedTrafficLightLogic::duration(), Command_SaveTLSSwitches::execute(), MSActuatedTrafficLightLogic::gapControl(), and GUIViewTraffic::onGamingClick().

int MSTrafficLightLogic::getLinkIndex ( const MSLink *const  link) const

Returns the index of the given link.

Parameters:
[in]linkThe link to retrieve the index for
Returns:
The index of the given link (-1 if it is not controlled by this tls)

Definition at line 192 of file MSTrafficLightLogic.cpp.

References myLinks.

Referenced by GUITrafficLightLogicWrapper::getLinkIndex().

const LinkVector& MSTrafficLightLogic::getLinksAt ( unsigned int  i) const [inline]

Returns the list of links that are controlled by the signals at the given position.

Parameters:
[in]iThe index of the signal
Returns:
The links controlled by the signal at the given index

Definition at line 212 of file MSTrafficLightLogic.h.

References myLinks.

Returns the assumed next switch time.

The time may change in case of adaptive/actuated traffic lights.

Returns:
The assumed next switch time (simulation time)

Definition at line 209 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::SwitchCommand::getNextSwitchTime(), and mySwitchCommand.

Referenced by MSTLLogicControl::WAUTSwitchProcedure::isPosAtGSP(), and TraCIServerAPI_TLS::processGet().

virtual SUMOTime MSTrafficLightLogic::getOffsetFromIndex ( unsigned int  index) const [pure virtual]

Returns the position (start of a phase during a cycle) from of a given step.

Parameters:
[in]indexThe index of the phase to return the begin of
Returns:
The begin time of the phase

Implemented in MSOffTrafficLightLogic, and MSSimpleTrafficLightLogic.

Referenced by MSTLLogicControl::WAUTSwitchProcedure::getDiffToStartOfPhase(), and MSTLLogicControl::WAUTSwitchProcedure::isPosAtGSP().

std::string MSTrafficLightLogic::getParameterValue ( const std::string &  key) const

Returns a named parameter.

Parameters:
[in]keyThe name of the parameter
Returns:
The value of the parameter, "" if the parameter is not known

Definition at line 237 of file MSTrafficLightLogic.cpp.

References myParameter.

Referenced by MSTLLogicControl::WAUTSwitchProcedure::getGSPValue(), MSTLLogicControl::WAUTSwitchProcedure_Stretch::getStretchAreaNo(), and MSTLLogicControl::WAUTSwitchProcedure_Stretch::getStretchBereichDef().

virtual const MSPhaseDefinition& MSTrafficLightLogic::getPhase ( unsigned int  givenstep) const [pure virtual]

Returns the definition of the phase from the given position within the plan.

Parameters:
[in]givenstepThe index of the phase within the plan
Returns:
The definition of the phase at the given position

Implemented in MSOffTrafficLightLogic, and MSSimpleTrafficLightLogic.

Referenced by MSTLLogicControl::TLSLogicVariants::addLogic(), TraCIServerAPI_TLS::processGet(), TraCIServerAPI_TLS::processSet(), and MSTLLogicControl::WAUTSwitchProcedure::switchToPos().

virtual SUMOTime MSTrafficLightLogic::getPhaseIndexAtTime ( SUMOTime  simStep) const [pure virtual]

Returns the index of the logic at the given simulation step.

Returns:
The (estimated) index of the tls at the given simulation time step

Implemented in MSOffTrafficLightLogic, and MSSimpleTrafficLightLogic.

virtual unsigned int MSTrafficLightLogic::getPhaseNumber ( ) const [pure virtual]

Returns the number of phases.

Returns:
The number of this tls program's phases

Implemented in MSOffTrafficLightLogic, and MSSimpleTrafficLightLogic.

Referenced by TraCIServerAPI_TLS::processGet(), and TraCIServerAPI_TLS::processSet().

virtual const Phases& MSTrafficLightLogic::getPhases ( ) const [pure virtual]

Returns the phases of this tls program.

Returns:
The phases of this tls program

Implemented in MSOffTrafficLightLogic, and MSSimpleTrafficLightLogic.

Referenced by GUITrafficLightLogicWrapper::drawGL().

void MSTrafficLightLogic::init ( NLDetectorBuilder nb) [virtual]

Initialises the tls with information about incoming lanes.

Parameters:
[in]nbThe detector builder
[in]edgeContinuationsInformation about edge predecessors/successors
Exceptions:
ProcessErrorIf something fails on initialisation

Reimplemented in MSAgentbasedTrafficLightLogic, MSActuatedTrafficLightLogic, and MSOffTrafficLightLogic.

Definition at line 114 of file MSTrafficLightLogic.cpp.

Referenced by NLJunctionControlBuilder::closeTrafficLightLogic().

MSTrafficLightLogic& MSTrafficLightLogic::operator= ( const MSTrafficLightLogic s) [private]

invalidated assignment operator

void MSTrafficLightLogic::resetLinkStates ( const std::map< MSLink *, LinkState > &  vals) const

Resets the states of controlled links.

Parameters:
[in]valsThe state of controlled links to use

Definition at line 179 of file MSTrafficLightLogic.cpp.

References MSNet::getCurrentTimeStep(), MSNet::getInstance(), and myLinks.

Delays current phase by the given delay.

Parameters:
[in]delayThe time by which the current phase shall be delayed

Definition at line 222 of file MSTrafficLightLogic.cpp.

References myCurrentDurationIncrement.

void MSTrafficLightLogic::setParameter ( const std::map< std::string, std::string > &  params)

Inserts read parameter.

Parameters:
[in]paramsThe parameter to use

Definition at line 231 of file MSTrafficLightLogic.cpp.

References myParameter.

Referenced by NLJunctionControlBuilder::closeTrafficLightLogic().

Applies the current signal states to controlled links.

Parameters:
[in]tThe current time
Returns:
Always true
See also:
LinkState
MSLink::setTLState

Definition at line 163 of file MSTrafficLightLogic.cpp.

References getCurrentPhaseDef(), MSPhaseDefinition::getState(), and myLinks.

Referenced by MSTLLogicControl::TLSLogicVariants::addLogic(), and TraCIServerAPI_TLS::processSet().

virtual SUMOTime MSTrafficLightLogic::trySwitch ( bool  isActive) [pure virtual]

Switches to the next phase.

Parameters:
[in]isActiveWhether this program is the currently used one
Returns:
The time of the next switch

Implemented in MSAgentbasedTrafficLightLogic, MSActuatedTrafficLightLogic, MSOffTrafficLightLogic, and MSSimpleTrafficLightLogic.


Field Documentation

A value for enlarge the current duration.

Definition at line 427 of file MSTrafficLightLogic.h.

Referenced by setCurrentDurationIncrement(), and MSSimpleTrafficLightLogic::trySwitch().

std::string MSTrafficLightLogic::myID [protected]

The id of the logic.

Definition at line 415 of file MSTrafficLightLogic.h.

Referenced by getID(), MSActuatedTrafficLightLogic::init(), and MSAgentbasedTrafficLightLogic::init().

The list of links which do participate in this traffic light.

Definition at line 421 of file MSTrafficLightLogic.h.

Referenced by adaptLinkInformationFrom(), addLink(), getLanes(), getLanesAt(), MSActuatedTrafficLightLogic::init(), and MSAgentbasedTrafficLightLogic::init().

The list of links which do participate in this traffic light.

Definition at line 418 of file MSTrafficLightLogic.h.

Referenced by adaptLinkInformationFrom(), addLink(), collectLinkStates(), getLinkIndex(), getLinks(), getLinksAt(), resetLinkStates(), and setTrafficLightSignals().

A list of duration overrides.

Definition at line 424 of file MSTrafficLightLogic.h.

Referenced by addOverridingDuration(), and MSSimpleTrafficLightLogic::trySwitch().

std::map<std::string, std::string> MSTrafficLightLogic::myParameter [protected]

The documentation for this class was generated from the following files:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines