SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2015 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(SUMOTime 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 std::string& id,
215  const std::vector<NBNode*>& junctions, SUMOTime offset,
216  TrafficLightType type);
217 
218 
225  NBLoadedTLDef(const std::string& id, NBNode* junction, SUMOTime offset,
226  TrafficLightType type);
227 
228 
234  NBLoadedTLDef(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 NBEdgeCont& ec) const;
304 
305 
312  void remapRemoved(NBEdge* removed,
313  const EdgeVector& incoming, const EdgeVector& outgoing);
315 
316 
317 protected:
320 
328  unsigned int brakingTime);
329 
330 
334  void collectNodes();
335 
336 
341  void collectLinks();
342 
343 
351  bool mustBrake(const NBEdgeCont& ec,
352  const NBConnection& possProhibited,
353  const std::string& state,
354  unsigned int strmpos) const;
355 
356 
364  void replaceRemoved(NBEdge* removed, int removedLane,
365  NBEdge* by, int byLane);
367 
368 private:
374  std::string buildPhaseState(const NBEdgeCont& ec, unsigned int time) const;
375 
376 
377 private:
379  SignalGroupCont mySignalGroups;
380 
382  unsigned int myCycleDuration;
383 
384 
385 };
386 
387 
388 #endif
389 
390 /****************************************************************************/
391 
SignalGroup * findGroup(NBEdge *from, NBEdge *to) const
Returns the signal group which is responsible for the given connection.
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.
void setTLControllingInformation(const NBEdgeCont &ec) const
Informs edges about being controlled by a tls.
std::string buildPhaseState(const NBEdgeCont &ec, unsigned int time) const
Builds the phase for a given time.
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:71
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.
bool mustBrake(const NBEdgeCont &ec, const NBConnection &possProhibited, const std::string &state, unsigned int strmpos) const
Returns the information whether a connection must brake, given a phase.
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.
SignalGroupCont mySignalGroups
Controlled signal groups.
unsigned int myCycleDuration
The duration of a single cycle.
NBTrafficLightLogic * myCompute(const NBEdgeCont &ec, unsigned int brakingTime)
Computes the traffic light logic finally in dependence to the type.
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 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 std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
void setCycleDuration(unsigned int cycleDur)
Sets the duration of a cycle.
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.
int SUMOTime
Definition: SUMOTime.h:43
Represents a single node (junction) during network building.
Definition: NBNode.h:75
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's color from this time.
void patchTYellow(SUMOTime tyellow, bool forced)
Sets the yellow time.
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
TrafficLightType
int operator()(const PhaseDef &p1, const PhaseDef &p2)
Sorts phases by their begin time.