SUMO - Simulation of Urban MObility
NIVisumTL.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2003-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Intermediate class for storing visum traffic lights during their import
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
34 #include <netbuild/NBLoadedTLDef.h>
36 #include <netbuild/NBEdgeCont.h>
37 #include "NIVisumTL.h"
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
43 NIVisumTL::NIVisumTL(const std::string& name, SUMOTime cycleTime, SUMOTime offset,
44  SUMOTime intermediateTime, bool phaseDefined)
45  : myName(name), myCycleTime(cycleTime), myOffset(offset),
46  myIntermediateTime(intermediateTime), myPhaseDefined(phaseDefined) {
47 }
48 
49 
51  for (std::map<std::string, Phase*>::iterator i = myPhases.begin(); i != myPhases.end(); ++i) {
52  delete i->second;
53  }
54  for (std::map<std::string, SignalGroup*>::iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); ++i) {
55  delete i->second;
56  }
57 }
58 
59 
60 void
61 NIVisumTL::addSignalGroup(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
62  mySignalGroups[name] = new NIVisumTL::SignalGroup(name, startTime, endTime, yellowTime);
63 }
64 
65 
66 void
67 NIVisumTL::addPhase(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
68  myPhases[name] = new NIVisumTL::Phase(startTime, endTime, yellowTime);
69 }
70 
71 
73 NIVisumTL::getSignalGroup(const std::string& name) {
74  return *mySignalGroups.find(name)->second;
75 }
76 
77 
78 void
80  for (std::vector<NBNode*>::iterator ni = myNodes.begin(); ni != myNodes.end(); ni++) {
81  NBNode* node = (*ni);
83  NBLoadedTLDef* def = new NBLoadedTLDef(ec, node->getID(), node, myOffset, type);
84  tlc.insert(def);
85  def->setCycleDuration((int) myCycleTime);
86  // signalgroups
87  for (std::map<std::string, SignalGroup*>::iterator gi = mySignalGroups.begin(); gi != mySignalGroups.end(); gi++) {
88  std::string groupName = (*gi).first;
89  NIVisumTL::SignalGroup& SG = *(*gi).second;
90  def->addSignalGroup(groupName);
91  def->addToSignalGroup(groupName, SG.connections());
92  // phases
93  SUMOTime yellowTime = -1;
94  if (myPhaseDefined) {
95  for (std::map<std::string, Phase*>::iterator pi = SG.phases().begin(); pi != SG.phases().end(); pi++) {
96  NIVisumTL::Phase& PH = *(*pi).second;
99  yellowTime = MAX2(PH.getYellowTime(), yellowTime);
100  };
101  } else {
104  yellowTime = MAX2(SG.getYellowTime(), yellowTime);
105  }
106  // yellowTime can be -1 if not given in the input; it will be "patched" later
107  def->setSignalYellowTimes(groupName, myIntermediateTime, yellowTime);
108  }
109  }
110 }
111 
112 
113 
114 /****************************************************************************/
115 
std::map< std::string, Phase * > & phases()
Returns the phases map.
Definition: NIVisumTL.h:123
bool myPhaseDefined
Toogles the usage either of phases or of time periods in signal groups.
Definition: NIVisumTL.h:188
void setSignalYellowTimes(const std::string &groupid, SUMOTime tRedYellow, SUMOTime tYellow)
Sets the times the light is yellow or red/yellow.
A signal group can be defined either by a time period or by phases.
Definition: NIVisumTL.h:108
SUMOTime getYellowTime()
Returns the stored yellow time.
Definition: NIVisumTL.h:75
void addSignalGroupPhaseBegin(const std::string &groupid, SUMOTime time, TLColor color)
Sets the information about the begin of a phase.
A container for traffic light definitions and built programs.
A loaded (complete) traffic light logic.
Definition: NBLoadedTLDef.h:48
SignalGroup & getSignalGroup(const std::string &name)
Returns the named signal group.
Definition: NIVisumTL.cpp:73
T MAX2(T a, T b)
Definition: StdDefs.h:73
SUMOTime myCycleTime
The cycle time of traffic light in seconds.
Definition: NIVisumTL.h:179
const std::string & getID() const
Returns the id.
Definition: Named.h:65
void addPhase(const std::string &name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
Adds a phase.
Definition: NIVisumTL.cpp:67
void addSignalGroup(const std::string &name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
Adds a signal group.
Definition: NIVisumTL.cpp:61
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
A phase.
Definition: NIVisumTL.h:93
SUMOTime getEndTime()
Returns the stored end time.
Definition: NIVisumTL.h:70
~NIVisumTL()
Destructor.
Definition: NIVisumTL.cpp:50
SUMOTime getStartTime()
Returns the stored start time.
Definition: NIVisumTL.h:65
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
SUMOTime myOffset
The offset in the plan.
Definition: NIVisumTL.h:182
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
void build(NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
build the traffic light and add it to the given container
Definition: NIVisumTL.cpp:79
NIVisumTL(const std::string &name, SUMOTime cycleTime, SUMOTime offset, SUMOTime intermediateTime, bool phaseDefined)
Constructor.
Definition: NIVisumTL.cpp:43
T get(const std::string &str) const
void setCycleDuration(int cycleDur)
Sets the duration of a cycle.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
std::map< std::string, SignalGroup * > mySignalGroups
Map of used signal groups.
Definition: NIVisumTL.h:197
void addSignalGroup(const std::string &id)
Adds a signal group.
NBConnectionVector & connections()
Returns the connections vector.
Definition: NIVisumTL.h:118
SUMOTime myIntermediateTime
The all-red time (unused here)
Definition: NIVisumTL.h:185
Represents a single node (junction) during network building.
Definition: NBNode.h:74
std::map< std::string, Phase * > myPhases
Map of used phases if phases defined.
Definition: NIVisumTL.h:194
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
std::vector< NBNode * > myNodes
Vector of nodes belonging to this traffic light.
Definition: NIVisumTL.h:191
long long int SUMOTime
Definition: TraCIDefs.h:51
TrafficLightType