SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSActuatedTrafficLightLogic Class Reference

An actuated (adaptive) traffic light logic. More...

#include <MSActuatedTrafficLightLogic.h>

Inheritance diagram for MSActuatedTrafficLightLogic:
MSSimpleTrafficLightLogic MSTrafficLightLogic

Public Types

typedef std::map< MSLane
*, MSInductLoop * > 
InductLoopMap
 Definition of a map from lanes to induct loops lying on them.
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.
typedef std::map< std::string,
std::string > 
ParameterMap

Public Member Functions

void init (NLDetectorBuilder &nb)
 Initialises the tls with information about incoming lanes.
 MSActuatedTrafficLightLogic (MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const MSSimpleTrafficLightLogic::Phases &phases, unsigned int step, SUMOTime delay, const ParameterMap &parameter)
 Constructor.
 ~MSActuatedTrafficLightLogic ()
 Destructor.
Switching and setting current rows
SUMOTime trySwitch (bool isActive)
 Switches to the next phase.
Static Information Retrieval
unsigned int getPhaseNumber () const
 Returns the number of phases.
const PhasesgetPhases () const
 Returns the phases of this tls program.
PhasesgetPhases ()
 Returns the phases of this tls program.
const MSPhaseDefinitiongetPhase (unsigned int givenstep) const
 Returns the definition of the phase from the given position within the plan.
Dynamic Information Retrieval
unsigned int getCurrentPhaseIndex () const
 Returns the current index within the program.
const MSPhaseDefinitiongetCurrentPhaseDef () const
 Returns the definition of the current phase.
Conversion between time and phase
SUMOTime getPhaseIndexAtTime (SUMOTime simStep) const
 Returns the index of the logic at the given simulation step.
SUMOTime getOffsetFromIndex (unsigned int index) const
 Returns the position (start of a phase during a cycle) from of a given step.
unsigned int getIndexFromOffset (SUMOTime offset) const
 Returns the step (the phasenumber) of a given position of the cycle.
Changing phases and phase durations
void changeStepAndDuration (MSTLLogicControl &tlcontrol, SUMOTime simStep, unsigned int step, SUMOTime stepDuration)
 Changes the current phase and her duration.
void setPhases (const Phases &phases, unsigned int index)
 Replaces the phases and set the phase index.
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
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.
Dynamic Information Retrieval
SUMOTime getDefaultCycleTime () const
 Returns the cycle time (in ms)
SUMOTime getNextSwitchTime () const
 Returns the assumed next switch time.
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.
Algorithm parameter handling
void setParameter (const ParameterMap &params)
 Inserts read parameter.
std::string getParameterValue (const std::string &key) const
 Returns a named parameter.

Protected Member Functions

"actuated" algorithm methods
SUMOTime duration () const
 Returns the duration of the given step.
void gapControl ()
 Decides, whether a phase should be continued by checking the gaps of vehicles having green.

Protected Attributes

bool myContinue
 information whether the current phase should be lenghtend
SUMOTime myCurrentDurationIncrement
 A value for enlarge the current duration.
SUMOTime myDefaultCycleTime
 The cycle time (without changes)
SUMOReal myDetectorGap
 The detector distance.
std::string myID
 The id of the logic.
InductLoopMap myInductLoops
 A map from lanes to induct loops lying on them.
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.
SUMOReal myMaxGap
 The maximum gap to check.
std::vector< SUMOTimemyOverridingTimes
 A list of duration overrides.
ParameterMap myParameter
 Given parameter.
SUMOReal myPassingTime
 The passing time used.
Phases myPhases
 The list of phases this logic uses.
std::string myProgramID
unsigned int myStep
 The current step.
SwitchCommandmySwitchCommand
 The current switch command.

Detailed Description

An actuated (adaptive) traffic light logic.

Definition at line 57 of file MSActuatedTrafficLightLogic.h.

Member Typedef Documentation

Definition of a map from lanes to induct loops lying on them.

Definition at line 60 of file MSActuatedTrafficLightLogic.h.

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

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

Definition at line 77 of file MSTrafficLightLogic.h.

typedef std::vector<LaneVector> MSTrafficLightLogic::LaneVectorVector
inherited

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
inherited

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

Definition at line 71 of file MSTrafficLightLogic.h.

