SUMO - Simulation of Urban MObility
NBTrafficLightLogicCont Class Reference

A container for traffic light definitions and built programs. More...

#include <NBTrafficLightLogicCont.h>

Collaboration diagram for NBTrafficLightLogicCont:
Collaboration graph

Public Member Functions

void applyOptions (OptionsCont &oc)
 Initialises the storage by applying given options. More...
 
std::pair< int, int > computeLogics (OptionsCont &oc)
 Computes the traffic light logics using the stored definitions and stores the results. More...
 
bool computeSingleLogic (OptionsCont &oc, NBTrafficLightDefinition *def)
 Computes a specific traffic light logic (using by NETEDIT) More...
 
void extract (NBTrafficLightDefinition *definition)
 Extracts a traffic light definition from myDefinitions but keeps it in myExtracted for eventual * deletion (used by NETEDIT) More...
 
std::vector< NBTrafficLightLogic * > getComputed () const
 Returns a list of all computed logics. More...
 
NBTrafficLightDefinitiongetDefinition (const std::string &id, const std::string &programID) const
 Returns the named definition. More...
 
NBTrafficLightLogicgetLogic (const std::string &id, const std::string &programID) const
 Returns the computed logic for the given name. More...
 
int getNumExtracted () const
 return the number of extracted traffic light definitions More...
 
const std::map< std::string, NBTrafficLightDefinition * > & getPrograms (const std::string &id) const
 Returns all programs for the given tl-id. More...
 
bool insert (NBTrafficLightDefinition *logic, bool forceInsert=false)
 Adds a logic definition to the dictionary. More...
 
 NBTrafficLightLogicCont ()
 Constructor. More...
 
