Eclipse SUMO - Simulation of Urban MObility
MSTLLogicControl Class Reference

A class that stores and controls tls and switching of their programs. More...

#include <MSTLLogicControl.h>

Data Structures

class  OnSwitchAction
 Base class for things to execute if a tls switches to a new phase. More...
 
class  SwitchInitCommand
 This event-class is used to initialise a WAUT switch at a certain time. More...
 
class  TLSLogicVariants
 Storage for all programs of a single tls. More...
 
struct  WAUT
 A WAUT definition. More...
 
struct  WAUTJunction
 Storage for a junction assigned to a WAUT. More...
 
struct  WAUTSwitch
 Storage for a WAUTs switch point. More...
 
class  WAUTSwitchProcedure
 This is the abstract base class for switching from one tls program to another. More...
 
class  WAUTSwitchProcedure_GSP
 This class switches using the GSP algorithm. More...
 
class  WAUTSwitchProcedure_JustSwitch
 This class simply switches to the next program. More...
 
class  WAUTSwitchProcedure_Stretch
 This class switches using the Stretch algorithm. More...
 
struct  WAUTSwitchProcess
 An initialised switch process. More...
 

Public Member Functions

bool add (const std::string &id, const std::string &programID, MSTrafficLightLogic *logic, bool newDefault=true)
 Adds a tls program to the container. More...
 
void check2Switch (SUMOTime step)
 Checks whether any WAUT is trying to switch a tls into another program. More...
 
void clearState (SUMOTime time, bool quickReload=false)
 Clear all tls states before quick-loading state. More...
 
bool closeNetworkReading ()
 Lets MSTLLogicControl know that the network has been loaded. More...
 
TLSLogicVariantsget (const std::string &id) const
 Returns the variants of a named tls. More...
 
MSTrafficLightLogicget (const std::string &id, const std::string &programID) const
 Returns a single program (variant) defined by the tls id and the program programID. More...
 
MSTrafficLightLogicgetActive (const std::string &id) const
 Returns the active program of a named tls. More...
 
std::vector< MSTrafficLightLogic * > getAllLogics () const
 Returns a vector which contains all logics. More...
 
std::vector< std::string > getAllTLIds () const
 
std::pair< SUMOTime, MSPhaseDefinitiongetPhaseDef (const std::string &tlid) const
 return the complete phase definition for a named traffic lights logic More...
 
SUMOTime initWautSwitch (SwitchInitCommand &cmd)
 Initialises switching a WAUT. More...
 
bool isActive (const MSTrafficLightLogic *tl) const
 Returns whether the given tls program is the currently active for his tls. More...
 
bool knows (const std::string &id) const
 Returns the information whether the named tls is stored. More...
 
 MSTLLogicControl ()
 Constructor. More...
 
void saveState (OutputDevice &out)
 Saves the current tls states into the given stream. More...
 
void setTrafficLightSignals (SUMOTime t) const
 Lets all running (current) tls programs apply their current signal states to links they control. More...
 
void switchOffAll ()
 switch all logic variants to 'off' More...
 
void switchTo (const std::string &id, const std::string &programID)
 Switches the named (id) tls to the named (programID) program. More...
 
 ~MSTLLogicControl ()
 Destructor. More...
 
WAUT definition methods
void addWAUT (SUMOTime refTime, const std::string &id, const std::string &startProg, SUMOTime period)
 Adds a WAUT definition. More...
 
void addWAUTSwitch (const std::string &wautid, SUMOTime when, const std::string &to)
 Adds a WAUT switch step to a previously built WAUT. More...
 
void addWAUTJunction (const std::string &wautid, const std::string &tls, const std::string &proc, bool synchron)
 Adds a tls to the list of tls to be switched by the named WAUT. More...
 
void closeWAUT (const std::string &wautid)
 Closes loading of a WAUT. More...
 

Protected Attributes

std::vector< WAUTSwitchProcessmyCurrentlySwitched
 A list of currently running switching procedures. More...
 
std::map< std::string, TLSLogicVariants * > myLogics
 A map from ids to the corresponding variants. More...
 
bool myNetWasLoaded
 Information whether the net was completely loaded. More...
 
std::map< std::string, WAUT * > myWAUTs
 A map of ids to corresponding WAUTs. More...
 

Private Member Functions

 MSTLLogicControl (const MSTLLogicControl &)
 Invalidated copy constructor. More...
 
MSTLLogicControloperator= (const MSTLLogicControl &)
 Invalidated assignment operator. More...
 

Detailed Description

A class that stores and controls tls and switching of their programs.

This class holds all traffic light logics (programs) and their variants during the simulation. In addition, the schedule for switching between different tls programs are also stored.

When a WAUT is forced to switch, for each TLS, a switching procedure derived from WAUTSwitchProcedure is initialised and is asked repeatedly whether a switch could be done until it returns true.

