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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // A loaded (complete) traffic light logic
19 /****************************************************************************/
20 #ifndef NBLoadedTLDef_h
21 #define NBLoadedTLDef_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <vector>
34 #include <string>
35 #include <set>
37 #include "NBNode.h"
38 #include <utils/common/SUMOTime.h>
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
49 public:
53  class SignalGroup : public Named {
54  public:
58  SignalGroup(const std::string& id);
59 
61  ~SignalGroup();
62 
66  void addConnection(const NBConnection& c);
67 
72  void addPhaseBegin(SUMOTime time, TLColor color);
73 
78  void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow);
79 
84  std::vector<double> getTimes(SUMOTime cycleDuration) const;
85 
87  void sortPhases();
88 
92  int getLinkNo() const;
93 
98  bool mayDrive(SUMOTime time) const;
99 
104  bool hasYellow(SUMOTime time) const;
105 
111  bool containsConnection(NBEdge* from, NBEdge* to) const;
112 
117  bool containsIncoming(NBEdge* from) const;
118 
123  void remapIncoming(NBEdge* which, const EdgeVector& by);
124 
129  bool containsOutgoing(NBEdge* to) const;
130 
135  void remapOutgoing(NBEdge* which, const EdgeVector& by);
136 
141  const NBConnection& getConnection(int pos) const;
142 
147  void patchTYellow(int tyellow, bool forced);
148 
155  void remap(NBEdge* removed, int removedLane, NBEdge* by, int byLane);
156 
160  class PhaseDef {
161  public:
166  PhaseDef(SUMOTime time, TLColor color)
167  : myTime(time), myColor(color) { }
168 
173  };
174 
179  public:
181  explicit phase_by_time_sorter() { }
182 
187  int operator()(const PhaseDef& p1, const PhaseDef& p2) {
188  return p1.myTime < p2.myTime;
189  }
190  };
191 
192  private:
196  std::vector<PhaseDef> myPhases;
199  };
200 
201 
202 
204  typedef std::map<std::string, SignalGroup*> SignalGroupCont;
205 
206 
213  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id,
214  const std::vector<NBNode*>& junctions, SUMOTime offset,
215  TrafficLightType type);
216 
217 
224  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, NBNode* junction, SUMOTime offset,
225  TrafficLightType type);
226 
227 
233  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, SUMOTime offset,
234  TrafficLightType type);
235 
236 
238  ~NBLoadedTLDef();
239 
240 
246  SignalGroup* findGroup(NBEdge* from, NBEdge* to) const;
247 
248 
252  void setCycleDuration(int cycleDur);
253 
254 
258  void addSignalGroup(const std::string& id);
259 
260 
265  bool addToSignalGroup(const std::string& groupid,
266  const NBConnection& connection);
267 
268 
273  bool addToSignalGroup(const std::string& groupid,
274  const NBConnectionVector& connections);
275 
276 
282  void addSignalGroupPhaseBegin(const std::string& groupid,
283  SUMOTime time, TLColor color);
284 
285 
291  void setSignalYellowTimes(const std::string& groupid,
292  SUMOTime tRedYellow, SUMOTime tYellow);
293 
294 
297 
302  void setTLControllingInformation() const;
303 
304 
311  void remapRemoved(NBEdge* removed,
312  const EdgeVector& incoming, const EdgeVector& outgoing);
313 
314  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
315  void initNeedsContRelation() const;
317 
318 
319 protected:
322 
328  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
329 
334 
335 
339  void collectNodes();
340 
341 
346  void collectLinks();
347 
348 
355  bool mustBrake(const NBConnection& possProhibited,
356  const std::string& state,
357  int strmpos) const;
358 
359 
367  void replaceRemoved(NBEdge* removed, int removedLane,
368  NBEdge* by, int byLane);
370 
371 private:
377  std::string buildPhaseState(int time) const;
378 
379  // pointer to the NBEdgeCont for checking edges
381 
382 
383 private:
385  SignalGroupCont mySignalGroups;
386 
389 
390 
391 };
392 
393 
394 #endif
395 
396 /****************************************************************************/
397 
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.
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:53
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:48
The representation of a single edge during network building.
Definition: NBEdge.h:70
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:66
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:54
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:40
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:74
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.
long long int SUMOTime
Definition: TraCIDefs.h:51
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.
bool hasYellow(SUMOTime time) const
Returns whether controlled links have yellow at the given time.