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 /****************************************************************************/
16 // Intermediate class for storing visum traffic lights during their import
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
28 #include <netbuild/NBLoadedTLDef.h>
30 #include <netbuild/NBEdgeCont.h>
31 #include "NIVisumTL.h"
32 
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
37 NIVisumTL::NIVisumTL(const std::string& name, SUMOTime cycleTime, SUMOTime offset,
38  SUMOTime intermediateTime, bool phaseDefined)
39  : myName(name), myCycleTime(cycleTime), myOffset(offset),
40  myIntermediateTime(intermediateTime), myPhaseDefined(phaseDefined) {
41 }
42 
43 
45  for (std::map<std::string, Phase*>::iterator i = myPhases.begin(); i != myPhases.end(); ++i) {
46  delete i->second;
47  }
48  for (std::map<std::string, SignalGroup*>::iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); ++i) {
49  delete i->second;
50  }
51 }
52 
53 
54 void
55 NIVisumTL::addSignalGroup(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
56  mySignalGroups[name] = new NIVisumTL::SignalGroup(name, startTime, endTime, yellowTime);
57 }
58 
59 
60 void
61 NIVisumTL::addPhase(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
62  myPhases[name] = new NIVisumTL::Phase(startTime, endTime, yellowTime);
63 }
64 
65 
67 NIVisumTL::getSignalGroup(const std::string& name) {
68  return *mySignalGroups.find(name)->second;
69 }
70 
71 
72 void
74  for (std::vector<NBNode*>::iterator ni = myNodes.begin(); ni != myNodes.end(); ni++) {
75  NBNode* node = (*ni);
76  if (node == nullptr) {
77  WRITE_WARNING("invalid node for traffic light '" + myName + "'");
78  continue;
79  }
81  NBLoadedTLDef* def = new NBLoadedTLDef(ec, node->getID(), node, myOffset, type);
82  tlc.insert(def);
83  def->setCycleDuration((int) myCycleTime);
84  // signalgroups
85  for (std::map<std::string, SignalGroup*>::iterator gi = mySignalGroups.begin(); gi != mySignalGroups.end(); gi++) {
86  std::string groupName = (*gi).first;
87  NIVisumTL::SignalGroup& SG = *(*gi).second;
88  def->addSignalGroup(groupName);
89  def->addToSignalGroup(groupName, SG.connections());
90  // phases
91  SUMOTime yellowTime = -1;
92  if (myPhaseDefined) {
93  for (std::map<std::string, Phase*>::iterator pi = SG.phases().begin(); pi != SG.phases().end(); pi++) {
94  NIVisumTL::Phase& PH = *(*pi).second;
97  yellowTime = MAX2(PH.getYellowTime(), yellowTime);
98  };
99  } else {
102  yellowTime = MAX2(SG.getYellowTime(), yellowTime);
103  }
104  // yellowTime can be -1 if not given in the input; it will be "patched" later
105  def->setSignalYellowTimes(groupName, myIntermediateTime, yellowTime);
106  }
107  }
108 }
109 
110 
111 
112 /****************************************************************************/
113 
NIVisumTL::myCycleTime
SUMOTime myCycleTime
The cycle time of traffic light in seconds.
Definition: NIVisumTL.h:172
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
NIVisumTL::myNodes
std::vector< NBNode * > myNodes
Vector of nodes belonging to this traffic light.
Definition: NIVisumTL.h:184
NBTrafficLightDefinition::TLCOLOR_RED
@ TLCOLOR_RED
Signal shows red.
Definition: NBTrafficLightDefinition.h:79
NIVisumTL::getSignalGroup
SignalGroup & getSignalGroup(const std::string &name)
Returns the named signal group.
Definition: NIVisumTL.cpp:67
NBTrafficLightLogicCont
A container for traffic light definitions and built programs.
Definition: NBTrafficLightLogicCont.h:57
OptionsCont.h
NBLoadedTLDef::addSignalGroup
void addSignalGroup(const std::string &id)
Adds a signal group.
Definition: NBLoadedTLDef.cpp:594
MsgHandler.h
NIVisumTL::~NIVisumTL
~NIVisumTL()
Destructor.
Definition: NIVisumTL.cpp:44
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1197
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
NBEdgeCont.h
NIVisumTL::TimePeriod::getStartTime
SUMOTime getStartTime()
Returns the stored start time.
Definition: NIVisumTL.h:58
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
NBLoadedTLDef::addSignalGroupPhaseBegin
void addSignalGroupPhaseBegin(const std::string &groupid, SUMOTime time, TLColor color)
Sets the information about the begin of a phase.
Definition: NBLoadedTLDef.cpp:601
NIVisumTL::addSignalGroup
void addSignalGroup(const std::string &name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
Adds a signal group.
Definition: NIVisumTL.cpp:55
NIVisumTL::TimePeriod::getYellowTime
SUMOTime getYellowTime()
Returns the stored yellow time.
Definition: NIVisumTL.h:68
NBLoadedTLDef::setCycleDuration
void setCycleDuration(int cycleDur)
Sets the duration of a cycle.
Definition: NBLoadedTLDef.cpp:616
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
NIVisumTL::SignalGroup
A signal group can be defined either by a time period or by phases.
Definition: NIVisumTL.h:101
NIVisumTL::SignalGroup::connections
NBConnectionVector & connections()
Returns the connections vector.
Definition: NIVisumTL.h:111
NIVisumTL::myPhaseDefined
bool myPhaseDefined
Toogles the usage either of phases or of time periods in signal groups.
Definition: NIVisumTL.h:181
NIVisumTL.h
NBLoadedTLDef.h
StringBijection::get
T get(const std::string &str) const
Definition: StringBijection.h:97
NIVisumTL::myOffset
SUMOTime myOffset
The offset in the plan.
Definition: NIVisumTL.h:175
NBLoadedTLDef::setSignalYellowTimes
void setSignalYellowTimes(const std::string &groupid, SUMOTime tRedYellow, SUMOTime tYellow)
Sets the times the light is yellow or red/yellow.
Definition: NBLoadedTLDef.cpp:608
NIVisumTL::addPhase
void addPhase(const std::string &name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
Adds a phase.
Definition: NIVisumTL.cpp:61
NIVisumTL::myIntermediateTime
SUMOTime myIntermediateTime
The all-red time (unused here)
Definition: NIVisumTL.h:178
NIVisumTL::Phase
A phase.
Definition: NIVisumTL.h:86
NIVisumTL::NIVisumTL
NIVisumTL(const std::string &name, SUMOTime cycleTime, SUMOTime offset, SUMOTime intermediateTime, bool phaseDefined)
Constructor.
Definition: NIVisumTL.cpp:37
NBLoadedTLDef
A loaded (complete) traffic light logic.
Definition: NBLoadedTLDef.h:41
SUMOXMLDefinitions::TrafficLightTypes
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
Definition: SUMOXMLDefinitions.h:1392
config.h
NIVisumTL::mySignalGroups
std::map< std::string, SignalGroup * > mySignalGroups
Map of used signal groups.
Definition: NIVisumTL.h:190
NIVisumTL::myName
std::string myName
The name of traffic light.
Definition: NIVisumTL.h:169
NIVisumTL::SignalGroup::phases
std::map< std::string, Phase * > & phases()
Returns the phases map.
Definition: NIVisumTL.h:116
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:67
NBTrafficLightLogicCont.h
NBTrafficLightLogicCont::insert
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
Definition: NBTrafficLightLogicCont.cpp:73
NIVisumTL::TimePeriod::getEndTime
SUMOTime getEndTime()
Returns the stored end time.
Definition: NIVisumTL.h:63
NIVisumTL::build
void build(NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
build the traffic light and add it to the given container
Definition: NIVisumTL.cpp:73
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
NIVisumTL::myPhases
std::map< std::string, Phase * > myPhases
Map of used phases if phases defined.
Definition: NIVisumTL.h:187
NBLoadedTLDef::addToSignalGroup
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
Definition: NBLoadedTLDef.cpp:562
NBTrafficLightDefinition::TLCOLOR_GREEN
@ TLCOLOR_GREEN
Signal shows green.
Definition: NBTrafficLightDefinition.h:85