Definition at line 59 of file MSTLLogicControl.h.

Constructor & Destructor Documentation

◆ MSTLLogicControl() [1/2]

MSTLLogicControl::MSTLLogicControl ( )

Constructor.

Definition at line 519 of file MSTLLogicControl.cpp.

◆ ~MSTLLogicControl()

MSTLLogicControl::~MSTLLogicControl ( )

Destructor.

Definition at line 523 of file MSTLLogicControl.cpp.

References myLogics, and myWAUTs.

◆ MSTLLogicControl() [2/2]

MSTLLogicControl::MSTLLogicControl ( const MSTLLogicControl )
private

Invalidated copy constructor.

Member Function Documentation

◆ add()

bool MSTLLogicControl::add ( const std::string &  id,
const std::string &  programID,
MSTrafficLightLogic logic,
bool  newDefault = true 
)

Adds a tls program to the container.

If a tls with the given id is not yet known, a TLSLogicVariants structure is built for this tls and added to the internal container and the tls program is used as the new default.

If the tls to add is loaded from an additional file (indicated by myNetWasLoaded, see closeNetworkReading), links from previously loaded tls are adapted to the logic. This may throw a ProcessError in the case no tls program was loaded for this tls before (was not defined in the network). In case of an error the logic gets deleted.

The parameter newDefault defines whether this program will be used as the new default program of this tls. This means that an existing tls program for this tls is replaced within the according TLSLogicVariants structure.

Parameters
[in]idThe id of the tls (program) to add
[in]programIDThe program id of the tls (program) to add
[in]logicThe tls logic to insert
Exceptions
ProcessErrorIn the case an additional tls program is loaded and no one for the tls existed in the network
Returns
true if the tls program could be added, false otherwise

Definition at line 585 of file MSTLLogicControl.cpp.

References MSTLLogicControl::TLSLogicVariants::addLogic(), myLogics, and myNetWasLoaded.

◆ addWAUT()

void MSTLLogicControl::addWAUT ( SUMOTime  refTime,
const std::string &  id,
const std::string &  startProg,
SUMOTime  period 
)

Adds a WAUT definition.

Throws an InvalidArgument if the given id is already in use.

Parameters
[in]refTimeThe reference time of the WAUT
[in]idThe ID of the WAUT
[in]startProgThe begin program of the WAUT
[in]periodThe period with which to repeat the switches
Exceptions
InvalidArgumentIf the id is already used by another WAUT

Definition at line 649 of file MSTLLogicControl.cpp.

References MSTLLogicControl::WAUT::id, myWAUTs, MSTLLogicControl::WAUT::period, MSTLLogicControl::WAUT::refTime, and MSTLLogicControl::WAUT::startProg.

Referenced by NLHandler::openWAUT().

Here is the caller graph for this function:

◆ addWAUTJunction()

void MSTLLogicControl::addWAUTJunction ( const std::string &  wautid,
const std::string &  tls,
const std::string &  proc,
bool  synchron 
)

Adds a tls to the list of tls to be switched by the named WAUT.

Passes the values directly to the used tls control. This throws an InvalidArgument if the given WAUT id or the given junction id is not known.

Parameters
[in]wautidThe ID of the WAUT
[in]tlsThe id of the tls to be switched
[in]procThe switching procedure to use
[in]synchronWhether the switching shall be done in synchron mode
Exceptions
InvalidArgumentIf the named WAUT or the named tls are not known
ProcessErrorIf the initial switch fails

Definition at line 686 of file MSTLLogicControl.cpp.

References MSNet::getCurrentTimeStep(), MSNet::getInstance(), MSTLLogicControl::WAUTJunction::junction, myLogics, myWAUTs, MSTLLogicControl::WAUTJunction::procedure, switchTo(), and MSTLLogicControl::WAUTJunction::synchron.

Referenced by NLHandler::addWAUTJunction().

Here is the caller graph for this function:

◆ addWAUTSwitch()

void MSTLLogicControl::addWAUTSwitch ( const std::string &  wautid,
SUMOTime  when,
const std::string &  to 
)

Adds a WAUT switch step to a previously built WAUT.

Throws an InvalidArgument if the given WAUT id is not known.

Parameters
[in]wautidThe ID of the WAUT
[in]whenThe switch procedure begin
[in]toThe program the WAUT shall start to switch to at the given time
Exceptions
InvalidArgumentIf the named WAUT is not known

Definition at line 666 of file MSTLLogicControl.cpp.

References myWAUTs, MSTLLogicControl::WAUT::period, MSTLLogicControl::WAUT::refTime, MSTLLogicControl::WAUTSwitch::to, and MSTLLogicControl::WAUTSwitch::when.

Referenced by NLHandler::addWAUTSwitch().

Here is the caller graph for this function:

◆ check2Switch()

