SUMO - Simulation of Urban MObility
NIVisumTL.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Intermediate class for storing visum traffic lights during their import
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2003-2016 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
35 #include <netbuild/NBLoadedTLDef.h>
37 #include <netbuild/NBEdgeCont.h>
38 #include "NIVisumTL.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 NIVisumTL::NIVisumTL(const std::string& name, SUMOTime cycleTime, SUMOTime offset,
49  SUMOTime intermediateTime, bool phaseDefined)
50  : myName(name), myCycleTime(cycleTime), myOffset(offset),
51  myIntermediateTime(intermediateTime), myPhaseDefined(phaseDefined) {
52 }
53 
54 
56  for (std::map<std::string, Phase*>::iterator i = myPhases.begin(); i != myPhases.end(); ++i) {
57  delete i->second;
58  }
59  for (std::map<std::string, SignalGroup*>::iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); ++i) {
60  delete i->second;
61  }
62 }
63 
64 
65 void
66 NIVisumTL::addSignalGroup(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
67  mySignalGroups[name] = new NIVisumTL::SignalGroup(name, startTime, endTime, yellowTime);
68 }
69 
70 
71 void
72 NIVisumTL::addPhase(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
73  myPhases[name] = new NIVisumTL::Phase(startTime, endTime, yellowTime);
74 }
75 
76 
78 NIVisumTL::getSignalGroup(const std::string& name) {
79  return *mySignalGroups.find(name)->second;
80 }
81 
82 
83 void
85  for (std::vector<NBNode*>::iterator ni = myNodes.begin(); ni != myNodes.end(); ni++) {
86  NBNode* node = (*ni);
88  NBLoadedTLDef* def = new NBLoadedTLDef(ec, node->getID(), node, myOffset, type);
89  tlc.insert(def);
90  def->setCycleDuration((unsigned int) myCycleTime);
91  // signalgroups
92  for (std::map<std::string, SignalGroup*>::iterator gi = mySignalGroups.begin(); gi != mySignalGroups.end(); gi++) {
93  std::string groupName = (*gi).first;
94  NIVisumTL::SignalGroup& SG = *(*gi).second;
95  def->addSignalGroup(groupName);
96  def->addToSignalGroup(groupName, SG.connections());
97  // phases
98  SUMOTime yellowTime = -1;
99  if (myPhaseDefined) {
100  for (std::map<std::string, Phase*>::iterator pi = SG.phases().begin(); pi != SG.phases().end(); pi++) {
101  NIVisumTL::Phase& PH = *(*pi).second;
104  yellowTime = MAX2(PH.getYellowTime(), yellowTime);
105  };
106  } else {
109  yellowTime = MAX2(SG.getYellowTime(), yellowTime);
110  }
111  // yellowTime can be -1 if not given in the input; it will be "patched" later
112  def->setSignalYellowTimes(groupName, myIntermediateTime, yellowTime);
113  }
114  }
115 }
116 
117 
118 
119 /****************************************************************************/
120 
std::map< std::string, Phase * > & phases()
Returns the phases map.
Definition: NIVisumTL.h:124
bool myPhaseDefined
Toogles the usage either of phases or of time periods in signal groups.
Definition: NIVisumTL.h:189
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:109
long long int SUMOTime
Definition: SUMOTime.h:43
SUMOTime getYellowTime()
Returns the stored yellow time.
Definition: NIVisumTL.h:76
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:49
SignalGroup & getSignalGroup(const std::string &name)
Returns the named signal group.
Definition: NIVisumTL.cpp:78
T MAX2(T a, T b)
Definition: StdDefs.h:75
SUMOTime myCycleTime
The cycle time of traffic light in seconds.
Definition: NIVisumTL.h:180
void addPhase(const std::string &name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
Adds a phase.
Definition: NIVisumTL.cpp:72
void addSignalGroup(const std::string &name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
Adds a signal group.
Definition: NIVisumTL.cpp:66
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
A phase.
Definition: NIVisumTL.h:94
SUMOTime getEndTime()
Returns the stored end time.
Definition: NIVisumTL.h:71
~NIVisumTL()
Destructor.
Definition: NIVisumTL.cpp:55
const std::string & getID() const
Returns the id.
Definition: Named.h:65
SUMOTime getStartTime()
Returns the stored start time.
Definition: NIVisumTL.h:66
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:183
static StringBijection< TrafficLightType > TrafficLightTypes
void build(NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
build the traffic light and add it to the given container
Definition: NIVisumTL.cpp:84
NIVisumTL(const std::string &name, SUMOTime cycleTime, SUMOTime offset, SUMOTime intermediateTime, bool phaseDefined)
Constructor.
Definition: NIVisumTL.cpp:48
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:198
void setCycleDuration(unsigned int cycleDur)
Sets the duration of a cycle.
void addSignalGroup(const std::string &id)
Adds a signal group.
NBConnectionVector & connections()
Returns the connections vector.
Definition: NIVisumTL.h:119
SUMOTime myIntermediateTime
The all-red time (unused here)
Definition: NIVisumTL.h:186
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:195
T get(const std::string &str) const
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:192
TrafficLightType