Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Intermediate class for storing visum traffic lights during their import
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
29 #include <netbuild/NBLoadedTLDef.h>
31 #include <netbuild/NBEdgeCont.h>
32 #include "NIVisumTL.h"
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 NIVisumTL::NIVisumTL(const std::string& name, SUMOTime cycleTime, SUMOTime offset,
39  SUMOTime intermediateTime, bool phaseDefined)
40  : myName(name), myCycleTime(cycleTime), myOffset(offset),
41  myIntermediateTime(intermediateTime), myPhaseDefined(phaseDefined) {
42 }
43 
44 
46  for (std::map<std::string, Phase*>::iterator i = myPhases.begin(); i != myPhases.end(); ++i) {
47  delete i->second;
48  }
49  for (std::map<std::string, SignalGroup*>::iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); ++i) {
50  delete i->second;
51  }
52 }
53 
54 
55 void
56 NIVisumTL::addSignalGroup(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
57  mySignalGroups[name] = new NIVisumTL::SignalGroup(name, startTime, endTime, yellowTime);
58 }
59 
60 
61 void
62 NIVisumTL::addPhase(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
63  myPhases[name] = new NIVisumTL::Phase(startTime, endTime, yellowTime);
64 }
65 
66 
68 NIVisumTL::getSignalGroup(const std::string& name) {
69  return *mySignalGroups.find(name)->second;
70 }
71 
72 
73 void
75  for (std::vector<NBNode*>::iterator ni = myNodes.begin(); ni != myNodes.end(); ni++) {
76  NBNode* node = (*ni);
77  if (node == nullptr) {
78  WRITE_WARNING("invalid node for traffic light '" + myName + "'");
79  continue;
80  }
82  NBLoadedTLDef* def = new NBLoadedTLDef(ec, node->getID(), node, myOffset, type);
83  tlc.insert(def);
84  def->setCycleDuration((int) myCycleTime);
85  // signalgroups
86  for (std::map<std::string, SignalGroup*>::iterator gi = mySignalGroups.begin(); gi != mySignalGroups.end(); gi++) {
87  std::string groupName = (*gi).first;
88  NIVisumTL::SignalGroup& SG = *(*gi).second;
89  def->addSignalGroup(groupName);
90  def->addToSignalGroup(groupName, SG.connections());
91  // phases
92  SUMOTime yellowTime = -1;
93  if (myPhaseDefined) {
94  for (std::map<std::string, Phase*>::iterator pi = SG.phases().begin(); pi != SG.phases().end(); pi++) {
95  NIVisumTL::Phase& PH = *(*pi).second;
98  yellowTime = MAX2(PH.getYellowTime(), yellowTime);
99  };
100  } else {
103  yellowTime = MAX2(SG.getYellowTime(), yellowTime);
104  }
105  // yellowTime can be -1 if not given in the input; it will be "patched" later
106  def->setSignalYellowTimes(groupName, myIntermediateTime, yellowTime);
107  }
108  }
109 }
110 
111 
112 
113 /****************************************************************************/
114 
std::map< std::string, Phase * > & phases()
Returns the phases map.
Definition: NIVisumTL.h:117
bool myPhaseDefined
Toogles the usage either of phases or of time periods in signal groups.
Definition: NIVisumTL.h:182
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:102
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOTime getYellowTime()
Returns the stored yellow time.
Definition: NIVisumTL.h:69
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:42
SignalGroup & getSignalGroup(const std::string &name)
Returns the named signal group.
Definition: NIVisumTL.cpp:68
T MAX2(T a, T b)
Definition: StdDefs.h:80
SUMOTime myCycleTime
The cycle time of traffic light in seconds.
Definition: NIVisumTL.h:173
const std::string & getID() const
Returns the id.
Definition: Named.h:77
void addPhase(const std::string &name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
Adds a phase.
Definition: NIVisumTL.cpp:62
void addSignalGroup(const std::string &name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
Adds a signal group.
Definition: NIVisumTL.cpp:56
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
A phase.
Definition: NIVisumTL.h:87
SUMOTime getEndTime()
Returns the stored end time.
Definition: NIVisumTL.h:64
~NIVisumTL()
Destructor.
Definition: NIVisumTL.cpp:45
SUMOTime getStartTime()
Returns the stored start time.
Definition: NIVisumTL.h:59
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:176
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:74
NIVisumTL(const std::string &name, SUMOTime cycleTime, SUMOTime offset, SUMOTime intermediateTime, bool phaseDefined)
Constructor.
Definition: NIVisumTL.cpp:38
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:61
std::map< std::string, SignalGroup * > mySignalGroups
Map of used signal groups.
Definition: NIVisumTL.h:191
std::string myName
The name of traffic light.
Definition: NIVisumTL.h:170
void addSignalGroup(const std::string &id)
Adds a signal group.
NBConnectionVector & connections()
Returns the connections vector.
Definition: NIVisumTL.h:112
SUMOTime myIntermediateTime
The all-red time (unused here)
Definition: NIVisumTL.h:179
Represents a single node (junction) during network building.
Definition: NBNode.h:68
std::map< std::string, Phase * > myPhases
Map of used phases if phases defined.
Definition: NIVisumTL.h:188
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:185
TrafficLightType