Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSPhaseDefinition.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/****************************************************************************/
22// The definition of a single phase of a tls logic
23/****************************************************************************/
24#pragma once
25#include <config.h>
26
27#define TARGET_BIT 0
28#define TRANSIENT_NOTDECISIONAL_BIT 1
29#define COMMIT_BIT 2
30#define UNDEFINED_BIT 3
31#include <config.h>
32
33#include <bitset>
34#include <string>
35#include <vector>
40
41
42// ===========================================================================
43// class definitions
44// ===========================================================================
52public:
53
54 static const SUMOTime UNSPECIFIED_DURATION = -1;
56
59
62
65
68
71
74
76 std::string earlyTarget;
77
79 std::string finalTarget;
80
83
86
88 std::vector<int> nextPhases;
89
91 std::string name;
92
95
98
101
104
107
110
111 /*
112 * @brief The lanes-set
113 * This array can be empty if this phase is not a target step,
114 * otherwise, a bit is true if the corresponding lane belongs to a
115 * set of input lanes.
116 * SOTL traffic light logics choose the target step according to sensors
117 * belonging to the lane-set.
118 */
119 std::vector<std::string> myTargetLaneSet;
120
121private:
123 std::string myState;
124
125
126public:
128 MSPhaseDefinition(SUMOTime _duration, const std::string& state, const std::string& _name = ""):
129 duration(_duration),
137 name(_name),
142 myCommit(false),
143 myUndefined(false),
144 myState(state)
145 {}
146
147
149 virtual ~MSPhaseDefinition() { }
150
151
155 const std::string& getState() const {
156 return myState;
157 }
158
159 void setState(const std::string& _state) {
160 myState = _state;
161 }
162
163 const std::vector<std::string>& getTargetLaneSet() const {
164 return myTargetLaneSet;
165 }
166
167 const std::vector<int>& getNextPhases() const {
168 return nextPhases;
169 }
170
171 const std::string& getName() const {
172 return name;
173 }
174
175 void setName(const std::string& _name) {
176 name = _name;
177 }
178
186 bool isGreenPhase() const {
187 if (myState.find_first_of("gG") == std::string::npos) {
188 return false;
189 }
190 if (myState.find_first_of("yY") != std::string::npos) {
191 return false;
192 }
193 return true;
194 }
195
196
203 bool isAllRedPhase() const {
204 return (int)myState.size() == (int)std::count(myState.begin(), myState.end(), 'r');
205 }
206
207
212 LinkState getSignalState(int pos) const {
213 return (LinkState) myState[pos];
214 }
215
216 inline bool isActuated() const {
218 }
219
227 return myState != pd.myState || name != pd.name;
228 }
229
230
231 /*
232 * @return true if the phase type is undefined
233 */
234 bool isUndefined() const {
235 return myUndefined;
236 }
237
238 /*
239 * @return true if this is a target phase
240 */
241 bool isTarget() const {
242 return !myTargetLaneSet.empty();
243 }
244
245 /*
246 * @return true if this is a transient phase
247 */
248 bool isTransient() const {
250 }
251
252 /*
253 * @return true if this is a decisional phase
254 */
255 bool isDecisional() const {
257 }
258
259 /*
260 * @return true if this is a commit phase
261 */
262 bool isCommit() const {
263 return myCommit;
264 }
265
266};
long long int SUMOTime
Definition GUI.h:36
#define TIME2STEPS(x)
Definition SUMOTime.h:57
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
The definition of a single phase of a tls logic.
std::string name
Optional name or description for the current phase.
SUMOTime lastDuration
The previous duration of the phase.
std::vector< std::string > myTargetLaneSet
SUMOTime maxDuration
The maximum duration of the phase.
bool myCommit
the phase is a commit, compulsory directive for SOTL policies
LinkState getSignalState(int pos) const
Returns the state of the tls signal at the given position.
static const SUMOTime UNSPECIFIED_DURATION
SUMOTime myLastEnd
Stores the timestep when the previous instance of this phase was switched off.
static const SUMOTime OVERRIDE_DURATION
SUMOTime vehext
for NEMA phase
SUMOTime latestEnd
The maximum time within the cycle for switching (for coordinated actuation)
const std::vector< int > & getNextPhases() const
virtual ~MSPhaseDefinition()
Destructor.
bool myUndefined
Leaving the phase type as "undefined" lets SOTL policies malfunction.
bool myTransientNotDecisional
the phase is a transient one or a decisional one, compulsory directive for SOTL policies
SUMOTime minDuration
The minimum duration of the phase.
const std::string & getName() const
SUMOTime yellow
for NEMA phase
SUMOTime red
for NEMA phase
SUMOTime myLastSwitch
Stores the timestep of the last on-switched of the phase.
const std::string & getState() const
Returns the state within this phase.
SUMOTime duration
The duration of the phase.
bool isGreenPhase() const
Returns whether this phase is a pure "green" phase.
bool isDecisional() const
std::vector< int > nextPhases
The index of the phase that suceeds this one (or -1)
void setState(const std::string &_state)
std::string finalTarget
The condition expression for switching into this phase when the active phase must end.
MSPhaseDefinition(SUMOTime _duration, const std::string &state, const std::string &_name="")
Constructor.
std::string earlyTarget
The condition expression for an early switch into this phase.
std::string myState
The phase definition.
bool isAllRedPhase() const
Returns whether this phase is an "all red" phase.
void setName(const std::string &_name)
bool operator!=(const MSPhaseDefinition &pd)
Comparison operator.
const std::vector< std::string > & getTargetLaneSet() const
SUMOTime earliestEnd
The minimum time within the cycle for switching (for coordinated actuation)