void MSTLLogicControl::check2Switch ( SUMOTime  step)

Checks whether any WAUT is trying to switch a tls into another program.

Called from MSNet::simulationStep

Definition at line 801 of file MSTLLogicControl.cpp.

References getActive(), Named::getID(), MSTrafficLightLogic::getProgramID(), myCurrentlySwitched, MSTLLogicControl::WAUTSwitchProcess::proc, switchTo(), MSTLLogicControl::WAUTSwitchProcess::to, TRACI_PROGRAM, and MSTLLogicControl::WAUTSwitchProcedure::trySwitch().

Referenced by MSNet::simulationStep().

Here is the caller graph for this function:

◆ clearState()

void MSTLLogicControl::clearState ( SUMOTime  time,
bool  quickReload = false 
)

Clear all tls states before quick-loading state.

Definition at line 843 of file MSTLLogicControl.cpp.

References MSRailSignalConstraint::clearState(), myLogics, OFF, RAIL_CROSSING, and RAIL_SIGNAL.

Referenced by MSNet::clearState().

Here is the caller graph for this function:

◆ closeNetworkReading()

bool MSTLLogicControl::closeNetworkReading ( )

Lets MSTLLogicControl know that the network has been loaded.

This method must be called after the network (including the initial tls definitions) was loaded.

The originally loaded traffic lights are also verified herein by calling TLSLogicVariants::checkOriginalTLS, first.

The MSTLLogicControl is informed in order to know that link information is known for the tls programs loaded afterwards so that it may be adapted from the previously loaded tls (a net may only contain one program per tls).

The states of the links controlled by tls are saved for their potential later usage (if the tls is switched to off-mode).

Returns
Whether the traffic lights could be initialised and are correct

Definition at line 605 of file MSTLLogicControl.cpp.

References myLogics, and myNetWasLoaded.

Referenced by NLJunctionControlBuilder::buildTLLogics().

Here is the caller graph for this function:

◆ closeWAUT()

void MSTLLogicControl::closeWAUT ( const std::string &  wautid)

Closes loading of a WAUT.

Instantiates the first switch ("SwitchInitCommand") for the WAUT into the network's simulation time step begin event control. Throws an InvalidArgument if the given WAUT id is not known.

Parameters
[in]wautidThe ID of the WAUT
Exceptions
InvalidArgumentIf the named WAUT is not known
See also
SwitchInitCommand

Definition at line 724 of file MSTLLogicControl.cpp.

References MSEventControl::addEvent(), MSNet::getBeginOfTimestepEvents(), MSNet::getCurrentTimeStep(), MSNet::getInstance(), myWAUTs, and MSTLLogicControl::WAUT::switches.

Referenced by NLHandler::closeWAUT().

Here is the caller graph for this function:

◆ get() [1/2]

◆ get() [2/2]

MSTrafficLightLogic * MSTLLogicControl::get ( const std::string &  id,
const std::string &  programID 
) const

Returns a single program (variant) defined by the tls id and the program programID.

Parameters
[in]idThe id of the tls to get program of
[in]programIDThe program id of the tls program to get
Returns
The defined tls program if existing, 0 otherwise

Definition at line 565 of file MSTLLogicControl.cpp.

References myLogics.

◆ getActive()

MSTrafficLightLogic * MSTLLogicControl::getActive ( const std::string &  id) const

Returns the active program of a named tls.

Parameters
[in]idThe id of the tls to get the active program of
Returns
The current program of the defined tls if existing, 0 otherwise

Definition at line 627 of file MSTLLogicControl.cpp.

References myLogics.

Referenced by check2Switch(), GUIJunctionWrapper::drawGL(), GUITrafficLightLogicWrapper::getActiveTLLogic(), GUINet::getLinkTLID(), GUINet::getLinkTLIndex(), and getPhaseDef().

Here is the caller graph for this function:

◆ getAllLogics()

std::vector< MSTrafficLightLogic * > MSTLLogicControl::getAllLogics ( ) const

Returns a vector which contains all logics.

All logics are included, active (current) and non-active

Returns
A vector containing all loaded logics

Definition at line 544 of file MSTLLogicControl.cpp.

References myLogics.

Referenced by NLBuilder::build(), GUIViewTraffic::onGamingClick(), and MSNet::writeRailSignalBlocks().

Here is the caller graph for this function:

◆ getAllTLIds()

std::vector< std::string > MSTLLogicControl::getAllTLIds ( ) const

