NBTrafficLightLogicCont Class Reference

#include <NBTrafficLightLogicCont.h>


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 62 of file NBTrafficLightLogicCont.h.


Public Member Functions

void applyOptions (OptionsCont &oc) throw ()
 Initialises the storage by applying given options.
void clear () throw ()
 Destroys all stored definitions and logics.
void computeLogics (NBEdgeCont &ec, OptionsCont &oc) throw ()
 Computes the traffic light logics using the stored definitions and stores the results.
NBTrafficLightDefinitiongetDefinition (const std::string &id) const throw ()
 Returns the named definition.
bool insert (NBTrafficLightDefinition *logic) throw ()
 Adds a logic definition to the dictionary.
 NBTrafficLightLogicCont () throw ()
 Constructor.
void remapRemoved (NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing) throw ()
 Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
bool remove (const std::string &id) throw ()
 Removes a logic definition from the dictionary.
void replaceRemoved (NBEdge *removed, int removedLane, NBEdge *by, int byLane) throw ()
 Replaces occurences of the removed edge/lane in all definitions by the given edge.
void setTLControllingInformation (const NBEdgeCont &ec) throw ()
 Informs the edges about being controlled by a tls.
void writeXML (OutputDevice &into) throw (IOError)
 Saves all known logics into the given stream.
 ~NBTrafficLightLogicCont () throw ()
 Destructor.

Private Types

typedef std::map< std::string,
NBTrafficLightLogic * > 
ComputedContType
 Definition of the container type for tl-ids to previously computed logics.
typedef std::map< std::string,
NBTrafficLightDefinition * > 
DefinitionContType
 Definition of the container type for tl-ids to their definitions.

Private Attributes

ComputedContType myComputed
 The container for previously computed tl-logics.
DefinitionContType myDefinitions
 The container for tl-ids to their definitions.
std::vector< std::string > myHalfOffsetTLS
 List of tls which shall have an offset of T/2.
std::vector< std::string > myQuarterOffsetTLS
 List of tls which shall have an offset of T/2.

Member Typedef Documentation

typedef std::map<std::string, NBTrafficLightLogic*> NBTrafficLightLogicCont::ComputedContType [private]

Definition of the container type for tl-ids to previously computed logics.

Definition at line 178 of file NBTrafficLightLogicCont.h.

typedef std::map<std::string, NBTrafficLightDefinition*> NBTrafficLightLogicCont::DefinitionContType [private]

Definition of the container type for tl-ids to their definitions.

Definition at line 184 of file NBTrafficLightLogicCont.h.


Constructor & Destructor Documentation

NBTrafficLightLogicCont::NBTrafficLightLogicCont (  )  throw ()

Constructor.

Definition at line 47 of file NBTrafficLightLogicCont.cpp.

00047 {}

NBTrafficLightLogicCont::~NBTrafficLightLogicCont (  )  throw ()

Destructor.

Definition at line 50 of file NBTrafficLightLogicCont.cpp.

References clear().

00050                                                           {
00051     clear();
00052 }


Member Function Documentation

void NBTrafficLightLogicCont::applyOptions ( OptionsCont oc  )  throw ()

Initialises the storage by applying given options.

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

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

Definition at line 56 of file NBTrafficLightLogicCont.cpp.

References myHalfOffsetTLS, and myQuarterOffsetTLS.

Referenced by NBNetBuilder::applyOptions().

00056                                                              {
00057     // check whether any offsets shall be manipulated by setting
00058     //  them to half of the duration
00059     if (oc.isSet("tl-logics.half-offset")) {
00060         myHalfOffsetTLS = oc.getStringVector("tl-logics.half-offset");
00061     }
00062     // check whether any offsets shall be manipulated by setting
00063     //  them to a quarter of the duration
00064     if (oc.isSet("tl-logics.quarter-offset")) {
00065         myQuarterOffsetTLS = oc.getStringVector("tl-logics.quarter-offset");
00066     }
00067 }

void NBTrafficLightLogicCont::clear (  )  throw ()

