Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NIVisumTL.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2003-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// Intermediate class for storing visum traffic lights during their import
21/****************************************************************************/
22#include <config.h>
23
24#include <string>
29#include <netbuild/NBEdgeCont.h>
30#include "NIVisumTL.h"
31
32
33// ===========================================================================
34// method definitions
35// ===========================================================================
36NIVisumTL::NIVisumTL(const std::string& name, SUMOTime cycleTime, SUMOTime offset,
37 SUMOTime intermediateTime, bool phaseDefined)
38 : myName(name), myCycleTime(cycleTime), myOffset(offset),
39 myIntermediateTime(intermediateTime), myPhaseDefined(phaseDefined) {
40}
41
42
44 for (std::map<std::string, Phase*>::iterator i = myPhases.begin(); i != myPhases.end(); ++i) {
45 delete i->second;
46 }
47 for (std::map<std::string, SignalGroup*>::iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); ++i) {
48 delete i->second;
49 }
50}
51
52
53void
54NIVisumTL::addSignalGroup(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
55 mySignalGroups[name] = new NIVisumTL::SignalGroup(name, startTime, endTime, yellowTime);
56}
57
58
59void
60NIVisumTL::addPhase(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
61 myPhases[name] = new NIVisumTL::Phase(startTime, endTime, yellowTime);
62}
63
64
66NIVisumTL::getSignalGroup(const std::string& name) {
67 return *mySignalGroups.find(name)->second;
68}
69
70
71void
73 for (std::vector<NBNode*>::iterator ni = myNodes.begin(); ni != myNodes.end(); ni++) {
74 NBNode* node = (*ni);
75 if (node == nullptr) {
76 WRITE_WARNINGF(TL("invalid node for traffic light '%'"), myName);
77 continue;
78 }
80 NBLoadedTLDef* def = new NBLoadedTLDef(ec, node->getID(), node, myOffset, type);
81 tlc.insert(def);
83 // signalgroups
84 for (std::map<std::string, SignalGroup*>::iterator gi = mySignalGroups.begin(); gi != mySignalGroups.end(); gi++) {
85 std::string groupName = (*gi).first;
86 NIVisumTL::SignalGroup& SG = *(*gi).second;
87 def->addSignalGroup(groupName);
88 def->addToSignalGroup(groupName, SG.connections());
89 // phases
90 SUMOTime yellowTime = -1;
91 if (myPhaseDefined) {
92 for (std::map<std::string, Phase*>::iterator pi = SG.phases().begin(); pi != SG.phases().end(); pi++) {
93 NIVisumTL::Phase& PH = *(*pi).second;
96 yellowTime = MAX2(PH.getYellowTime(), yellowTime);
97 }
98 } else {
101 yellowTime = MAX2(SG.getYellowTime(), yellowTime);
102 }
103 // yellowTime can be -1 if not given in the input; it will be "patched" later
104 def->setSignalYellowTimes(groupName, myIntermediateTime, yellowTime);
105 }
106 }
107}
108
109
110/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define TL(string)
Definition MsgHandler.h:315
T MAX2(T a, T b)
Definition StdDefs.h:82
Storage for edges, including some functionality operating on multiple edges.
Definition NBEdgeCont.h:59
A loaded (complete) traffic light logic.
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
void addSignalGroupPhaseBegin(const std::string &groupid, SUMOTime time, TLColor color)
Sets the information about the begin of a phase.
void setSignalYellowTimes(const std::string &groupid, SUMOTime tRedYellow, SUMOTime tYellow)
Sets the times the light is yellow or red/yellow.
void addSignalGroup(const std::string &id)
Adds a signal group.
void setCycleDuration(SUMOTime cycleDur)
Sets the duration of a cycle.
Represents a single node (junction) during network building.
Definition NBNode.h:66
A container for traffic light definitions and built programs.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
A signal group can be defined either by a time period or by phases.
Definition NIVisumTL.h:103
std::map< std::string, Phase * > & phases()
Returns the phases map.
Definition NIVisumTL.h:118
NBConnectionVector & connections()
Returns the connections vector.
Definition NIVisumTL.h:113
SUMOTime getYellowTime()
Returns the stored yellow time.
Definition NIVisumTL.h:66
SUMOTime getStartTime()
Returns the stored start time.
Definition NIVisumTL.h:56
SUMOTime getEndTime()
Returns the stored end time.
Definition NIVisumTL.h:61
SUMOTime myOffset
The offset in the plan.
Definition NIVisumTL.h:177
bool myPhaseDefined
Toggles the usage either of phases or of time periods in signal groups.
Definition NIVisumTL.h:183
void addSignalGroup(const std::string &name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
Adds a signal group.
Definition NIVisumTL.cpp:54
SUMOTime myCycleTime
The cycle time of traffic light in seconds.
Definition NIVisumTL.h:174
NIVisumTL(const std::string &name, SUMOTime cycleTime, SUMOTime offset, SUMOTime intermediateTime, bool phaseDefined)
Constructor.
Definition NIVisumTL.cpp:36
std::map< std::string, SignalGroup * > mySignalGroups
Map of used signal groups.
Definition NIVisumTL.h:192
std::string myName
The name of traffic light.
Definition NIVisumTL.h:171
void addPhase(const std::string &name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
Adds a phase.
Definition NIVisumTL.cpp:60
std::vector< NBNode * > myNodes
Vector of nodes belonging to this traffic light.
Definition NIVisumTL.h:186
std::map< std::string, Phase * > myPhases
Map of used phases if phases defined.
Definition NIVisumTL.h:189
SignalGroup & getSignalGroup(const std::string &name)
Returns the named signal group.
Definition NIVisumTL.cpp:66
SUMOTime myIntermediateTime
The all-red time (unused here)
Definition NIVisumTL.h:180
void build(NBEdgeCont &ec, NBTrafficLightLogicCont &tlc)
build the traffic light and add it to the given container
Definition NIVisumTL.cpp:72
~NIVisumTL()
Destructor.
Definition NIVisumTL.cpp:43
const std::string & getID() const
Returns the id.
Definition Named.h:74
static OptionsCont & getOptions()
Retrieves the options.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(const std::string &str) const