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.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 /****************************************************************************/
16 // A loaded (complete) traffic light logic
17 /****************************************************************************/
18 #ifndef NBLoadedTLDef_h
19 #define NBLoadedTLDef_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <string>
29 #include <set>
31 #include "NBNode.h"
32 #include <utils/common/SUMOTime.h>
33 
34 
35 // ===========================================================================
36 // class definitions
37 // ===========================================================================
43 public:
47  class SignalGroup : public Named {
48  public:
52  SignalGroup(const std::string& id);
53 
55  ~SignalGroup();
56 
60  void addConnection(const NBConnection& c);
61 
66  void addPhaseBegin(SUMOTime time, TLColor color);
67 
72  void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow);
73 
78  std::vector<double> getTimes(SUMOTime cycleDuration) const;
79 
81  void sortPhases();
82 
86  int getLinkNo() const;
87 
92  bool mayDrive(SUMOTime time) const;
93 
98  bool hasYellow(SUMOTime time) const;
99 
105  bool containsConnection(NBEdge* from, NBEdge* to) const;
106 
111  bool containsIncoming(NBEdge* from) const;
112 
117  void remapIncoming(NBEdge* which, const EdgeVector& by);
118 
123  bool containsOutgoing(NBEdge* to) const;
124 
129  void remapOutgoing(NBEdge* which, const EdgeVector& by);
130 
135  const NBConnection& getConnection(int pos) const;
136 
141  void patchTYellow(int tyellow, bool forced);
142 
149  void remap(NBEdge* removed, int removedLane, NBEdge* by, int byLane);
150 
154  class PhaseDef {
155  public:
160  PhaseDef(SUMOTime time, TLColor color)
161  : myTime(time), myColor(color) { }
162 
167  };
168 
173  public:
175  explicit phase_by_time_sorter() { }
176 
181  int operator()(const PhaseDef& p1, const PhaseDef& p2) {
182  return p1.myTime < p2.myTime;
183  }
184  };
185 
186  private:
190  std::vector<PhaseDef> myPhases;
193  };
194 
195 
196 
198  typedef std::map<std::string, SignalGroup*> SignalGroupCont;
199 
200 
207  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id,
208  const std::vector<NBNode*>& junctions, SUMOTime offset,
209  TrafficLightType type);
210 
211 
218  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, NBNode* junction, SUMOTime offset,
219  TrafficLightType type);
220 
221 
227  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, SUMOTime offset,
228  TrafficLightType type);
229 
230 
232  ~NBLoadedTLDef();
233 
234 
240  SignalGroup* findGroup(NBEdge* from, NBEdge* to) const;
241 
242 
246  void setCycleDuration(int cycleDur);
247 
248 
252  void addSignalGroup(const std::string& id);
253 
254 
259  bool addToSignalGroup(const std::string& groupid,
260  const NBConnection& connection);
261 
262 
267  bool addToSignalGroup(const std::string& groupid,
268  const NBConnectionVector& connections);
269 
270 
276  void addSignalGroupPhaseBegin(const std::string& groupid,
277  SUMOTime time, TLColor color);
278 
279 
285  void setSignalYellowTimes(const std::string& groupid,
286  SUMOTime tRedYellow, SUMOTime tYellow);
287 
288 
291 
296  void setTLControllingInformation() const;
297 
298 
305  void remapRemoved(NBEdge* removed,
306  const EdgeVector& incoming, const EdgeVector& outgoing);
307 
308  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
309  void initNeedsContRelation() const;
310 
312  int getMaxIndex();
313 
315 
316 
317 protected:
320 
326  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
327 
332 
333 
337  void collectNodes();
338 
339 
344  void collectLinks();
345 
346 
353  bool mustBrake(const NBConnection& possProhibited,
354  const std::string& state,
355  int strmpos) const;
356 
357 
365  void replaceRemoved(NBEdge* removed, int removedLane,
366  NBEdge* by, int byLane);
368 
369 private:
375  std::string buildPhaseState(int time) const;
376 
377  // pointer to the NBEdgeCont for checking edges
379 
380 
381 private:
383  SignalGroupCont mySignalGroups;
384 
387 
388 
389 };
390 
391 
392 #endif
393 
394 /****************************************************************************/
395 
std::vector< double > getTimes(SUMOTime cycleDuration) const
Returns the times at which the signal switches.
void setSignalYellowTimes(const std::string &groupid, SUMOTime tRedYellow, SUMOTime tYellow)
Sets the times the light is yellow or red/yellow.
long long int SUMOTime
Definition: SUMOTime.h:35
bool containsOutgoing(NBEdge *to) const
Returns whether this signal controls a connection where the given edge is the destination.
A single signal group, may control several connections.
Definition: NBLoadedTLDef.h:47
SignalGroup(const std::string &id)
Constructor.
void addSignalGroupPhaseBegin(const std::string &groupid, SUMOTime time, TLColor color)
Sets the information about the begin of a phase.
A SUMO-compliant built logic for a traffic light.
A loaded (complete) traffic light logic.
Definition: NBLoadedTLDef.h:42
The representation of a single edge during network building.
Definition: NBEdge.h:86
std::string buildPhaseState(int time) const
Builds the phase for a given time.
void sortPhases()
Sorts the phases.
void collectNodes()
Collects the nodes participating in this traffic light.
The base class for traffic light logic definitions.
bool containsConnection(NBEdge *from, NBEdge *to) const
Returns whether the given connection is controlled by this signal.
const NBConnection & getConnection(int pos) const
Returns the connection at the given index.
TLColor
An enumeration of possible tl-signal states.
SUMOTime myTime
The begin time of this phase.
std::map< std::string, SignalGroup * > SignalGroupCont
Definition of the container for signal groups.
Definition of a single, loaded phase.
void remapOutgoing(NBEdge *which, const EdgeVector &by)
Replaces the given outgoing edge by the others given.
void remapIncoming(NBEdge *which, const EdgeVector &by)
Replaces the given incoming edge by the others given.
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
int getLinkNo() const
Returns the number of links (connection) controlled by this signal.
NBLoadedTLDef(const NBEdgeCont &ec, const std::string &id, const std::vector< NBNode *> &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
SignalGroupCont mySignalGroups
Controlled signal groups.
SignalGroup * findGroup(NBEdge *from, NBEdge *to) const
Returns the signal group which is responsible for the given connection.
PhaseDef(SUMOTime time, TLColor color)
Constructor.
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
void setCycleDuration(int cycleDur)
Sets the duration of a cycle.
void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
std::vector< PhaseDef > myPhases
The phases of this signal.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
void remap(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
void collectLinks()
Collects the links participating in this traffic light.
void addConnection(const NBConnection &c)
Inserts a controlled connection.
Base class for objects which have an id.
Definition: Named.h:57
void addPhaseBegin(SUMOTime time, TLColor color)
Sets the begin of a phase.
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow)
Sets the times for redyellow and yellow.
void initNeedsContRelation() const
void patchTYellow(int tyellow, bool forced)
Sets the yellow time.
SUMOTime myTRedYellow
The times of redyellow and yellow.
void addSignalGroup(const std::string &id)
Adds a signal group.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
bool mayDrive(SUMOTime time) const
Returns whether vehicles on controlled links may drive at the given time.
Sorts phases by their begin time.
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
bool containsIncoming(NBEdge *from) const
Returns whether this signal controls the given edge.
int myCycleDuration
The duration of a single cycle.
Represents a single node (junction) during network building.
Definition: NBNode.h:68
bool mustBrake(const NBConnection &possProhibited, const std::string &state, int strmpos) const
Returns the information whether a connection must brake, given a phase.
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
NBConnectionVector myConnections
Connections controlled by this signal.
~NBLoadedTLDef()
Destructor.
TLColor myColor
A signal&#39;s color from this time.
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
const NBEdgeCont * myEdgeCont
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
TrafficLightType
int operator()(const PhaseDef &p1, const PhaseDef &p2)
Sorts phases by their begin time.
bool hasYellow(SUMOTime time) const
Returns whether controlled links have yellow at the given time.