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-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 /****************************************************************************/
17 // A SUMO-compliant built logic for a traffic light
18 /****************************************************************************/
19 #ifndef NBTrafficLightLogic_h
20 #define NBTrafficLightLogic_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <string>
30 #include <bitset>
31 #include <utility>
32 #include <set>
33 #include "NBConnectionDefs.h"
34 #include <utils/common/SUMOTime.h>
35 #include <utils/common/Named.h>
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 class OutputDevice;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
52 class NBTrafficLightLogic : public Named, public Parameterised {
53 public:
59  public:
64 
66  std::string state;
67 
69  std::vector<int> next;
71  std::string name;
72 
77  PhaseDefinition(SUMOTime durationArg, const std::string& stateArg, SUMOTime minDurArg, SUMOTime maxDurArg, const std::vector<int>& nextArg, const std::string& nameArg) :
78  duration(durationArg),
79  minDur(minDurArg),
80  maxDur(maxDurArg),
81  state(stateArg),
82  next(nextArg),
83  name(nameArg)
84  { }
85 
88 
93  bool operator!=(const PhaseDefinition& pd) const {
94  return (pd.duration != duration
95  || pd.minDur != minDur
96  || pd.maxDur != maxDur
97  || pd.state != state
98  || pd.next != next
99  || pd.name != name);
100  }
101 
102  };
103 
104 
112  NBTrafficLightLogic(const std::string& id, const std::string& subid, int noLinks,
113  SUMOTime offset = 0, TrafficLightType type = TLTYPE_STATIC);
114 
115 
120 
121 
124 
125 
138  void addStep(SUMOTime duration, const std::string& state,
139  const std::vector<int>& next = std::vector<int>(), const std::string& name = "", int index = -1);
140  void addStep(SUMOTime duration, const std::string& state, SUMOTime minDur, SUMOTime maxDur,
141  const std::vector<int>& next = std::vector<int>(), const std::string& name = "", int index = -1);
142 
143 
149  void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState);
150 
155  void setPhaseDuration(int phaseIndex, SUMOTime duration);
156  void setPhaseMinDuration(int phaseIndex, SUMOTime duration);
157  void setPhaseMaxDuration(int phaseIndex, SUMOTime duration);
158  void setPhaseNext(int phaseIndex, const std::vector<int>& next);
159  void setPhaseName(int phaseIndex, const std::string& name);
160 
161  /* @brief deletes the phase at the given index
162  * @note thhrows InvalidArgument on out-of range index
163  */
164  void deletePhase(int index);
165 
166  /* @brief changes state size either by cutting of at the end or by adding
167  * new states at the end
168  */
169  void setStateLength(int numLinks, LinkState fill = LINKSTATE_TL_RED);
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 
236 private:
239 
241  const std::string mySubID;
242 
245 
247  typedef std::vector<PhaseDefinition> PhaseDefinitionVector;
248 
250  PhaseDefinitionVector myPhases;
251 
254 
255 private:
258 
259 };
260 
261 
262 #endif
263 
264 /****************************************************************************/
265 
void setPhaseNext(int phaseIndex, const std::vector< int > &next)
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOTime getOffset() const
Returns the offset of first switch.
void setPhaseMaxDuration(int phaseIndex, SUMOTime duration)
int getNumLinks()
Returns the number of participating links.
void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState)
Modifies the state for an existing phase (used by NETEDIT)
std::vector< PhaseDefinition > PhaseDefinitionVector
Definition of a vector of traffic light phases.
A SUMO-compliant built logic for a traffic light.
PhaseDefinition(SUMOTime durationArg, const std::string &stateArg, SUMOTime minDurArg, SUMOTime maxDurArg, const std::vector< int > &nextArg, const std::string &nameArg)
Constructor.
int myNumLinks
The number of participating links.
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
NBTrafficLightLogic(const std::string &id, const std::string &subid, int noLinks, SUMOTime offset=0, TrafficLightType type=TLTYPE_STATIC)
Constructor.
void setPhaseMinDuration(int phaseIndex, SUMOTime duration)
void setOffset(SUMOTime offset)
Sets the offset of this tls.
const std::string & getProgramID() const
Returns the ProgramID.
The definition of a single phase of the logic.
SUMOTime duration
The duration of the phase in s.
bool operator!=(const PhaseDefinition &pd) const
Comparison operator.
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.
SUMOTime myOffset
The tls program&#39;s offset.
std::vector< int > next
next phase indices or empty list
std::string state
The state definition.
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
void setPhaseName(int phaseIndex, const std::string &name)
An upper class for objects with additional parameters.
Definition: Parameterised.h:43
Base class for objects which have an id.
Definition: Named.h:57
SUMOTime getDuration() const
Returns the duration of the complete cycle.
void closeBuilding(bool checkVarDurations=true)
closes the building process
std::string name
option phase name
TrafficLightType getType() const
get the algorithm type (static etc..)
const std::string mySubID
The tls program&#39;s subid.
~NBTrafficLightLogic()
Destructor.
The link has red light (must brake)
void setPhaseDuration(int phaseIndex, SUMOTime duration)
Modifies the duration for an existing phase (used by NETEDIT)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
TrafficLightType myType
The algorithm type for the traffic light.
PhaseDefinitionVector myPhases
The junction logic&#39;s storage for traffic light phase list.
TrafficLightType
NBTrafficLightLogic & operator=(const NBTrafficLightLogic &s)
Invalidated assignment operator.