typedef std::vector<LinkVector> MSTrafficLightLogic::LinkVectorVector
inherited

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

Definition at line 74 of file MSTrafficLightLogic.h.

typedef std::map<std::string, std::string> MSTrafficLightLogic::ParameterMap
inherited

Definition at line 82 of file MSTrafficLightLogic.h.

typedef std::vector<MSPhaseDefinition*> MSTrafficLightLogic::Phases
inherited

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

Definition at line 68 of file MSTrafficLightLogic.h.

Constructor & Destructor Documentation

MSActuatedTrafficLightLogic::MSActuatedTrafficLightLogic ( MSTLLogicControl tlcontrol,
const std::string &  id,
const std::string &  programID,
const MSSimpleTrafficLightLogic::Phases phases,
unsigned int  step,
SUMOTime  delay,
const ParameterMap parameter 
)

Constructor.

Parameters
[in]tlcontrolThe tls control responsible for this tls
[in]idThis tls' id
[in]programIDThis tls' sub-id (program id)
[in]phasesDefinitions of the phases
[in]stepThe initial phase index
[in]delayThe time to wait before the first switch
[in]parameterThe parameter to use for tls set-up

Definition at line 56 of file MSActuatedTrafficLightLogic.cpp.

References TplConvert::_2SUMOReal(), myDetectorGap, myMaxGap, myPassingTime, and SUMOReal.

MSActuatedTrafficLightLogic::~MSActuatedTrafficLightLogic ( )

Destructor.

Definition at line 109 of file MSActuatedTrafficLightLogic.cpp.

References myInductLoops.

Member Function Documentation

void MSTrafficLightLogic::adaptLinkInformationFrom ( const MSTrafficLightLogic logic)
virtualinherited

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 151 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myLanes, and MSTrafficLightLogic::myLinks.

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

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

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 133 of file MSTrafficLightLogic.cpp.

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

void MSTrafficLightLogic::addOverridingDuration ( SUMOTime  duration)
inherited

Changes the duration of the next phase.

Parameters
[in]durationThe new duration

Definition at line 224 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myOverridingTimes.

void MSSimpleTrafficLightLogic::changeStepAndDuration ( MSTLLogicControl tlcontrol,
SUMOTime  simStep,
unsigned int  step,
SUMOTime  stepDuration 
)
virtualinherited
std::map< MSLink *, LinkState > MSTrafficLightLogic::collectLinkStates ( ) const
inherited

Returns the (uncontrolled) states of the controlled links.

Returns
The controlled link's states

Definition at line 158 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myLinks.

const MSPhaseDefinition & MSSimpleTrafficLightLogic::getCurrentPhaseDef ( ) const
virtualinherited
unsigned int MSSimpleTrafficLightLogic::getCurrentPhaseIndex ( ) const
virtualinherited

Returns the current index within the program.

Returns
The index of the current phase within the tls
See Also
MSTrafficLightLogic::getCurrentPhaseIndex

Implements MSTrafficLightLogic.

Definition at line 130 of file MSSimpleTrafficLightLogic.cpp.

References MSSimpleTrafficLightLogic::myStep.

SUMOTime MSTrafficLightLogic::getDefaultCycleTime ( ) const
inlineinherited

Returns the cycle time (in ms)

Returns
The (maybe changing) cycle time of this tls

Definition at line 268 of file MSTrafficLightLogic.h.

References MSTrafficLightLogic::myDefaultCycleTime.

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

unsigned int MSSimpleTrafficLightLogic::getIndexFromOffset ( SUMOTime  offset) const
virtualinherited

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
See Also
MSTrafficLightLogic::getIndexFromOffset

Implements MSTrafficLightLogic.

Definition at line 172 of file MSSimpleTrafficLightLogic.cpp.

References MSPhaseDefinition::duration, MSSimpleTrafficLightLogic::getPhase(), MSTrafficLightLogic::myDefaultCycleTime, and MSSimpleTrafficLightLogic::myPhases.

const LaneVectorVector& MSTrafficLightLogic::getLanes ( ) const
inlineinherited

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 191 of file MSTrafficLightLogic.h.

References MSTrafficLightLogic::myLanes.

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

const LaneVector& MSTrafficLightLogic::getLanesAt ( unsigned int  i) const
inlineinherited

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 200 of file MSTrafficLightLogic.h.

