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

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

#include <NBTrafficLightLogicCont.h>

Public Member Functions

void applyOptions (OptionsCont &oc)
 Initialises the storage by applying given options. More...
 
std::pair< unsigned int,
unsigned int
computeLogics (NBEdgeCont &ec, OptionsCont &oc)
 Computes the traffic light logics using the stored definitions and stores the results. More...
 
bool computeSingleLogic (NBEdgeCont &ec, 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...
 
size_t 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)
 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,
Program2Def
Id2Defs
 
typedef std::map< std::string,
Program2Logic
Id2Logics
 
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 65 of file NBTrafficLightLogicCont.h.

Member Typedef Documentation

Definition at line 227 of file NBTrafficLightLogicCont.h.

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

Definition at line 225 of file NBTrafficLightLogicCont.h.

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

Definition at line 223 of file NBTrafficLightLogicCont.h.

Definition at line 226 of file NBTrafficLightLogicCont.h.

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

Definition at line 224 of file NBTrafficLightLogicCont.h.

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

Definition of internal the container types.

Definition at line 222 of file NBTrafficLightLogicCont.h.

Constructor & Destructor Documentation

NBTrafficLightLogicCont::NBTrafficLightLogicCont ( )

Constructor.

Definition at line 57 of file NBTrafficLightLogicCont.cpp.

NBTrafficLightLogicCont::~NBTrafficLightLogicCont ( )

Destructor.

Definition at line 60 of file NBTrafficLightLogicCont.cpp.

References clear().

Member Function Documentation

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 66 of file NBTrafficLightLogicCont.cpp.

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

Referenced by NBNetBuilder::applyOptions().

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().

std::pair< unsigned int, unsigned int > NBTrafficLightLogicCont::computeLogics ( NBEdgeCont ec,
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]ecThe edge container used during the computation
[in]ocOptions used during the computation
Returns
The number of computed tls and programs
See Also
NBTrafficLightDefinition::compute

Definition at line 150 of file NBTrafficLightLogicCont.cpp.

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

Referenced by NBNetBuilder::compute().

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

Computes a specific traffic light logic (using by NETEDIT)

Parameters
[in]ecThe edge container used during the computation
[in]ocOptions used during the computation
Returns
whether the logic was computed successfully
See Also
NBTrafficLightDefinition::compute

Definition at line 170 of file NBTrafficLightLogicCont.cpp.

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

Referenced by computeLogics().

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 143 of file NBTrafficLightLogicCont.cpp.

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

Referenced by NBNodeCont::discardTrafficLights().

NBTrafficLightLogicCont::Logics NBTrafficLightLogicCont::getComputed ( ) const

Returns a list of all computed logics.

Definition at line 291 of file NBTrafficLightLogicCont.cpp.

References myComputed.

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

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 NIXMLTrafficLightsHandler::initTrafficLightLogic(), and NBNode::invalidateTLS().

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

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

Definition at line 304 of file NBTrafficLightLogicCont.cpp.

References myDefinitions.

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

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.

size_t NBTrafficLightLogicCont::getNumExtracted ( ) const
inline

return the number of extracted traffic light definitions

Definition at line 127 of file NBTrafficLightLogicCont.h.

References myExtracted.

Referenced by NILoader::load().

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(), NIXMLNodesHandler::processTrafficLightDefinitions(), and NIXMLTrafficLightsHandler::removeTlConnection().

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]renameProgramIf 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 83 of file NBTrafficLightLogicCont.cpp.

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

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

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 NBNode::remapRemoved().

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 107 of file NBTrafficLightLogicCont.cpp.

References myComputed, and myDefinitions.

Referenced by NIXMLNodesHandler::addNode(), and NBNodeCont::joinTLS().

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 129 of file NBTrafficLightLogicCont.cpp.

References myDefinitions.

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

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 NBEdgeCont::joinSameNodeConnectingEdges(), and NBNodeCont::removeUnwishedNodes().

void NBTrafficLightLogicCont::setTLControllingInformation ( const NBEdgeCont ec)

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 NBEdgeCont::clearControllingTLInformation(), and getDefinitions().

Referenced by NBNetBuilder::compute().

Field Documentation

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

Definition at line 244 of file NBTrafficLightLogicCont.h.

Referenced by getPrograms().

Id2Logics NBTrafficLightLogicCont::myComputed
private

The container for previously computed tl-logics.

Definition at line 230 of file NBTrafficLightLogicCont.h.

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

Id2Defs NBTrafficLightLogicCont::myDefinitions
private

The container for tl-ids to their definitions.

Definition at line 233 of file NBTrafficLightLogicCont.h.

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

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

The container for extracted definitions.

Definition at line 236 of file NBTrafficLightLogicCont.h.

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

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

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

Definition at line 239 of file NBTrafficLightLogicCont.h.

Referenced by applyOptions(), and computeSingleLogic().

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

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

Definition at line 242 of file NBTrafficLightLogicCont.h.

Referenced by computeSingleLogic().


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