SUMO - Simulation of Urban MObility
NBLoadedTLDef.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // A loaded (complete) traffic light logic
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef NBLoadedTLDef_h
22 #define NBLoadedTLDef_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <string>
36 #include <set>
38 #include "NBNode.h"
39 #include <utils/common/SUMOTime.h>
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
50 public:
54  class SignalGroup : public Named {
55  public:
59  SignalGroup(const std::string& id);
60 
62  ~SignalGroup();
63 
67  void addConnection(const NBConnection& c);
68 
73  void addPhaseBegin(SUMOTime time, TLColor color);
74 
79  void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow);
80 
85  std::vector<SUMOReal> getTimes(SUMOTime cycleDuration) const;
86 
88  void sortPhases();
89 
93  unsigned int getLinkNo() const;
94 
99  bool mayDrive(SUMOTime time) const;
100 
105  bool hasYellow(SUMOTime time) const;
106 
112  bool containsConnection(NBEdge* from, NBEdge* to) const;
113 
118  bool containsIncoming(NBEdge* from) const;
119 
124  void remapIncoming(NBEdge* which, const EdgeVector& by);
125 
130  bool containsOutgoing(NBEdge* to) const;
131 
136  void remapOutgoing(NBEdge* which, const EdgeVector& by);
137 
142  const NBConnection& getConnection(unsigned int pos) const;
143 
148  void patchTYellow(unsigned int tyellow, bool forced);
149 
156  void remap(NBEdge* removed, int removedLane, NBEdge* by, int byLane);
157 
161  class PhaseDef {
162  public:
167  PhaseDef(SUMOTime time, TLColor color)
168  : myTime(time), myColor(color) { }
169 
174  };
175 
180  public:
182  explicit phase_by_time_sorter() { }
183 
188  int operator()(const PhaseDef& p1, const PhaseDef& p2) {
189  return p1.myTime < p2.myTime;
190  }
191  };
192 
193  private:
197  std::vector<PhaseDef> myPhases;
200  };
201 
202 
203 
205  typedef std::map<std::string, SignalGroup*> SignalGroupCont;
206 
207 
214  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id,
215  const std::vector<NBNode*>& junctions, SUMOTime offset,
216  TrafficLightType type);
217 
218 
225  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, NBNode* junction, SUMOTime offset,
226  TrafficLightType type);
227 
228 
234  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, SUMOTime offset,
235  TrafficLightType type);
236 
237 
239  ~NBLoadedTLDef();
240 
241 
247  SignalGroup* findGroup(NBEdge* from, NBEdge* to) const;
248 
249 
253  void setCycleDuration(unsigned int cycleDur);
254 
255 
259  void addSignalGroup(const std::string& id);
260 
261 
266  bool addToSignalGroup(const std::string& groupid,
267  const NBConnection& connection);
268 
269 
274  bool addToSignalGroup(const std::string& groupid,
275  const NBConnectionVector& connections);
276 
277 
283  void addSignalGroupPhaseBegin(const std::string& groupid,
284  SUMOTime time, TLColor color);
285 
286 
292  void setSignalYellowTimes(const std::string& groupid,
293  SUMOTime tRedYellow, SUMOTime tYellow);
294 
295 
298 
303  void setTLControllingInformation() const;
304 
305 
312  void remapRemoved(NBEdge* removed,
313  const EdgeVector& incoming, const EdgeVector& outgoing);
314 
315  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
316  void initNeedsContRelation() const;
318 
319 
320 protected:
323 
329  NBTrafficLightLogic* myCompute(unsigned int brakingTimeSeconds);
330 
331 
335  void collectNodes();
336 
337 
342  void collectLinks();
343 
344 
351  bool mustBrake(const NBConnection& possProhibited,
352  const std::string& state,
353  unsigned int strmpos) const;
354 
355 
363  void replaceRemoved(NBEdge* removed, int removedLane,
364  NBEdge* by, int byLane);
366 
367 private:
373  std::string buildPhaseState(unsigned int time) const;
374 
375  // pointer to the NBEdgeCont for checking edges
377 
378 
379 private:
381  SignalGroupCont mySignalGroups;
382 
384  unsigned int myCycleDuration;
385 
386 
387 };
388 
389 
390 #endif
391 
392 /****************************************************************************/
393 
SignalGroup * findGroup(NBEdge *from, NBEdge *to) const
Returns the signal group which is responsible for the given connection.
bool mustBrake(const NBConnection &possProhibited, const std::string &state, unsigned int strmpos) const
Returns the information whether a connection must brake, given a phase.
bool mayDrive(SUMOTime time) const
Returns whether vehicles on controlled links may drive at the given time.
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:43
void initNeedsContRelation() const
A single signal group, may control several connections.
Definition: NBLoadedTLDef.h:54
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:49
The representation of a single edge during network building.
Definition: NBEdge.h:70
void sortPhases()
Sorts the phases.
void collectNodes()
Collects the nodes participating in this traffic light.
bool containsOutgoing(NBEdge *to) const
Returns whether this signal controls a connection where the given edge is the destination.
The base class for traffic light logic definitions.
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.
std::string buildPhaseState(unsigned int time) const
Builds the phase for a given time.
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.
NBTrafficLightLogic * myCompute(unsigned int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
SignalGroupCont mySignalGroups
Controlled signal groups.
unsigned int myCycleDuration
The duration of a single cycle.
PhaseDef(SUMOTime time, TLColor color)
Constructor.
std::vector< PhaseDef > myPhases
The phases of this signal.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
bool containsConnection(NBEdge *from, NBEdge *to) const
Returns whether the given connection is controlled by this signal.
void remap(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
void patchTYellow(unsigned int tyellow, bool forced)
Sets the yellow time.
void collectLinks()
Collects the links participating in this traffic light If a link could not be found.
void addConnection(const NBConnection &c)
Inserts a controlled connection.
std::vector< SUMOReal > getTimes(SUMOTime cycleDuration) const
Returns the times at which the signal switches.
Base class for objects which have an id.
Definition: Named.h:45
void addPhaseBegin(SUMOTime time, TLColor color)
Sets the begin of a phase.
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
bool hasYellow(SUMOTime time) const
Returns whether controlled links have yellow at the given time.
void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow)
Sets the times for redyellow and yellow.
NBLoadedTLDef(const NBEdgeCont &ec, const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
void setCycleDuration(unsigned int cycleDur)
Sets the duration of a cycle.
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
SUMOTime myTRedYellow
The times of redyellow and yellow.
void addSignalGroup(const std::string &id)
Adds a signal group.
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
Sorts phases by their begin time.
unsigned int getLinkNo() const
Returns the number of links (connection) controlled by this signal.
Represents a single node (junction) during network building.
Definition: NBNode.h:74
const NBConnection & getConnection(unsigned int pos) const
Returns the connection at the given index.
bool containsIncoming(NBEdge *from) const
Returns whether this signal controls the given edge.
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
TrafficLightType
int operator()(const PhaseDef &p1, const PhaseDef &p2)
Sorts phases by their begin time.