Eclipse SUMO - Simulation of Urban MObility
NBTrafficLightLogic.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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 // A SUMO-compliant built logic for a traffic light
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 
25 #include <vector>
26 #include <string>
27 #include <bitset>
28 #include <utility>
29 #include <set>
30 #include "NBConnectionDefs.h"
31 #include <utils/common/SUMOTime.h>
32 #include <utils/common/Named.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class OutputDevice;
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
49 class NBTrafficLightLogic : public Named, public Parameterised {
50 public:
56  public:
61 
63  std::string state;
64 
66  std::vector<int> next;
68  std::string name;
69 
74  PhaseDefinition(SUMOTime durationArg, const std::string& stateArg, SUMOTime minDurArg, SUMOTime maxDurArg, const std::vector<int>& nextArg, const std::string& nameArg) :
75  duration(durationArg),
76  minDur(minDurArg),
77  maxDur(maxDurArg),
78  state(stateArg),
79  next(nextArg),
80  name(nameArg)
81  { }
82 
85 
90  bool operator!=(const PhaseDefinition& pd) const {
91  return (pd.duration != duration
92  || pd.minDur != minDur
93  || pd.maxDur != maxDur
94  || pd.state != state
95  || pd.next != next
96  || pd.name != name);
97  }
98 
99  };
100 
101 
109  NBTrafficLightLogic(const std::string& id, const std::string& subid, int noLinks,
111 
112 
117 
118 
121 
122 
135  void addStep(SUMOTime duration, const std::string& state,
136  const std::vector<int>& next = std::vector<int>(), const std::string& name = "", int index = -1);
137  void addStep(SUMOTime duration, const std::string& state, SUMOTime minDur, SUMOTime maxDur,
138  const std::vector<int>& next = std::vector<int>(), const std::string& name = "", int index = -1);
139 
140 
146  void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState);
147 
152  void setPhaseDuration(int phaseIndex, SUMOTime duration);
153  void setPhaseMinDuration(int phaseIndex, SUMOTime duration);
154  void setPhaseMaxDuration(int phaseIndex, SUMOTime duration);
155  void setPhaseNext(int phaseIndex, const std::vector<int>& next);
156  void setPhaseName(int phaseIndex, const std::string& name);
157 
158  /* @brief deletes the phase at the given index
159  * @note thhrows InvalidArgument on out-of range index
160  */
161  void deletePhase(int index);
162 
163  /* @brief changes state size either by cutting of at the end or by adding
164  * new states at the end
165  */
166  void setStateLength(int numLinks, LinkState fill = LINKSTATE_TL_RED);
167 
169  void deleteStateIndex(int index);
170 
171  /* @brief deletes all phases and reset the expect number of links
172  */
173  void resetPhases();
174 
179  void closeBuilding(bool checkVarDurations = true);
180 
181 
185  SUMOTime getDuration() const;
186 
187 
191  void setOffset(SUMOTime offset) {
192  myOffset = offset;
193  }
194 
195 
199  const std::string& getProgramID() const {
200  return mySubID;
201  };
202 
203 
207  const std::vector<PhaseDefinition>& getPhases() const {
208  return myPhases;
209  }
210 
211 
215  SUMOTime getOffset() const {
216  return myOffset;
217  };
218 
219 
222  int getNumLinks() {
223  return myNumLinks;
224  }
225 
228  return myType;
229  }
230 
233  myType = type;
234  }
235 
239  void setProgramID(const std::string& programID) {
240  mySubID = programID;
241  }
242 
243 private:
246 
248  std::string mySubID;
249 
252 
254  typedef std::vector<PhaseDefinition> PhaseDefinitionVector;
255 
258 
261 
262 private:
265 
266 };
long long int SUMOTime
Definition: SUMOTime.h:31
TrafficLightType
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
@ LINKSTATE_TL_RED
The link has red light (must brake)
The definition of a single phase of the logic.
PhaseDefinition(SUMOTime durationArg, const std::string &stateArg, SUMOTime minDurArg, SUMOTime maxDurArg, const std::vector< int > &nextArg, const std::string &nameArg)
Constructor.
bool operator!=(const PhaseDefinition &pd) const
Comparison operator.
std::string state
The state definition.
std::string name
option phase name
SUMOTime duration
The duration of the phase in s.
std::vector< int > next
next phase indices or empty list
A SUMO-compliant built logic for a traffic light.
SUMOTime getDuration() const
Returns the duration of the complete cycle.
void deleteStateIndex(int index)
remove the index from all phase states
SUMOTime myOffset
The tls program's offset.
int myNumLinks
The number of participating links.
void setPhaseMinDuration(int phaseIndex, SUMOTime duration)
NBTrafficLightLogic & operator=(const NBTrafficLightLogic &s)=delete
Invalidated assignment operator.
NBTrafficLightLogic(const std::string &id, const std::string &subid, int noLinks, SUMOTime offset=0, TrafficLightType type=TrafficLightType::STATIC)
Constructor.
void closeBuilding(bool checkVarDurations=true)
closes the building process
SUMOTime getOffset() const
Returns the offset of first switch.
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
PhaseDefinitionVector myPhases
The junction logic's storage for traffic light phase list.
void setPhaseName(int phaseIndex, const std::string &name)
void setPhaseDuration(int phaseIndex, SUMOTime duration)
Modifies the duration for an existing phase (used by NETEDIT)
void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState)
Modifies the state for an existing phase (used by NETEDIT)
void setPhaseMaxDuration(int phaseIndex, SUMOTime duration)
int getNumLinks()
Returns the number of participating links.
const std::string & getProgramID() const
Returns the ProgramID.
void setType(TrafficLightType type)
set the algorithm type (static etc..)
void addStep(SUMOTime duration, const std::string &state, const std::vector< int > &next=std::vector< int >(), const std::string &name="", int index=-1)
Adds a phase to the logic.
void setPhaseNext(int phaseIndex, const std::vector< int > &next)
~NBTrafficLightLogic()
Destructor.
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
TrafficLightType getType() const
get the algorithm type (static etc..)
TrafficLightType myType
The algorithm type for the traffic light.
void setOffset(SUMOTime offset)
Sets the offset of this tls.
std::string mySubID
The tls program's subid.
void setProgramID(const std::string &programID)
Sets the programID.
std::vector< PhaseDefinition > PhaseDefinitionVector
Definition of a vector of traffic light phases.
Base class for objects which have an id.
Definition: Named.h:53
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
An upper class for objects with additional parameters.
Definition: Parameterised.h:39