Destroys all stored definitions and logics.

Definition at line 135 of file NBTrafficLightLogicCont.cpp.

References myComputed, and myDefinitions.

Referenced by ~NBTrafficLightLogicCont().

00135                                        {
00136     for (ComputedContType::iterator i=myComputed.begin(); i!=myComputed.end(); ++i) {
00137         delete(*i).second;
00138     }
00139     myComputed.clear();
00140     for (DefinitionContType::iterator i=myDefinitions.begin(); i!=myDefinitions.end(); ++i) {
00141         delete(*i).second;
00142     }
00143     myDefinitions.clear();
00144 }

void NBTrafficLightLogicCont::computeLogics ( NBEdgeCont ec,
OptionsCont oc 
) throw ()

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] ec The edge container used during the computation
[in] oc Options used during the computation
See also:
NBTrafficLightDefinition::compute

Definition at line 94 of file NBTrafficLightLogicCont.cpp.

References NBTrafficLightDefinition::compute(), NBTrafficLightLogic::getDuration(), myComputed, myDefinitions, myHalfOffsetTLS, myQuarterOffsetTLS, NBTrafficLightLogic::setOffset(), WRITE_MESSAGE, and WRITE_WARNING.

Referenced by NBNetBuilder::compute().

00094                                                                               {
00095     unsigned int no = 0;
00096     for (DefinitionContType::iterator i=myDefinitions.begin(); i!=myDefinitions.end(); i++) {
00097         std::string id = (*i).first;
00098         if (myComputed.find(id)!=myComputed.end()) {
00099             WRITE_WARNING("Traffic light '" + id + "' was already built.");
00100             continue;
00101         }
00102         // build program
00103         NBTrafficLightDefinition *def = (*i).second;
00104         NBTrafficLightLogic *built = def->compute(ec, oc);
00105         if (built==0) {
00106             WRITE_WARNING("Could not build traffic lights '" + id + "'");
00107             continue;
00108         }
00109         // compute offset
00110         SUMOTime T = built->getDuration();
00111         if (find(myHalfOffsetTLS.begin(), myHalfOffsetTLS.end(), id)!=myHalfOffsetTLS.end()) {
00112             built->setOffset((SUMOTime)(T/2.));
00113         }
00114         if (find(myQuarterOffsetTLS.begin(), myQuarterOffsetTLS.end(), id)!=myQuarterOffsetTLS.end()) {
00115             built->setOffset((SUMOTime)(T/4.));
00116         }
00117         // and insert the result after computation
00118         myComputed[(*i).first] = built;
00119         no++;
00120     }
00121     WRITE_MESSAGE(toString<int>(no) + " traffic light(s) computed.");
00122 }

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

Returns the named definition.

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

Definition at line 166 of file NBTrafficLightLogicCont.cpp.

References myDefinitions.

Referenced by NIXMLNodesHandler::processTrafficLightDefinitions().

00166                                                                         {
00167     DefinitionContType::const_iterator i=myDefinitions.find(id);
00168     if (i!=myDefinitions.end()) {
00169         return (*i).second;
00170     }
00171     return 0;
00172 }

bool NBTrafficLightLogicCont::insert ( NBTrafficLightDefinition logic  )  throw ()

Adds a logic definition to the dictionary.

"true" is returned if the logic is accepted - no logic with the same name exists within this container. If another logic with the same name exists, false is returned.

Parameters:
[in] logic The logic to add
Returns:
Whether the logic was valid (no logic with the same id is already known)

Definition at line 71 of file NBTrafficLightLogicCont.cpp.

References myDefinitions.

Referenced by NIVisumTL::build(), NIVissimTL::dict_SetSignals(), NBNodeCont::guessTLs(), NBNodeCont::joinTLS(), NIXMLNodesHandler::processTrafficLightDefinitions(), NIImporter_DlrNavteq::TrafficlightsHandler::report(), and NBNodeCont::setAsTLControlled().

