SUMO - Simulation of Urban MObility
NBTrafficLightDefinition.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // The base class for traffic light logic definitions
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2002-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef NBTrafficLightDefinition_h
23 #define NBTrafficLightDefinition_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
36 #include <string>
37 #include <bitset>
38 #include <utility>
39 #include <set>
40 #include <utils/common/StdDefs.h>
41 #include <utils/common/Named.h>
43 #include <utils/common/SUMOTime.h>
46 #include "NBCont.h"
47 #include "NBConnection.h"
48 #include "NBConnectionDefs.h"
50 
51 
52 // ===========================================================================
53 // class declarations
54 // ===========================================================================
55 class NBNode;
56 class OptionsCont;
58 
59 
60 // ===========================================================================
61 // class definitions
62 // ===========================================================================
76 public:
77 
79  static const std::string DefaultProgramID;
80 
85  enum TLColor {
96  };
97 
98 
106  NBTrafficLightDefinition(const std::string& id,
107  const std::vector<NBNode*>& junctions,
108  const std::string& programID,
109  SUMOTime offset,
110  TrafficLightType type);
111 
112 
120  NBTrafficLightDefinition(const std::string& id,
121  NBNode* junction,
122  const std::string& programID,
123  SUMOTime offset,
124  TrafficLightType type);
125 
126 
133  NBTrafficLightDefinition(const std::string& id, const std::string& programID,
134  SUMOTime offset,
135  TrafficLightType type);
136 
137 
139  virtual ~NBTrafficLightDefinition();
140 
141 
151 
152 
153 
156 
160  virtual void addNode(NBNode* node);
161 
162 
166  virtual void removeNode(NBNode* node);
167 
172  virtual void removeConnection(const NBConnection& conn, bool reconstruct = true) {
173  UNUSED_PARAMETER(conn);
174  UNUSED_PARAMETER(reconstruct);
175  }
176 
180  const std::vector<NBNode*>& getNodes() const {
181  return myControlledNodes;
182  }
184 
185 
196  bool mustBrake(const NBEdge* const from, const NBEdge* const to) const;
197 
198 
206  bool mustBrake(const NBConnection& possProhibited,
207  const NBConnection& possProhibitor,
208  bool regardNonSignalisedLowerPriority) const;
209 
219  bool mustBrake(const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
220  const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
221  bool regardNonSignalisedLowerPriority) const;
222 
223 
234  bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
235  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
236  bool regardNonSignalisedLowerPriority,
237  bool sameNodeOnly = false) const;
238 
239 
247  bool foes(const NBEdge* const from1, const NBEdge* const to1,
248  const NBEdge* const from2, const NBEdge* const to2) const;
249 
250 
253  virtual void setTLControllingInformation() const = 0;
254 
255 
258  virtual void setParticipantsInformation();
259 
260 
264  void addControlledInnerEdges(const std::vector<std::string>& edges);
265 
268  std::vector<std::string> getControlledInnerEdges() const;
269 
275  virtual void remapRemoved(NBEdge* removed,
276  const EdgeVector& incoming, const EdgeVector& outgoing) = 0;
277 
278 
285  virtual void replaceRemoved(NBEdge* removed, int removedLane,
286  NBEdge* by, int byLane) = 0;
287 
289  virtual void shiftTLConnectionLaneIndex(NBEdge* edge, int offset) {
290  UNUSED_PARAMETER(edge);
291  UNUSED_PARAMETER(offset);
292  }
293 
297  const EdgeVector& getIncomingEdges() const;
298 
299 
302  return myControlledLinks;
303  }
304 
305 
308  return myControlledLinks;
309  }
310 
311 
315  const std::string& getProgramID() const {
316  return mySubID;
317  };
318 
319 
323  void setProgramID(const std::string& programID) {
324  mySubID = programID;
325  }
326 
327 
332  return myOffset;
333  }
334 
335 
338  return myType;
339  }
340 
342  virtual void setType(TrafficLightType type) {
343  myType = type;
344  }
345 
346  /* @brief computes whether the given stream may have green minor while the
347  * other stream has green major in the same phase
348  */
349  bool needsCont(const NBEdge* fromE, const NBEdge* toE, const NBEdge* otherFromE, const NBEdge* otherToE) const;
350 
352  virtual bool rightOnRedConflict(int index, int foeIndex) const;
353 
354  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true
355  * This information is a byproduct of NBOwnTLDef::myCompute. All other
356  * subclasses instantiate a private instance of NBOwnTLDef to answer this query */
357  virtual void initNeedsContRelation() const;
358 
359 protected:
361  static const std::string DummyID;
362 
367  virtual NBTrafficLightLogic* myCompute(int brakingTime) = 0;
368 
369 
373  virtual void collectLinks() = 0;
374 
375 
378  virtual void collectEdges();
379 
380 
386  int computeBrakingTime(double minDecel) const;
387 
388 
389  // @return whether this traffic light is invalid and should be computed
390  virtual bool amInvalid() const;
391 
393  void collectAllLinks();
394 
395 protected:
397  std::vector<NBNode*> myControlledNodes;
398 
401 
404 
407 
409  std::set<std::string> myControlledInnerEdges;
410 
412  std::string mySubID;
413 
416 
419 
421  struct StreamPair {
422  StreamPair(const NBEdge* _from1, const NBEdge* _to1, const NBEdge* _from2, const NBEdge* _to2):
423  from1(_from1),
424  to1(_to1),
425  from2(_from2),
426  to2(_to2) {}
427 
428  bool operator==(const StreamPair& o) const {
429  return (from1 == o.from1 && to1 == o.to1
430  && from2 == o.from2 && to2 == o.to2);
431  }
432 
433  bool operator<(const StreamPair& o) const {
434  if (from1 != o.from1) {
435  return from1 < o.from1;
436  }
437  if (to1 != o.to1) {
438  return to1 < o.to1;
439  }
440  if (from2 != o.from2) {
441  return from2 < o.from2;
442  }
443  return to2 < o.to2;
444  }
445 
446  const NBEdge* from1;
447  const NBEdge* to1;
448  const NBEdge* from2;
449  const NBEdge* to2;
450  };
451  typedef std::set<StreamPair> NeedsContRelation;
452  mutable NeedsContRelation myNeedsContRelation;
454 
455  typedef std::set<std::pair<int, int> > RightOnRedConflicts;
456  mutable RightOnRedConflicts myRightOnRedConflicts;
458 
459 private:
460  static std::set<NBEdge*> collectReachable(EdgeVector outer, const EdgeVector& within, bool checkControlled);
461 
462 
463 };
464 
465 
466 #endif
467 
468 /****************************************************************************/
469 
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
StreamPair(const NBEdge *_from1, const NBEdge *_to1, const NBEdge *_from2, const NBEdge *_to2)
TrafficLightType myType
The algorithm type for the traffic light.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
virtual void removeConnection(const NBConnection &conn, bool reconstruct=true)
removes the given connection from the traffic light if recontruct=true, reconstructs the logic and in...
void collectAllLinks()
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
static const std::string DummyID
id for temporary definitions
RightOnRedConflicts myRightOnRedConflicts
std::vector< std::string > getControlledInnerEdges() const
Retrieve the ids of edges explicitly controlled by the tls.
A SUMO-compliant built logic for a traffic light.
TrafficLightType getType() const
get the algorithm type (static etc..)
virtual void setTLControllingInformation() const =0
Informs edges about being controlled by a tls.
EdgeVector myIncomingEdges
The list of incoming edges.
virtual ~NBTrafficLightDefinition()
Destructor.
const std::string & getProgramID() const
Returns the ProgramID.
The representation of a single edge during network building.
Definition: NBEdge.h:71
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
The base class for traffic light logic definitions.
virtual void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)=0
Replaces a removed edge/lane.
static const SUMOTime UNSPECIFIED_DURATION
std::set< std::pair< int, int > > RightOnRedConflicts
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
TLColor
An enumeration of possible tl-signal states.
SUMOTime myOffset
The offset in the program.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:40
NBConnectionVector & getControlledLinks()
returns the controlled links (non const version)
virtual void collectLinks()=0
Collects the links participating in this traffic light If a link could not be found.
std::set< StreamPair > NeedsContRelation
bool operator==(const StreamPair &o) const
SUMOTime getOffset()
Returns the offset.
virtual void collectEdges()
Build the list of participating edges.
int computeBrakingTime(double minDecel) const
Computes the time vehicles may need to brake.
std::set< std::string > myControlledInnerEdges
Set of inner edges that shall be controlled, though.
virtual void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)=0
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
const NBConnectionVector & getControlledLinks() const
returns the controlled links (depends on previous call to collectLinks)
virtual void shiftTLConnectionLaneIndex(NBEdge *edge, int offset)
patches (loaded) signal plans by modifying lane indices
virtual NBTrafficLightLogic * myCompute(int brakingTime)=0
Computes the traffic light logic finally in dependence to the type.
static const std::string DefaultProgramID
void setProgramID(const std::string &programID)
Sets the programID.
void addControlledInnerEdges(const std::vector< std::string > &edges)
Adds the given ids into the list of inner edges controlled by the tls.
bool mustBrake(const NBEdge *const from, const NBEdge *const to) const
Returns the information whether the described flow must let any other flow pass.
An upper class for objects with additional parameters.
Definition: Parameterised.h:51
const std::vector< NBNode * > & getNodes() const
Returns the list of controlled nodes.
virtual void removeNode(NBNode *node)
Removes the given node from the list of controlled nodes.
Base class for objects which have an id.
Definition: Named.h:46
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority, bool sameNodeOnly=false) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
bool needsCont(const NBEdge *fromE, const NBEdge *toE, const NBEdge *otherFromE, const NBEdge *otherToE) const
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:41
A storage for options typed value containers)
Definition: OptionsCont.h:99
Represents a single node (junction) during network building.
Definition: NBNode.h:75
bool operator<(const StreamPair &o) const
long long int SUMOTime
Definition: TraCIDefs.h:52
data structure for caching needsCont information
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
NBTrafficLightDefinition(const std::string &id, const std::vector< NBNode * > &junctions, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
static std::set< NBEdge * > collectReachable(EdgeVector outer, const EdgeVector &within, bool checkControlled)
NBConnectionVector myControlledLinks
The list of controlled links.
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
virtual void setType(TrafficLightType type)
set the algorithm type (static etc..)
std::string mySubID
The tls program&#39;s subid.
virtual bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light ...
TrafficLightType
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
virtual void initNeedsContRelation() const