Eclipse SUMO - Simulation of Urban MObility
MSPhaseDefinition.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-2022 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>
37 #include <utils/common/SUMOTime.h>
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
52 public:
53 
54  static const SUMOTime UNSPECIFIED_DURATION = -1;
55 
58 
61 
64 
67 
70 
73 
75  std::string earlyTarget;
76 
78  std::string finalTarget;
79 
82 
85 
87  std::vector<int> nextPhases;
88 
90  std::string name;
91 
94 
97 
100 
103 
105  bool myCommit;
106 
109 
110  /*
111  * @brief The lanes-set
112  * This array can be empty if this phase is not a target step,
113  * otherwise, a bit is true if the corresponding lane belongs to a
114  * set of input lanes.
115  * SOTL traffic light logics choose the target step according to sensors
116  * belonging to the lane-set.
117  */
118  std::vector<std::string> myTargetLaneSet;
119 
120 private:
122  std::string myState;
123 
124 
125 public:
127  MSPhaseDefinition(SUMOTime _duration, const std::string& state, const std::string& _name = ""):
128  duration(_duration),
136  name(_name),
141  myCommit(false),
142  myUndefined(false),
143  myState(state)
144  {}
145 
146 
148  virtual ~MSPhaseDefinition() { }
149 
150 
154  const std::string& getState() const {
155  return myState;
156  }
157 
158  void setState(const std::string& _state) {
159  myState = _state;
160  }
161 
162  const std::vector<std::string>& getTargetLaneSet() const {
163  return myTargetLaneSet;
164  }
165 
166  const std::vector<int>& getNextPhases() const {
167  return nextPhases;
168  }
169 
170  const std::string& getName() const {
171  return name;
172  }
173 
174  void setName(const std::string& _name) {
175  name = _name;
176  }
177 
185  bool isGreenPhase() const {
186  if (myState.find_first_of("gG") == std::string::npos) {
187  return false;
188  }
189  if (myState.find_first_of("yY") != std::string::npos) {
190  return false;
191  }
192  return true;
193  }
194 
195 
200  LinkState getSignalState(int pos) const {
201  return (LinkState) myState[pos];
202  }
203 
204  inline bool isActuted() const {
205  return minDuration != maxDuration;
206  }
207 
214  bool operator!=(const MSPhaseDefinition& pd) {
215  return myState != pd.myState || name != pd.name;
216  }
217 
218 
219  /*
220  * @return true if the phase type is undefined
221  */
222  bool isUndefined() const {
223  return myUndefined;
224  }
225 
226  /*
227  * @return true if this is a target phase
228  */
229  bool isTarget() const {
230  return !myTargetLaneSet.empty();
231  }
232 
233  /*
234  * @return true if this is a transient phase
235  */
236  bool isTransient() const {
238  }
239 
240  /*
241  * @return true if this is a decisional phase
242  */
243  bool isDecisional() const {
244  return !myTransientNotDecisional;
245  }
246 
247  /*
248  * @return true if this is a commit phase
249  */
250  bool isCommit() const {
251  return myCommit;
252  }
253 
254 };
long long int SUMOTime
Definition: SUMOTime.h:32
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.
const std::string & getState() const
Returns the state within this phase.
std::string name
Optional name or description for the current phase.
SUMOTime lastDuration
The previous duration of the phase.
bool isTransient() const
bool isUndefined() const
const std::vector< std::string > & getTargetLaneSet() const
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.
SUMOTime vehext
for NEMA phase
SUMOTime latestEnd
The maximum time within the cycle for switching (for coordinated actuation)
virtual ~MSPhaseDefinition()
Destructor.
bool myUndefined
Leaving the phase type as "undefined" lets SOTL policies malfunction.
const std::vector< int > & getNextPhases() const
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.
SUMOTime yellow
for NEMA phase
SUMOTime red
for NEMA phase
SUMOTime myLastSwitch
Stores the timestep of the last on-switched of the phase.
SUMOTime duration
The duration of the phase.
bool isGreenPhase() const
Returns whether this phase is a pure "green" phase.
const std::string & getName() const
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.
bool isActuted() const
std::string myState
The phase definition.
void setName(const std::string &_name)
bool operator!=(const MSPhaseDefinition &pd)
Comparison operator.
SUMOTime earliestEnd
The minimum time within the cycle for switching (for coordinated actuation)