References MSTrafficLightLogic::myLanes.

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

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

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 200 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myLinks.

Referenced by GUITrafficLightLogicWrapper::getLinkIndex().

const LinkVectorVector& MSTrafficLightLogic::getLinks ( ) const
inlineinherited
const LinkVector& MSTrafficLightLogic::getLinksAt ( unsigned int  i) const
inlineinherited

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 217 of file MSTrafficLightLogic.h.

References MSTrafficLightLogic::myLinks.

SUMOTime MSTrafficLightLogic::getNextSwitchTime ( ) const
inherited

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 217 of file MSTrafficLightLogic.cpp.

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

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

SUMOTime MSSimpleTrafficLightLogic::getOffsetFromIndex ( unsigned int  index) const
virtualinherited

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
See Also
MSTrafficLightLogic::getOffsetFromIndex

Implements MSTrafficLightLogic.

Definition at line 158 of file MSSimpleTrafficLightLogic.cpp.

References MSPhaseDefinition::duration, MSSimpleTrafficLightLogic::getPhase(), and MSSimpleTrafficLightLogic::myPhases.

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

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 245 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myParameter.

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

const MSPhaseDefinition & MSSimpleTrafficLightLogic::getPhase ( unsigned int  givenstep) const
virtualinherited

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
See Also
MSTrafficLightLogic::getPhase

Implements MSTrafficLightLogic.

Definition at line 122 of file MSSimpleTrafficLightLogic.cpp.

References MSSimpleTrafficLightLogic::myPhases.

Referenced by MSSimpleTrafficLightLogic::getIndexFromOffset(), MSSimpleTrafficLightLogic::getOffsetFromIndex(), MSSimpleTrafficLightLogic::getPhaseIndexAtTime(), and GUIViewTraffic::onGamingClick().

SUMOTime MSSimpleTrafficLightLogic::getPhaseIndexAtTime ( SUMOTime  simStep) const
virtualinherited

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

Returns
The (estimated) index of the tls at the given simulation time step
See Also
MSTrafficLightLogic::getPhaseIndexAtTime

Implements MSTrafficLightLogic.

Definition at line 143 of file MSSimpleTrafficLightLogic.cpp.

References MSPhaseDefinition::duration, MSSimpleTrafficLightLogic::getPhase(), MSTrafficLightLogic::myDefaultCycleTime, MSPhaseDefinition::myLastSwitch, and MSSimpleTrafficLightLogic::myStep.

unsigned int MSSimpleTrafficLightLogic::getPhaseNumber ( ) const
virtualinherited

Returns the number of phases.

Returns
The number of this tls program's phases
See Also
MSTrafficLightLogic::getPhaseNumber

Implements MSTrafficLightLogic.

Definition at line 104 of file MSSimpleTrafficLightLogic.cpp.

References MSSimpleTrafficLightLogic::myPhases.

const MSSimpleTrafficLightLogic::Phases & MSSimpleTrafficLightLogic::getPhases ( ) const
virtualinherited

Returns the phases of this tls program.

Returns
The phases of this tls program
See Also
MSTrafficLightLogic::getPhases

Implements MSTrafficLightLogic.

Definition at line 110 of file MSSimpleTrafficLightLogic.cpp.

References MSSimpleTrafficLightLogic::myPhases.

MSSimpleTrafficLightLogic::Phases & MSSimpleTrafficLightLogic::getPhases ( )
inherited

Returns the phases of this tls program.

Returns
The phases of this tls program
Todo:
Recheck!

Definition at line 116 of file MSSimpleTrafficLightLogic.cpp.

References MSSimpleTrafficLightLogic::myPhases.

const std::string& MSTrafficLightLogic::getProgramID ( ) const
inlineinherited
void MSActuatedTrafficLightLogic::init ( NLDetectorBuilder nb)
virtual

Initialises the tls with information about incoming lanes.

Parameters
[in]nbThe detector builder
Exceptions
ProcessErrorIf something fails on initialisation

Reimplemented from MSTrafficLightLogic.

Definition at line 79 of file MSActuatedTrafficLightLogic.cpp.

