Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NBTrafficLightLogic.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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// 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"
32#include <utils/common/Named.h>
34
35
36// ===========================================================================
37// class declarations
38// ===========================================================================
39class OutputDevice;
40
41
42// ===========================================================================
43// class definitions
44// ===========================================================================
49class NBTrafficLightLogic : public Named, public Parameterised {
50public:
56
57 public:
60
62 std::string state;
63
66
69
72
75
78
81
84
86 std::vector<int> next;
87
89 std::string name;
90
95 PhaseDefinition(const SUMOTime duration_, const std::string& state_, const SUMOTime minDur_, const SUMOTime maxDur_,
96 const SUMOTime earliestEnd_, const SUMOTime latestEnd_, const SUMOTime vehExt_, const SUMOTime yellow_,
97 const SUMOTime red_, const std::vector<int>& next_, const std::string& name_) :
98 duration(duration_),
99 state(state_),
100 minDur(minDur_),
101 maxDur(maxDur_),
102 earliestEnd(earliestEnd_),
103 latestEnd(latestEnd_),
104 vehExt(vehExt_),
105 yellow(yellow_),
106 red(red_),
107 next(next_),
108 name(name_)
109 { }
110
113
118 bool operator!=(const PhaseDefinition& pd) const {
119 return ((pd.duration != duration) ||
120 (pd.minDur != minDur) ||
121 (pd.maxDur != maxDur) ||
122 (pd.earliestEnd != earliestEnd) ||
123 (pd.latestEnd != latestEnd) ||
124 (pd.state != state) ||
125 (pd.next != next) ||
126 (pd.name != name));
127 }
128
129 };
130
131
139 NBTrafficLightLogic(const std::string& id, const std::string& subid, int noLinks,
141
142
147
148
151
152
163 void addStep(const SUMOTime duration, const std::string& state, const std::vector<int>& next = std::vector<int>(),
164 const std::string& name = "", const int index = -1);
165
183 void addStep(const SUMOTime duration, const std::string& state, const SUMOTime minDur, const SUMOTime maxDur, const SUMOTime earliestEnd,
184 const SUMOTime latestEnd,
185 const SUMOTime vehExt = -1, // UNSPECIFIED_DURATION
186 const SUMOTime yellow = -1, // UNSPECIFIED_DURATION
187 const SUMOTime red = -1, // UNSPECIFIED_DURATION
188 const std::string& name = "",
189 const std::vector<int>& next = std::vector<int>(),
190 int index = -1);
191
197 void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState);
198
203 void setPhaseDuration(int phaseIndex, SUMOTime duration);
204
209 void setPhaseMinDuration(int phaseIndex, SUMOTime duration);
210
215 void setPhaseMaxDuration(int phaseIndex, SUMOTime duration);
216
221 void setPhaseEarliestEnd(int phaseIndex, SUMOTime duration);
222
227 void setPhaseLatestEnd(int phaseIndex, SUMOTime duration);
228
233 void setPhaseVehExt(int phaseIndex, SUMOTime duration);
234
239 void setPhaseYellow(int phaseIndex, SUMOTime duration);
240
245 void setPhaseRed(int phaseIndex, SUMOTime duration);
246
251 void setPhaseNext(int phaseIndex, const std::vector<int>& next);
252
257 void setPhaseName(int phaseIndex, const std::string& name);
258
263 void overrideState(int phaseIndex, const char c);
264
265 /* @brief deletes the phase at the given index
266 * @note throws InvalidArgument on out-of range index
267 */
268 void deletePhase(int index);
269
270 /* @brief swap phases
271 * @note throws InvalidArgument on out-of range index
272 */
273 void swapPhase(int indexPhaseA, int indexPhaseB);
274
276 void swapfirstPhase();
277
279 void swaplastPhase();
280
281 /* @brief changes state size either by cutting of at the end or by adding
282 * new states at the end
283 */
284 void setStateLength(int numLinks, LinkState fill = LINKSTATE_TL_RED);
285
287 void deleteStateIndex(int index);
288
290 void resetPhases();
291
296 void closeBuilding(bool checkVarDurations = true);
297
299 SUMOTime getDuration() const;
300
304 void setOffset(SUMOTime offset) {
305 myOffset = offset;
306 }
307
309 const std::string& getProgramID() const {
310 return mySubID;
311 };
312
314 const std::vector<PhaseDefinition>& getPhases() const {
315 return myPhases;
316 }
317
319 void copyPhase(const int origin, const int destination) {
320 myPhases.at(destination) = myPhases.at(origin);
321 }
322
325 return myOffset;
326 };
327
330 return myNumLinks;
331 }
332
335 return myType;
336 }
337
340 myType = type;
341 }
342
346 void setProgramID(const std::string& programID) {
347 mySubID = programID;
348 }
349
350private:
353
355 std::string mySubID;
356
359
361 typedef std::vector<PhaseDefinition> PhaseDefinitionVector;
362
365
368
371};
long long int SUMOTime
Definition GUI.h:36
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.
SUMOTime latestEnd
maximum duration duration (for actuated)
bool operator!=(const PhaseDefinition &pd) const
Comparison operator.
SUMOTime earliestEnd
minimum duration (for actuated)
SUMOTime maxDur
maximum duration duration (for actuated)
std::string state
The state definition.
PhaseDefinition(const SUMOTime duration_, const std::string &state_, const SUMOTime minDur_, const SUMOTime maxDur_, const SUMOTime earliestEnd_, const SUMOTime latestEnd_, const SUMOTime vehExt_, const SUMOTime yellow_, const SUMOTime red_, const std::vector< int > &next_, const std::string &name_)
Constructor.
SUMOTime minDur
minimum duration (for actuated)
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.
void copyPhase(const int origin, const int destination)
copy phase values in other
SUMOTime getDuration() const
Returns the duration of the complete cycle.
void setPhaseVehExt(int phaseIndex, SUMOTime duration)
Modifies the veh ex for an existing phase (used by netedit)
void deleteStateIndex(int index)
remove the index from all phase states
SUMOTime myOffset
The tls program's offset.
void resetPhases()
deletes all phases and reset the expect number of links
void setPhaseEarliestEnd(int phaseIndex, SUMOTime duration)
Modifies the min duration for an existing phase (used by netedit)
void setPhaseRed(int phaseIndex, SUMOTime duration)
Modifies the veh ex for an existing phase (used by netedit)
int myNumLinks
The number of participating links.
void setPhaseMinDuration(int phaseIndex, SUMOTime duration)
Modifies the min duration for an existing phase (used by netedit)
void swaplastPhase()
swap first phase
void closeBuilding(bool checkVarDurations=true)
closes the building process
void swapPhase(int indexPhaseA, int indexPhaseB)
SUMOTime getOffset() const
Returns the offset of first switch.
NBTrafficLightLogic & operator=(const NBTrafficLightLogic &s)=delete
Invalidated assignment operator.
void overrideState(int phaseIndex, const char c)
override state with the given character(used by netedit)
PhaseDefinitionVector myPhases
The junction logic's storage for traffic light phase list.
void setPhaseName(int phaseIndex, const std::string &name)
Modifies the phase name (used by netedit)
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)
Modifies the max duration for an existing phase (used by netedit)
int getNumLinks()
Returns the number of participating links.
void setPhaseYellow(int phaseIndex, SUMOTime duration)
Modifies the veh ex for an existing phase (used by netedit)
void setType(TrafficLightType type)
set the algorithm type (static etc..)
void setPhaseLatestEnd(int phaseIndex, SUMOTime duration)
Modifies the max duration for an existing phase (used by netedit)
void setPhaseNext(int phaseIndex, const std::vector< int > &next)
Modifies the next phase (used by netedit)
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
TrafficLightType getType() const
get the algorithm type (static etc..)
void swapfirstPhase()
swap first phase
TrafficLightType myType
The algorithm type for the traffic light.
void setOffset(SUMOTime offset)
Sets the offset of this tls.
const std::string & getProgramID() const
Returns the ProgramID.
std::string mySubID
The tls program's subid.
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
void addStep(const SUMOTime duration, const std::string &state, const std::vector< int > &next=std::vector< int >(), const std::string &name="", const int index=-1)
Adds a phase to the logic (static)
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:54
Static storage of an output device and its base (abstract) implementation.
An upper class for objects with additional parameters.