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