References NLDetectorBuilder::createInductLoop(), Named::getID(), MSLane::getLength(), MSLane::getSpeedLimit(), myDetectorGap, MSTrafficLightLogic::myID, myInductLoops, MSTrafficLightLogic::myLanes, MSTrafficLightLogic::myProgramID, and SUMOReal.

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

Resets the states of controlled links.

Parameters
[in]valsThe state of controlled links to use

Definition at line 187 of file MSTrafficLightLogic.cpp.

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

void MSTrafficLightLogic::setCurrentDurationIncrement ( SUMOTime  delay)
inherited

Delays current phase by the given delay.

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

Definition at line 230 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myCurrentDurationIncrement.

void MSTrafficLightLogic::setParameter ( const ParameterMap params)
inherited

Inserts read parameter.

Parameters
[in]paramsThe parameter to use

Definition at line 239 of file MSTrafficLightLogic.cpp.

References MSTrafficLightLogic::myParameter.

void MSSimpleTrafficLightLogic::setPhases ( const Phases phases,
unsigned int  index 
)
inherited

Replaces the phases and set the phase index.

Definition at line 210 of file MSSimpleTrafficLightLogic.cpp.

References MSSimpleTrafficLightLogic::deletePhases(), MSSimpleTrafficLightLogic::myPhases, and MSSimpleTrafficLightLogic::myStep.

bool MSTrafficLightLogic::setTrafficLightSignals ( SUMOTime  t) const
inherited

Applies the current signal states to controlled links.

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

Definition at line 171 of file MSTrafficLightLogic.cpp.

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

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

SUMOTime MSActuatedTrafficLightLogic::trySwitch ( bool  isActive)
virtual

Switches to the next phase.

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

Reimplemented from MSSimpleTrafficLightLogic.

Definition at line 118 of file MSActuatedTrafficLightLogic.cpp.

References duration(), gapControl(), MSSimpleTrafficLightLogic::getCurrentPhaseDef(), MSNet::getCurrentTimeStep(), MSNet::getInstance(), MSPhaseDefinition::minDuration, myContinue, MSSimpleTrafficLightLogic::myPhases, and MSSimpleTrafficLightLogic::myStep.

Field Documentation

bool MSActuatedTrafficLightLogic::myContinue
protected

information whether the current phase should be lenghtend

Definition at line 124 of file MSActuatedTrafficLightLogic.h.

Referenced by duration(), gapControl(), and trySwitch().

SUMOTime MSTrafficLightLogic::myCurrentDurationIncrement
protectedinherited

A value for enlarge the current duration.

Definition at line 432 of file MSTrafficLightLogic.h.

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

SUMOReal MSActuatedTrafficLightLogic::myDetectorGap
protected

The detector distance.

Definition at line 133 of file MSActuatedTrafficLightLogic.h.

Referenced by init(), and MSActuatedTrafficLightLogic().

std::string MSTrafficLightLogic::myID
protectedinherited

The id of the logic.

Definition at line 420 of file MSTrafficLightLogic.h.

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

InductLoopMap MSActuatedTrafficLightLogic::myInductLoops
protected

A map from lanes to induct loops lying on them.

Definition at line 121 of file MSActuatedTrafficLightLogic.h.

Referenced by duration(), gapControl(), init(), and ~MSActuatedTrafficLightLogic().

LaneVectorVector MSTrafficLightLogic::myLanes
protectedinherited
SUMOReal MSActuatedTrafficLightLogic::myMaxGap
protected

The maximum gap to check.

Definition at line 127 of file MSActuatedTrafficLightLogic.h.

Referenced by gapControl(), and MSActuatedTrafficLightLogic().

std::vector<SUMOTime> MSTrafficLightLogic::myOverridingTimes
protectedinherited

A list of duration overrides.

Definition at line 429 of file MSTrafficLightLogic.h.

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

ParameterMap MSTrafficLightLogic::myParameter
protectedinherited
SUMOReal MSActuatedTrafficLightLogic::myPassingTime
protected

The passing time used.

Definition at line 130 of file MSActuatedTrafficLightLogic.h.

Referenced by duration(), and MSActuatedTrafficLightLogic().

std::string MSTrafficLightLogic::myProgramID
protectedinherited
SwitchCommand* MSTrafficLightLogic::mySwitchCommand
protectedinherited

The documentation for this class was generated from the following files: