Eclipse SUMO - Simulation of Urban MObility
|
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. | |
void | check2Switch (SUMOTime step) |
Checks whether any WAUT is trying to switch a tls into another program. | |
void | clearState (SUMOTime time, bool quickReload=false) |
Clear all tls states before quick-loading state. | |
bool | closeNetworkReading () |
Lets MSTLLogicControl know that the network has been loaded. | |
TLSLogicVariants & | get (const std::string &id) const |
Returns the variants of a named tls. | |
MSTrafficLightLogic * | get (const std::string &id, const std::string &programID) const |
Returns a single program (variant) defined by the tls id and the program programID. | |
MSTrafficLightLogic * | getActive (const std::string &id) const |
Returns the active program of a named tls. | |
std::vector< MSTrafficLightLogic * > | getAllLogics () const |
Returns a vector which contains all logics. | |
std::vector< std::string > | getAllTLIds () const |
std::pair< SUMOTime, MSPhaseDefinition > | getPhaseDef (const std::string &tlid) const |
return the complete phase definition for a named traffic lights logic | |
SUMOTime | initWautSwitch (SwitchInitCommand &cmd) |
Initialises switching a WAUT. | |
bool | isActive (const MSTrafficLightLogic *tl) const |
Returns whether the given tls program is the currently active for his tls. | |
bool | knows (const std::string &id) const |
Returns the information whether the named tls is stored. | |
MSTLLogicControl () | |
Constructor. | |
void | saveState (OutputDevice &out) |
Saves the current tls states into the given stream. | |
void | setTrafficLightSignals (SUMOTime t) const |
Lets all running (current) tls programs apply their current signal states to links they control. | |
void | switchOffAll () |
switch all logic variants to 'off' | |
void | switchTo (const std::string &id, const std::string &programID) |
Switches the named (id) tls to the named (programID) program. | |
~MSTLLogicControl () | |
Destructor. | |
WAUT definition methods | |
void | addWAUT (SUMOTime refTime, const std::string &id, const std::string &startProg, SUMOTime period) |
Adds a WAUT definition. | |
void | addWAUTSwitch (const std::string &wautid, SUMOTime when, const std::string &to) |
Adds a WAUT switch step to a previously built WAUT. | |
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. | |
void | closeWAUT (const std::string &wautid) |
Closes loading of a WAUT. | |
Protected Attributes | |
std::vector< WAUTSwitchProcess > | myCurrentlySwitched |
A list of currently running switching procedures. | |
std::map< std::string, TLSLogicVariants * > | myLogics |
A map from ids to the corresponding variants. | |
bool | myNetWasLoaded |
Information whether the net was completely loaded. | |
std::map< std::string, WAUT * > | myWAUTs |
A map of ids to corresponding WAUTs. | |
Private Member Functions | |
MSTLLogicControl (const MSTLLogicControl &) | |
Invalidated copy constructor. | |
MSTLLogicControl & | operator= (const MSTLLogicControl &) |
Invalidated assignment operator. | |
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.
MSTLLogicControl::MSTLLogicControl | ( | ) |
Constructor.
Definition at line 520 of file MSTLLogicControl.cpp.
MSTLLogicControl::~MSTLLogicControl | ( | ) |
|
private |
Invalidated copy constructor.
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.
[in] | id | The id of the tls (program) to add |
[in] | programID | The program id of the tls (program) to add |
[in] | logic | The tls logic to insert |
ProcessError | In the case an additional tls program is loaded and no one for the tls existed in the network |
Definition at line 586 of file MSTLLogicControl.cpp.
References MSTLLogicControl::TLSLogicVariants::addLogic(), myLogics, and myNetWasLoaded.
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.
[in] | refTime | The reference time of the WAUT |
[in] | id | The ID of the WAUT |
[in] | startProg | The begin program of the WAUT |
[in] | period | The period with which to repeat the switches |
InvalidArgument | If the id is already used by another WAUT |
Definition at line 650 of file MSTLLogicControl.cpp.
References MSTLLogicControl::WAUT::id, myWAUTs, MSTLLogicControl::WAUT::period, MSTLLogicControl::WAUT::refTime, and MSTLLogicControl::WAUT::startProg.
Referenced by NLHandler::openWAUT().
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.
[in] | wautid | The ID of the WAUT |
[in] | tls | The id of the tls to be switched |
[in] | proc | The switching procedure to use |
[in] | synchron | Whether the switching shall be done in synchron mode |
InvalidArgument | If the named WAUT or the named tls are not known |
ProcessError | If the initial switch fails |
Definition at line 687 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().
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.
[in] | wautid | The ID of the WAUT |
[in] | when | The switch procedure begin |
[in] | to | The program the WAUT shall start to switch to at the given time |
InvalidArgument | If the named WAUT is not known |
Definition at line 667 of file MSTLLogicControl.cpp.
References myWAUTs, MSTLLogicControl::WAUT::period, MSTLLogicControl::WAUT::refTime, MSTLLogicControl::WAUTSwitch::to, and MSTLLogicControl::WAUTSwitch::when.
Referenced by NLHandler::addWAUTSwitch().
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 802 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().
void MSTLLogicControl::clearState | ( | SUMOTime | time, |
bool | quickReload = false |
||
) |
Clear all tls states before quick-loading state.
Definition at line 845 of file MSTLLogicControl.cpp.
References MSRailSignalConstraint::clearState(), myLogics, OFF, RAIL_CROSSING, and RAIL_SIGNAL.
Referenced by MSNet::clearState().
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).
Definition at line 606 of file MSTLLogicControl.cpp.
References myLogics, and myNetWasLoaded.
Referenced by NLJunctionControlBuilder::buildTLLogics().
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.
[in] | wautid | The ID of the WAUT |
InvalidArgument | If the named WAUT is not known |
Definition at line 725 of file MSTLLogicControl.cpp.
References MSEventControl::addEvent(), MSNet::getBeginOfTimestepEvents(), MSNet::getCurrentTimeStep(), MSNet::getInstance(), myWAUTs, MSTLLogicControl::WAUT::startProg, and MSTLLogicControl::WAUT::switches.
Referenced by NLHandler::closeWAUT().
MSTLLogicControl::TLSLogicVariants & MSTLLogicControl::get | ( | const std::string & | id | ) | const |
Returns the variants of a named tls.
[in] | id | The id of the tls to get variants of |
InvalidArgument |
Definition at line 556 of file MSTLLogicControl.cpp.
References myLogics.
Referenced by NLHandler::addPredecessorConstraint(), NLDiscreteEventBuilder::buildSaveTLSProgramCommand(), NLDiscreteEventBuilder::buildSaveTLStateCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchesCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchStatesCommand(), MSActuatedTrafficLightLogic::changeStepAndDuration(), MSSimpleTrafficLightLogic::changeStepAndDuration(), NLJunctionControlBuilder::closeTrafficLightLogic(), GUITrafficLightLogicWrapper::getPopUpMenu(), NLJunctionControlBuilder::getTLLogic(), libsumo::Helper::getTLS(), NLHandler::initTrafficLightLogic(), MSActuatedTrafficLightLogic::loadState(), MSStateHandler::myStartElement(), NLHandler::myStartElement(), TraCIServerAPI_TrafficLight::processGet(), GUITrafficLightLogicWrapper::switchTLSLogic(), and MSFullExport::writeTLS().
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.
[in] | id | The id of the tls to get program of |
[in] | programID | The program id of the tls program to get |
Definition at line 566 of file MSTLLogicControl.cpp.
References MSTLLogicControl::TLSLogicVariants::getLogic(), and myLogics.
MSTrafficLightLogic * MSTLLogicControl::getActive | ( | const std::string & | id | ) | const |
Returns the active program of a named tls.
[in] | id | The id of the tls to get the active program of |
Definition at line 628 of file MSTLLogicControl.cpp.
References myLogics.
Referenced by NLHandler::addDeadlock(), check2Switch(), GUIJunctionWrapper::drawGL(), GUITrafficLightLogicWrapper::getActiveTLLogic(), GUINet::getLinkTLID(), GUINet::getLinkTLIndex(), and getPhaseDef().
std::vector< MSTrafficLightLogic * > MSTLLogicControl::getAllLogics | ( | ) | const |
Returns a vector which contains all logics.
All logics are included, active (current) and non-active
Definition at line 545 of file MSTLLogicControl.cpp.
References myLogics.
Referenced by NLBuilder::build(), GUINet::initGUIStructures(), GUINet::initTLMap(), GUIViewTraffic::onGamingClick(), and MSNet::writeRailSignalBlocks().
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)
Definition at line 576 of file MSTLLogicControl.cpp.
References myLogics.
Referenced by NLDiscreteEventBuilder::buildSaveTLSProgramCommand(), NLDiscreteEventBuilder::buildSaveTLStateCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchesCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchStatesCommand(), and MSFullExport::writeTLS().
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.
[in] | tlid | The id of the tls to get the current phases of |
Definition at line 820 of file MSTLLogicControl.cpp.
References getActive(), MSTrafficLightLogic::getCurrentPhaseDef(), and MSNet::getInstance().
Referenced by GUITrafficLightLogicWrapper::begin2TrackPhases().
SUMOTime MSTLLogicControl::initWautSwitch | ( | MSTLLogicControl::SwitchInitCommand & | cmd | ) |
Initialises switching a WAUT.
This method is called from a previously built SwitchInitCommand
[in] | The | command which initialises the switch |
Definition at line 759 of file MSTLLogicControl.cpp.
References MSTLLogicControl::WAUTSwitchProcess::from, MSTLLogicControl::TLSLogicVariants::getActive(), MSNet::getCurrentTimeStep(), MSTLLogicControl::SwitchInitCommand::getIndex(), MSNet::getInstance(), MSTLLogicControl::TLSLogicVariants::getLogicInstantiatingOff(), MSTLLogicControl::SwitchInitCommand::getWAUTID(), MSTLLogicControl::WAUTSwitchProcess::junction, myCurrentlySwitched, myLogics, myWAUTs, MSTLLogicControl::WAUT::period, MSTLLogicControl::WAUTSwitchProcess::proc, MSTLLogicControl::WAUT::switches, MSTLLogicControl::WAUTSwitch::to, and MSTLLogicControl::WAUTSwitchProcess::to.
Referenced by MSTLLogicControl::SwitchInitCommand::execute().
bool MSTLLogicControl::isActive | ( | const MSTrafficLightLogic * | tl | ) | const |
Returns whether the given tls program is the currently active for his tls.
[in] | tl | The tls to ask for |
Definition at line 618 of file MSTLLogicControl.cpp.
References Named::getID(), and myLogics.
Referenced by GUIViewTraffic::onGamingClick().
bool MSTLLogicControl::knows | ( | const std::string & | id | ) | const |
Returns the information whether the named tls is stored.
[in] | id | The id of the tls to ask for |
Definition at line 600 of file MSTLLogicControl.cpp.
References myLogics.
Referenced by NLHandler::addPredecessorConstraint(), NLDiscreteEventBuilder::buildSaveTLSProgramCommand(), NLDiscreteEventBuilder::buildSaveTLStateCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchesCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchStatesCommand(), MSStateHandler::myStartElement(), and NLHandler::myStartElement().
|
private |
Invalidated assignment operator.
void MSTLLogicControl::saveState | ( | OutputDevice & | out | ) |
Saves the current tls states into the given stream.
Definition at line 835 of file MSTLLogicControl.cpp.
References myLogics, MSDriveWay::saveState(), and MSRailSignalConstraint::saveState().
Referenced by MSStateHandler::saveState().
void MSTLLogicControl::setTrafficLightSignals | ( | SUMOTime | t | ) | const |
Lets all running (current) tls programs apply their current signal states to links they control.
[in] | t | The current time |
Definition at line 537 of file MSTLLogicControl.cpp.
References myLogics.
void MSTLLogicControl::switchOffAll | ( | ) |
switch all logic variants to 'off'
Definition at line 827 of file MSTLLogicControl.cpp.
References myLogics.
Referenced by NLBuilder::build().
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.
[in] | id | The id of the tls to switch to |
[in] | programID | The program id of the tls (program) to switch to |
ProcessError | If either the tls or the program to switch to is not known |
Definition at line 638 of file MSTLLogicControl.cpp.
References myLogics.
Referenced by addWAUTJunction(), check2Switch(), MSTLLogicControl::TLSLogicVariants::setStateInstantiatingOnline(), and GUITrafficLightLogicWrapper::switchTLSLogic().
|
protected |
A list of currently running switching procedures.
Definition at line 748 of file MSTLLogicControl.h.
Referenced by check2Switch(), and initWautSwitch().
|
protected |
A map from ids to the corresponding variants.
Definition at line 751 of file MSTLLogicControl.h.
Referenced by add(), addWAUTJunction(), clearState(), closeNetworkReading(), get(), get(), getActive(), getAllLogics(), getAllTLIds(), initWautSwitch(), isActive(), knows(), saveState(), setTrafficLightSignals(), switchOffAll(), switchTo(), and ~MSTLLogicControl().
|
protected |
Information whether the net was completely loaded.
Definition at line 754 of file MSTLLogicControl.h.
Referenced by add(), and closeNetworkReading().
|
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().