00071                                                                        {
00072     DefinitionContType::iterator i=myDefinitions.find(logic->getID());
00073     if (i!=myDefinitions.end()) {
00074         return false;
00075     }
00076     myDefinitions[logic->getID()] = logic;
00077     return true;
00078 }

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

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

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

Definition at line 148 of file NBTrafficLightLogicCont.cpp.

References myDefinitions.

Referenced by NBNode::remapRemoved().

00149                                                                           {
00150     for (DefinitionContType::iterator i=myDefinitions.begin(); i!=myDefinitions.end(); i++) {
00151         (*i).second->remapRemoved(removed, incoming, outgoing);
00152     }
00153 }

bool NBTrafficLightLogicCont::remove ( const std::string &  id  )  throw ()

Removes a logic definition from the dictionary.

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

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

Definition at line 82 of file NBTrafficLightLogicCont.cpp.

References myDefinitions.

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

00082                                                            {
00083     DefinitionContType::iterator i=myDefinitions.find(id);
00084     if (i==myDefinitions.end()) {
00085         return false;
00086     }
00087     delete(*i).second;
00088     myDefinitions.erase(i);
00089     return true;
00090 }

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

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

Parameters:
[in] removed The removed edge
[in] removed The removed lane
[in] by The edge to use instead
[in] byLane The lane to use instead
Todo:
Recheck usage

Definition at line 157 of file NBTrafficLightLogicCont.cpp.

References myDefinitions.

00158                                                                         {
00159     for (DefinitionContType::iterator i=myDefinitions.begin(); i!=myDefinitions.end(); i++) {
00160         (*i).second->replaceRemoved(removed, removedLane, by, byLane);
00161     }
00162 }

void NBTrafficLightLogicCont::setTLControllingInformation ( const NBEdgeCont ec  )  throw ()

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] ec The ede control to set information into
See also:
NBTrafficLightDefinition::setParticipantsInformation

NBTrafficLightDefinition::setTLControllingInformation

Definition at line 176 of file NBTrafficLightLogicCont.cpp.

References myDefinitions.

Referenced by NBNetBuilder::compute().

00176                                                                                  {
00177     DefinitionContType::iterator i;
00178     // set the information about all participants, first
00179     for (i=myDefinitions.begin(); i!=myDefinitions.end(); i++) {
00180         (*i).second->setParticipantsInformation();
00181     }
00182     // insert the information about the tl-controlling
00183     for (i=myDefinitions.begin(); i!=myDefinitions.end(); i++) {
00184         (*i).second->setTLControllingInformation(ec);
00185     }
00186 }

void NBTrafficLightLogicCont::writeXML ( OutputDevice into  )  throw (IOError)

Saves all known logics into the given stream.

Calls "writeXML" for each of the stored NBTrafficLightLogics.

Parameters:
[in] into The stream to write the logics into
Exceptions:
IOError (not yet implemented)
See also:
NBTrafficLightLogic::writeXML

Definition at line 126 of file NBTrafficLightLogicCont.cpp.

References myComputed.

Referenced by NBNetBuilder::save().

00126                                                                    {
00127     for (ComputedContType::iterator i=myComputed.begin(); i!=myComputed.end(); i++) {
00128         (*i).second->writeXML(into);
00129     }
00130     into << "\n";
00131 }


Field Documentation

The container for previously computed tl-logics.

Definition at line 181 of file NBTrafficLightLogicCont.h.

Referenced by clear(), computeLogics(), and writeXML().

The container for tl-ids to their definitions.

Definition at line 187 of file NBTrafficLightLogicCont.h.

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

std::vector<std::string> NBTrafficLightLogicCont::myHalfOffsetTLS [private]

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

Definition at line 190 of file NBTrafficLightLogicCont.h.

Referenced by applyOptions(), and computeLogics().

std::vector<std::string> NBTrafficLightLogicCont::myQuarterOffsetTLS [private]

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

Definition at line 193 of file NBTrafficLightLogicCont.h.

Referenced by applyOptions(), and computeLogics().


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

Generated on Wed May 5 00:06:52 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6