Eclipse SUMO - Simulation of Urban MObility
NBLoadedTLDef.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 /****************************************************************************/
19 // A loaded (complete) traffic light logic
20 /****************************************************************************/
21 #pragma once
22 #include <config.h>
23 
24 #include <vector>
25 #include <string>
26 #include <set>
28 #include "NBNode.h"
29 #include <utils/common/SUMOTime.h>
30 
31 
32 // ===========================================================================
33 // class definitions
34 // ===========================================================================
40 public:
44  class SignalGroup : public Named {
45  public:
49  SignalGroup(const std::string& id);
50 
52  ~SignalGroup();
53 
57  void addConnection(const NBConnection& c);
58 
63  void addPhaseBegin(SUMOTime time, TLColor color);
64 
69  void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow);
70 
75  std::vector<SUMOTime> getTimes(SUMOTime cycleDuration) const;
76 
78  void sortPhases();
79 
83  int getLinkNo() const;
84 
89  bool mayDrive(SUMOTime time) const;
90 
95  bool hasYellow(SUMOTime time) const;
96 
101  bool containsIncoming(NBEdge* from) const;
102 
107  void remapIncoming(NBEdge* which, const EdgeVector& by);
108 
113  bool containsOutgoing(NBEdge* to) const;
114 
119  void remapOutgoing(NBEdge* which, const EdgeVector& by);
120 
125  const NBConnection& getConnection(int pos) const;
126 
131  void patchTYellow(SUMOTime tyellow, bool forced);
132 
139  void remap(NBEdge* removed, int removedLane, NBEdge* by, int byLane);
140 
144  class PhaseDef {
145  public:
150  PhaseDef(SUMOTime time, TLColor color)
151  : myTime(time), myColor(color) { }
152 
157  };
158 
159  private:
163  std::vector<PhaseDef> myPhases;
166  };
167 
168 
169 
171  typedef std::map<std::string, SignalGroup*> SignalGroupCont;
172 
173 
180  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id,
181  const std::vector<NBNode*>& junctions, SUMOTime offset,
182  TrafficLightType type);
183 
184 
191  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, NBNode* junction, SUMOTime offset,
192  TrafficLightType type);
193 
194 
200  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, SUMOTime offset,
201  TrafficLightType type);
202 
203 
205  ~NBLoadedTLDef();
206 
207 
211  void setCycleDuration(SUMOTime cycleDur);
212 
213 
217  void addSignalGroup(const std::string& id);
218 
219 
224  bool addToSignalGroup(const std::string& groupid,
225  const NBConnection& connection);
226 
227 
232  bool addToSignalGroup(const std::string& groupid,
233  const NBConnectionVector& connections);
234 
235 
241  void addSignalGroupPhaseBegin(const std::string& groupid,
242  SUMOTime time, TLColor color);
243 
244 
250  void setSignalYellowTimes(const std::string& groupid,
251  SUMOTime tRedYellow, SUMOTime tYellow);
252 
253 
256 
261  void setTLControllingInformation() const;
262 
263 
270  void remapRemoved(NBEdge* removed,
271  const EdgeVector& incoming, const EdgeVector& outgoing);
272 
273  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
274  void initNeedsContRelation() const;
275 
277  int getMaxIndex();
278 
280 
281 
282 protected:
285 
291  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
292 
297 
298 
302  void collectNodes();
303 
304 
309  void collectLinks();
310 
311 
318  bool mustBrake(const NBConnection& possProhibited,
319  const std::string& state,
320  int strmpos) const;
321 
322 
330  void replaceRemoved(NBEdge* removed, int removedLane,
331  NBEdge* by, int byLane, bool incoming);
333 
334 private:
340  std::string buildPhaseState(const SUMOTime time) const;
341 
342  // pointer to the NBEdgeCont for checking edges
344 
345 
346 private:
349 
352 
353 
354 };
long long int SUMOTime
Definition: GUI.h:35
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
TrafficLightType
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
The representation of a single edge during network building.
Definition: NBEdge.h:92
Definition of a single, loaded phase.
PhaseDef(SUMOTime time, TLColor color)
Constructor.
TLColor myColor
A signal's color from this time.
SUMOTime myTime
The begin time of this phase.
A single signal group, may control several connections.
Definition: NBLoadedTLDef.h:44
void remapOutgoing(NBEdge *which, const EdgeVector &by)
Replaces the given outgoing edge by the others given.
NBConnectionVector myConnections
Connections controlled by this signal.
SignalGroup(const std::string &id)
Constructor.
void addPhaseBegin(SUMOTime time, TLColor color)
Sets the begin of a phase.
void addConnection(const NBConnection &c)
Inserts a controlled connection.
SUMOTime myTRedYellow
The times of redyellow and yellow.
std::vector< SUMOTime > getTimes(SUMOTime cycleDuration) const
Returns the times at which the signal switches.
bool mayDrive(SUMOTime time) const
Returns whether vehicles on controlled links may drive at the given time.
std::vector< PhaseDef > myPhases
The phases of this signal.
void patchTYellow(SUMOTime tyellow, bool forced)
Sets the yellow time.
bool hasYellow(SUMOTime time) const
Returns whether controlled links have yellow at the given time.
const NBConnection & getConnection(int pos) const
Returns the connection at the given index.
void remap(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
bool containsIncoming(NBEdge *from) const
Returns whether this signal controls the given edge.
void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow)
Sets the times for redyellow and yellow.
void sortPhases()
Sorts the phases.
bool containsOutgoing(NBEdge *to) const
Returns whether this signal controls a connection where the given edge is the destination.
void remapIncoming(NBEdge *which, const EdgeVector &by)
Replaces the given incoming edge by the others given.
int getLinkNo() const
Returns the number of links (connection) controlled by this signal.
A loaded (complete) traffic light logic.
Definition: NBLoadedTLDef.h:39
void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
void collectNodes()
Collects the nodes participating in this traffic light.
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane, bool incoming)
Replaces a removed edge/lane.
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
std::string buildPhaseState(const SUMOTime time) const
Builds the phase for a given time.
~NBLoadedTLDef()
Destructor.
void addSignalGroupPhaseBegin(const std::string &groupid, SUMOTime time, TLColor color)
Sets the information about the begin of a phase.
SUMOTime myCycleDuration
The duration of a single cycle.
const NBEdgeCont * myEdgeCont
void setSignalYellowTimes(const std::string &groupid, SUMOTime tRedYellow, SUMOTime tYellow)
Sets the times the light is yellow or red/yellow.
std::map< std::string, SignalGroup * > SignalGroupCont
Definition of the container for signal groups.
NBLoadedTLDef(const NBEdgeCont &ec, const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
void addSignalGroup(const std::string &id)
Adds a signal group.
void setCycleDuration(SUMOTime cycleDur)
Sets the duration of a cycle.
SignalGroupCont mySignalGroups
Controlled signal groups.
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
void collectLinks()
Collects the links participating in this traffic light.
bool mustBrake(const NBConnection &possProhibited, const std::string &state, int strmpos) const
Returns the information whether a connection must brake, given a phase.
void initNeedsContRelation() const
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurrences of the removed edge in incoming/outgoing edges of all definitions.
Represents a single node (junction) during network building.
Definition: NBNode.h:66
The base class for traffic light logic definitions.
TLColor
An enumeration of possible tl-signal states.
A SUMO-compliant built logic for a traffic light.
Base class for objects which have an id.
Definition: Named.h:54