Returns the ids of all existing variants-structures, wich are the ids of their contained tls logics (not the logic's programm-ids)

Returns
the list of ids

Definition at line 575 of file MSTLLogicControl.cpp.

References myLogics.

Referenced by NLDiscreteEventBuilder::buildSaveTLSProgramCommand(), NLDiscreteEventBuilder::buildSaveTLStateCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchesCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchStatesCommand(), and MSFullExport::writeTLS().

Here is the caller graph for this function:

◆ getPhaseDef()

std::pair< SUMOTime, MSPhaseDefinition > MSTLLogicControl::getPhaseDef ( const std::string &  tlid) const

return the complete phase definition for a named traffic lights logic

The phase definition will be the current of the currently active program of the named tls.

Parameters
[in]tlidThe id of the tls to get the current phases of
Returns
A pair containing the current time and the current phases of the named tls

Definition at line 819 of file MSTLLogicControl.cpp.

References getActive(), MSTrafficLightLogic::getCurrentPhaseDef(), and MSNet::getInstance().

Referenced by GUITrafficLightLogicWrapper::begin2TrackPhases().

Here is the caller graph for this function:

◆ initWautSwitch()

◆ isActive()

bool MSTLLogicControl::isActive ( const MSTrafficLightLogic tl) const

Returns whether the given tls program is the currently active for his tls.

Parameters
[in]tlThe tls to ask for
Returns
Whether the given tl is currently active (or a different program is used)

Definition at line 617 of file MSTLLogicControl.cpp.

References Named::getID(), and myLogics.

Referenced by GUIViewTraffic::onGamingClick().

Here is the caller graph for this function:

◆ knows()

bool MSTLLogicControl::knows ( const std::string &  id) const

Returns the information whether the named tls is stored.

Parameters
[in]idThe id of the tls to ask for
Returns
Whether a tls with the given id is known

Definition at line 599 of file MSTLLogicControl.cpp.

References myLogics.

Referenced by NLHandler::addPredecessorConstraint(), NLDiscreteEventBuilder::buildSaveTLSProgramCommand(), NLDiscreteEventBuilder::buildSaveTLStateCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchesCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchStatesCommand(), MSStateHandler::myStartElement(), and NLHandler::myStartElement().

Here is the caller graph for this function:

◆ operator=()

MSTLLogicControl& MSTLLogicControl::operator= ( const MSTLLogicControl )
private

Invalidated assignment operator.

◆ saveState()

void MSTLLogicControl::saveState ( OutputDevice out)

Saves the current tls states into the given stream.

Definition at line 834 of file MSTLLogicControl.cpp.

References myLogics, and MSRailSignalConstraint::saveState().

Referenced by MSStateHandler::saveState().

Here is the caller graph for this function:

◆ setTrafficLightSignals()

void MSTLLogicControl::setTrafficLightSignals ( SUMOTime  t) const

Lets all running (current) tls programs apply their current signal states to links they control.

Parameters
[in]tThe current time
See also
MSTrafficLightLogic::setTrafficLightSignals
LinkState
MSLink::setTLState

Definition at line 536 of file MSTLLogicControl.cpp.

References myLogics.

◆ switchOffAll()

void MSTLLogicControl::switchOffAll ( )

switch all logic variants to 'off'

Definition at line 826 of file MSTLLogicControl.cpp.

References myLogics.

Referenced by NLBuilder::build().

Here is the caller graph for this function:

◆ switchTo()

void MSTLLogicControl::switchTo ( const std::string &  id,
const std::string &  programID 
)

Switches the named (id) tls to the named (programID) program.

The program with the used programID must be previously added. If the tls itself or the program to switch to is not known, false is returned.

Parameters
[in]idThe id of the tls to switch to
[in]programIDThe program id of the tls (program) to switch to
Exceptions
ProcessErrorIf either the tls or the program to switch to is not known

Definition at line 637 of file MSTLLogicControl.cpp.

References myLogics.

Referenced by addWAUTJunction(), check2Switch(), MSTLLogicControl::TLSLogicVariants::setStateInstantiatingOnline(), and GUITrafficLightLogicWrapper::switchTLSLogic().

Here is the caller graph for this function:

Field Documentation

◆ myCurrentlySwitched

std::vector<WAUTSwitchProcess> MSTLLogicControl::myCurrentlySwitched
protected

A list of currently running switching procedures.

Definition at line 748 of file MSTLLogicControl.h.

Referenced by check2Switch(), and initWautSwitch().

◆ myLogics

std::map<std::string, TLSLogicVariants*> MSTLLogicControl::myLogics
protected

◆ myNetWasLoaded

bool MSTLLogicControl::myNetWasLoaded
protected

Information whether the net was completely loaded.

Definition at line 754 of file MSTLLogicControl.h.

Referenced by add(), and closeNetworkReading().

◆ myWAUTs

std::map<std::string, WAUT*> MSTLLogicControl::myWAUTs
protected

A map of ids to corresponding WAUTs.

Definition at line 745 of file MSTLLogicControl.h.

Referenced by addWAUT(), addWAUTJunction(), addWAUTSwitch(), closeWAUT(), initWautSwitch(), and ~MSTLLogicControl().


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