void remapRemoved (NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
 Replaces occurences of the removed edge in incoming/outgoing edges of all definitions. More...
 
bool removeFully (const std::string id)
 Removes a logic definition (and all programs) from the dictionary. More...
 
bool removeProgram (const std::string id, const std::string programID, bool del=true)
 Removes a program of a logic definition from the dictionary. More...
 
void replaceRemoved (NBEdge *removed, int removedLane, NBEdge *by, int byLane)
 Replaces occurences of the removed edge/lane in all definitions by the given edge. More...
 
void setTLControllingInformation (const NBEdgeCont &ec, const NBNodeCont &nc)
 Informs the edges about being controlled by a tls. More...
 
 ~NBTrafficLightLogicCont ()
 Destructor. More...
 

Private Types

typedef std::vector< NBTrafficLightDefinition * > Definitions
 
typedef std::map< std::string, Program2DefId2Defs
 
typedef std::map< std::string, Program2LogicId2Logics
 
typedef std::vector< NBTrafficLightLogic * > Logics
 
typedef std::map< std::string, NBTrafficLightDefinition * > Program2Def
 
typedef std::map< std::string, NBTrafficLightLogic * > Program2Logic
 Definition of internal the container types. More...
 

Private Member Functions

void clear ()
 Destroys all stored definitions and logics. More...
 
Definitions getDefinitions () const
 Returns a list of all definitions (convenience for easier iteration) More...
 

Private Attributes

Id2Logics myComputed
 The container for previously computed tl-logics. More...
 
Id2Defs myDefinitions
 The container for tl-ids to their definitions. More...
 
std::set< NBTrafficLightDefinition * > myExtracted
 The container for extracted definitions. More...
 
std::set< std::string > myHalfOffsetTLS
 List of tls which shall have an offset of T/2. More...
 
std::set< std::string > myQuarterOffsetTLS
 List of tls which shall have an offset of T/2. More...
 

Static Private Attributes

static const Program2Def EmptyDefinitions = NBTrafficLightLogicCont::Program2Def()
 

Detailed Description

A container for traffic light definitions and built programs.

This container class holds definitions of traffic light logics during the loading of the network. After all information has been loaded, these definitions are used to build the traffic light logics.

The built traffic light logics are kept stored within this container during their building and written to the network file at the end.

See also
NBTrafficLightDefinition
NBTrafficLightLogic

Definition at line 64 of file NBTrafficLightLogicCont.h.

Member Typedef Documentation

◆ Definitions

Definition at line 224 of file NBTrafficLightLogicCont.h.

◆ Id2Defs

typedef std::map<std::string, Program2Def> NBTrafficLightLogicCont::Id2Defs
private

Definition at line 222 of file NBTrafficLightLogicCont.h.

◆ Id2Logics

typedef std::map<std::string, Program2Logic> NBTrafficLightLogicCont::Id2Logics
private

Definition at line 220 of file NBTrafficLightLogicCont.h.

◆ Logics

Definition at line 223 of file NBTrafficLightLogicCont.h.

◆ Program2Def

typedef std::map<std::string, NBTrafficLightDefinition*> NBTrafficLightLogicCont::Program2Def
private

Definition at line 221 of file NBTrafficLightLogicCont.h.

◆ Program2Logic

typedef std::map<std::string, NBTrafficLightLogic*> NBTrafficLightLogicCont::Program2Logic
private

Definition of internal the container types.

Definition at line 219 of file NBTrafficLightLogicCont.h.

Constructor & Destructor Documentation

◆ NBTrafficLightLogicCont()

NBTrafficLightLogicCont::NBTrafficLightLogicCont ( )

Constructor.

Definition at line 54 of file NBTrafficLightLogicCont.cpp.

◆ ~NBTrafficLightLogicCont()

NBTrafficLightLogicCont::~NBTrafficLightLogicCont ( )

Destructor.

Definition at line 57 of file NBTrafficLightLogicCont.cpp.

References clear().

Member Function Documentation

◆ applyOptions()

void NBTrafficLightLogicCont::applyOptions ( OptionsCont oc)

Initialises the storage by applying given options.

Options, mainly setting offsets, are parsed and the according internal variables are set.

Parameters
[in]ocThe options container to read options from
Todo:
Recheck exceptions

Definition at line 63 of file NBTrafficLightLogicCont.cpp.

References OptionsCont::getStringVector(), OptionsCont::isSet(), and myHalfOffsetTLS.

Referenced by NBNetBuilder::applyOptions().

◆ clear()

void NBTrafficLightLogicCont::clear ( )
private

Destroys all stored definitions and logics.

Definition at line 198 of file NBTrafficLightLogicCont.cpp.

References getComputed(), getDefinitions(), myComputed, myDefinitions, and myExtracted.

Referenced by ~NBTrafficLightLogicCont().

◆ computeLogics()

std::pair< int, int > NBTrafficLightLogicCont::computeLogics ( OptionsCont oc)

Computes the traffic light logics using the stored definitions and stores the results.

Goes through all stored definitions and calls "NBTrafficLightDefinition::compute" for each. Stores the result using "insert".

Parameters
[in]ocOptions used during the computation
Returns
The number of computed tls and programs
See also
NBTrafficLightDefinition::compute

Definition at line 147 of file NBTrafficLightLogicCont.cpp.

References computeSingleLogic(), getComputed(), getDefinitions(), and myComputed.

Referenced by NBNetBuilder::compute(), and getNumExtracted().

◆ computeSingleLogic()

bool NBTrafficLightLogicCont::computeSingleLogic ( OptionsCont oc,
NBTrafficLightDefinition def 
)

Computes a specific traffic light logic (using by NETEDIT)

Parameters
[in]ocOptions used during the computation
Returns
whether the logic was computed successfully
See also
NBTrafficLightDefinition::compute

Definition at line 167 of file NBTrafficLightLogicCont.cpp.

References NBTrafficLightDefinition::compute(), NBTrafficLightLogic::getDuration(), Named::getID(), NBTrafficLightDefinition::getNodes(), NBTrafficLightDefinition::getProgramID(), myComputed, myHalfOffsetTLS, myQuarterOffsetTLS, NBTrafficLightLogic::setOffset(), and WRITE_WARNING.

Referenced by GNENet::computeJunction(), computeLogics(), and getNumExtracted().

◆ extract()

void NBTrafficLightLogicCont::extract ( NBTrafficLightDefinition definition)

Extracts a traffic light definition from myDefinitions but keeps it in myExtracted for eventual * deletion (used by NETEDIT)

Definition at line 140 of file NBTrafficLightLogicCont.cpp.

References Named::getID(), NBTrafficLightDefinition::getProgramID(), myExtracted, and removeProgram().

Referenced by NBNodeCont::discardTrafficLights(), and GNEJunction::removeTrafficLight().

◆ getComputed()

NBTrafficLightLogicCont::Logics NBTrafficLightLogicCont::getComputed ( ) const

Returns a list of all computed logics.

Definition at line 302 of file NBTrafficLightLogicCont.cpp.

References myComputed.

Referenced by clear(), computeLogics(), getNumExtracted(), and NWWriter_SUMO::writeTrafficLights().

◆ getDefinition()

NBTrafficLightDefinition * NBTrafficLightLogicCont::getDefinition ( const std::string &  id,
const std::string &  programID 
) const

Returns the named definition.

Parameters
[in]idThe id of the definition to return
[in]programIDThe id of the program to return
Returns
The named definition, 0 if it is not known

Definition at line 237 of file NBTrafficLightLogicCont.cpp.

References myDefinitions.

Referenced by getNumExtracted(), and NIXMLTrafficLightsHandler::initTrafficLightLogic().

◆ getDefinitions()

NBTrafficLightLogicCont::Definitions NBTrafficLightLogicCont::getDefinitions ( ) const
private

Returns a list of all definitions (convenience for easier iteration)

Definition at line 315 of file NBTrafficLightLogicCont.cpp.

References myDefinitions.

Referenced by clear(), computeLogics(), remapRemoved(), replaceRemoved(), and setTLControllingInformation().

◆ getLogic()

NBTrafficLightLogic * NBTrafficLightLogicCont::getLogic ( const std::string &  id,
const std::string &  programID 
) const

Returns the computed logic for the given name.

Parameters
[in]idThe id of the logic to return
[in]programIDThe id of the program to return
Returns
The named definition, 0 if it is not known

Definition at line 261 of file NBTrafficLightLogicCont.cpp.

References myComputed.

Referenced by getNumExtracted(), and GNETLSEditorFrame::onCmdDefSwitch().

◆ getNumExtracted()

int NBTrafficLightLogicCont::getNumExtracted ( ) const
inline

return the number of extracted traffic light definitions

Definition at line 126 of file NBTrafficLightLogicCont.h.

References computeLogics(), computeSingleLogic(), getComputed(), getDefinition(), getLogic(), getPrograms(), myExtracted, remapRemoved(), replaceRemoved(), and setTLControllingInformation().

Referenced by NILoader::load().

◆ getPrograms()

const NBTrafficLightLogicCont::Program2Def & NBTrafficLightLogicCont::getPrograms ( const std::string &  id) const

Returns all programs for the given tl-id.

Parameters
[in]idThe tl-id for which to return all programs
Returns
The map of programIDs to definitions

Definition at line 250 of file NBTrafficLightLogicCont.cpp.

References EmptyDefinitions, and myDefinitions.

Referenced by NIImporter_SUMO::_loadNetwork(), NIXMLTrafficLightsHandler::addTlConnection(), getNumExtracted(), NIXMLTrafficLightsHandler::initTrafficLightLogic(), NIXMLNodesHandler::processTrafficLightDefinitions(), NIXMLTrafficLightsHandler::removeTlConnection(), and GNEJunction::setAttribute().

◆ insert()

bool NBTrafficLightLogicCont::insert ( NBTrafficLightDefinition logic,
bool  forceInsert = false 
)

Adds a logic definition to the dictionary.

"true" is returned if the logic is accepted - no logic with the same name and programID exists within this container.

Parameters
[in]logicThe logic to add
[in]forceInsertIf true, rename the program to make insertion succeed
Returns
Whether the logic was valid (no logic with the same id and programID is already known)

Definition at line 80 of file NBTrafficLightLogicCont.cpp.

References IDSupplier::avoid(), Named::getID(), IDSupplier::getNext(), NBTrafficLightDefinition::getProgramID(), myDefinitions, myExtracted, and NBTrafficLightDefinition::setProgramID().

Referenced by GNEJunction::addTrafficLight(), NIVisumTL::build(), NGNode::buildNBNode(), NIVissimTL::dict_SetSignals(), NBNodeCont::guessTLs(), NIXMLTrafficLightsHandler::initTrafficLightLogic(), NIImporter_OpenStreetMap::insertNodeChecking(), NBNode::invalidateTLS(), NBNodeCont::joinNodeClusters(), NBNodeCont::joinTLS(), NIImporter_OpenDrive::loadNetwork(), NIImporter_SUMO::myEndElement(), NIXMLNodesHandler::processTrafficLightDefinitions(), NIImporter_DlrNavteq::TrafficlightsHandler::report(), and NBNodeCont::setAsTLControlled().

◆ remapRemoved()

void NBTrafficLightLogicCont::remapRemoved ( NBEdge removed,
const EdgeVector incoming,
const EdgeVector outgoing 
)

Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.

Parameters
[in]removedThe removed edge
[in]incomingThe edges to use instead if an incoming edge was removed
[in]outgoingThe edges to use instead if an outgoing edge was removed
Todo:
Recheck usage

Definition at line 217 of file NBTrafficLightLogicCont.cpp.

References getDefinitions().

Referenced by getNumExtracted(), and NBNode::remapRemoved().

◆ removeFully()

bool NBTrafficLightLogicCont::removeFully ( const std::string  id)

Removes a logic definition (and all programs) from the dictionary.

"true" is returned if the logic existed in the dictionary, otherwise "false".

Parameters
[in]idThe id of the logic to remove
Returns
Whether the named logic was within the dictionary

Definition at line 104 of file NBTrafficLightLogicCont.cpp.

References myComputed, and myDefinitions.

Referenced by NBNodeCont::guessTLs(), NBNode::invalidateTLS(), NBNodeCont::joinTLS(), and NIXMLNodesHandler::processNodeType().

◆ removeProgram()

bool NBTrafficLightLogicCont::removeProgram ( const std::string  id,
const std::string  programID,
bool  del = true 
)

Removes a program of a logic definition from the dictionary.

"true" is returned if the program existed in the dictionary, otherwise "false".

Parameters
[in]idThe id of the logic
[in]programIDThe id of the program to remove
[in]delWhether the definition shall be deleted
Returns
Whether the program was within the dictionary

Definition at line 126 of file NBTrafficLightLogicCont.cpp.

References myDefinitions.

Referenced by extract(), and NIXMLTrafficLightsHandler::initTrafficLightLogic().

◆ replaceRemoved()

void NBTrafficLightLogicCont::replaceRemoved ( NBEdge removed,
int  removedLane,
NBEdge by,
int  byLane 
)

Replaces occurences of the removed edge/lane in all definitions by the given edge.

Parameters
[in]removedThe removed edge
[in]removedThe removed lane
[in]byThe edge to use instead
[in]byLaneThe lane to use instead
Todo:
Recheck usage

Definition at line 227 of file NBTrafficLightLogicCont.cpp.

References getDefinitions().

Referenced by getNumExtracted(), NBEdgeCont::joinSameNodeConnectingEdges(), GNENet::GNEChange_ReplaceEdgeInTLS::redo(), NBNodeCont::removeUnwishedNodes(), and GNENet::GNEChange_ReplaceEdgeInTLS::undo().

◆ setTLControllingInformation()

void NBTrafficLightLogicCont::setTLControllingInformation ( const NBEdgeCont ec,
const NBNodeCont nc 
)

Informs the edges about being controlled by a tls.

Goes through all definition, calling eachs "setParticipantsInformation" method. Goes through all definition, calling eachs "setTLControllingInformation" method.

Parameters
[in]ecThe ede control to set information into
See also
NBTrafficLightDefinition::setParticipantsInformation
NBTrafficLightDefinition::setTLControllingInformation

Definition at line 275 of file NBTrafficLightLogicCont.cpp.

References NBNodeCont::begin(), NBEdgeCont::clearControllingTLInformation(), NBNodeCont::end(), getDefinitions(), Named::getID(), NBNode::getType(), NODETYPE_RAIL_CROSSING, NODETYPE_RAIL_SIGNAL, NBNode::removeTrafficLight(), NBNode::setCrossingTLIndices(), NBTrafficLightDefinition::setParticipantsInformation(), and TLTYPE_STATIC.

Referenced by NBNetBuilder::compute(), and getNumExtracted().

Field Documentation

◆ EmptyDefinitions

const NBTrafficLightLogicCont::Program2Def NBTrafficLightLogicCont::EmptyDefinitions = NBTrafficLightLogicCont::Program2Def()
staticprivate

Definition at line 241 of file NBTrafficLightLogicCont.h.

Referenced by getPrograms().

◆ myComputed

Id2Logics NBTrafficLightLogicCont::myComputed
private

The container for previously computed tl-logics.

Definition at line 227 of file NBTrafficLightLogicCont.h.

Referenced by clear(), computeLogics(), computeSingleLogic(), getComputed(), getLogic(), and removeFully().

◆ myDefinitions

Id2Defs NBTrafficLightLogicCont::myDefinitions
private

The container for tl-ids to their definitions.

Definition at line 230 of file NBTrafficLightLogicCont.h.

Referenced by clear(), getDefinition(), getDefinitions(), getPrograms(), insert(), removeFully(), and removeProgram().

◆ myExtracted

std::set<NBTrafficLightDefinition*> NBTrafficLightLogicCont::myExtracted
private

The container for extracted definitions.

Definition at line 233 of file NBTrafficLightLogicCont.h.

Referenced by clear(), extract(), getNumExtracted(), and insert().

◆ myHalfOffsetTLS

std::set<std::string> NBTrafficLightLogicCont::myHalfOffsetTLS
private

List of tls which shall have an offset of T/2.

Definition at line 236 of file NBTrafficLightLogicCont.h.

Referenced by applyOptions(), and computeSingleLogic().

◆ myQuarterOffsetTLS

std::set<std::string> NBTrafficLightLogicCont::myQuarterOffsetTLS
private

List of tls which shall have an offset of T/2.

Definition at line 239 of file NBTrafficLightLogicCont.h.

Referenced by computeSingleLogic().


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