SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2015 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 
78  static const std::string DefaultProgramID;
79 
84  enum TLColor {
95  };
96 
97 
105  NBTrafficLightDefinition(const std::string& id,
106  const std::vector<NBNode*>& junctions,
107  const std::string& programID,
108  SUMOTime offset,
109  TrafficLightType type);
110 
111 
119  NBTrafficLightDefinition(const std::string& id,
120  NBNode* junction,
121  const std::string& programID,
122  SUMOTime offset,
123  TrafficLightType type);
124 
125 
132  NBTrafficLightDefinition(const std::string& id, const std::string& programID,
133  SUMOTime offset,
134  TrafficLightType type);
135 
136 
138  virtual ~NBTrafficLightDefinition();
139 
140 
151 
152 
153 
156 
160  virtual void addNode(NBNode* node);
161 
162 
166  virtual void removeNode(NBNode* node);
167 
168 
172  const std::vector<NBNode*>& getNodes() const {
173  return myControlledNodes;
174  }
176 
177 
188  bool mustBrake(const NBEdge* const from, const NBEdge* const to) const;
189 
190 
198  bool mustBrake(const NBConnection& possProhibited,
199  const NBConnection& possProhibitor,
200  bool regardNonSignalisedLowerPriority) const;
201 
211  bool mustBrake(const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
212  const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
213  bool regardNonSignalisedLowerPriority) const;
214 
215 
225  bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
226  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
227  bool regardNonSignalisedLowerPriority) const;
228 
229 
237  bool foes(const NBEdge* const from1, const NBEdge* const to1,
238  const NBEdge* const from2, const NBEdge* const to2) const;
239 
240 
244  virtual void setTLControllingInformation(const NBEdgeCont& ec) const = 0;
245 
246 
249  virtual void setParticipantsInformation();
250 
251 
255  void addControlledInnerEdges(const std::vector<std::string>& edges);
256 
259  std::vector<std::string> getControlledInnerEdges() const;
260 
266  virtual void remapRemoved(NBEdge* removed,
267  const EdgeVector& incoming, const EdgeVector& outgoing) = 0;
268 
269 
276  virtual void replaceRemoved(NBEdge* removed, int removedLane,
277  NBEdge* by, int byLane) = 0;
278 
280  virtual void shiftTLConnectionLaneIndex(NBEdge* edge, int offset) {
281  UNUSED_PARAMETER(edge);
282  UNUSED_PARAMETER(offset);
283  }
284 
288  const EdgeVector& getIncomingEdges() const;
289 
290 
293  return myControlledLinks;
294  }
295 
296 
300  const std::string& getProgramID() const {
301  return mySubID;
302  };
303 
304 
308  void setProgramID(const std::string& programID) {
309  mySubID = programID;
310  }
311 
312 
317  return myOffset;
318  }
319 
320 
323  return myType;
324  }
325 
326  /* @brief computes whether the given stream may have green minor while the
327  * other stream has green major in the same phase
328  */
329  bool needsCont(const NBEdge* fromE, const NBEdge* toE, const NBEdge* otherFromE, const NBEdge* otherToE) const;
330 
331  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true
332  * This information is a byproduct of NBOwnTLDef::myCompute. All other
333  * subclasses instantiate a private instance of NBOwnTLDef to answer this query */
334  virtual void initNeedsContRelation() const;
335 
336 protected:
342  virtual NBTrafficLightLogic* myCompute(const NBEdgeCont& ec,
343  unsigned int brakingTime) = 0;
344 
345 
349  virtual void collectLinks() = 0;
350 
351 
354  virtual void collectEdges();
355 
356 
362  unsigned int computeBrakingTime(SUMOReal minDecel) const;
363 
364 
365  // @return whether this traffic light is invalid and should be computed
366  virtual bool amInvalid() const;
367 
369  void collectAllLinks();
370 
371 protected:
373  std::vector<NBNode*> myControlledNodes;
374 
377 
380 
383 
385  std::set<std::string> myControlledInnerEdges;
386 
388  std::string mySubID;
389 
392 
395 
397  struct StreamPair {
398  StreamPair(const NBEdge* _from1, const NBEdge* _to1, const NBEdge* _from2, const NBEdge* _to2):
399  from1(_from1),
400  to1(_to1),
401  from2(_from2),
402  to2(_to2) {}
403 
404  bool operator==(const StreamPair& o) const {
405  return (from1 == o.from1 && to1 == o.to1
406  && from2 == o.from2 && to2 == o.to2);
407  }
408 
409  bool operator<(const StreamPair& o) const {
410  if (from1 != o.from1) {
411  return from1 < o.from1;
412  }
413  if (to1 != o.to1) {
414  return to1 < o.to1;
415  }
416  if (from2 != o.from2) {
417  return from2 < o.from2;
418  }
419  return to2 < o.to2;
420  }
421 
422  const NBEdge* from1;
423  const NBEdge* to1;
424  const NBEdge* from2;
425  const NBEdge* to2;
426  };
427  typedef std::set<StreamPair> NeedsContRelation;
428  mutable NeedsContRelation myNeedsContRelation;
430 
431 
432 };
433 
434 
435 #endif
436 
437 /****************************************************************************/
438 
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.
void collectAllLinks()
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
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..)
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
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.
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:39
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.
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.
NBTrafficLightLogic * compute(const NBEdgeCont &ec, OptionsCont &oc)
Computes the traffic light logic.
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
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
static const std::string DefaultProgramID
unsigned int computeBrakingTime(SUMOReal minDecel) const
Computes the time vehicles may need to brake.
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:47
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:45
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
bool needsCont(const NBEdge *fromE, const NBEdge *toE, const NBEdge *otherFromE, const NBEdge *otherToE) const
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
A storage for options typed value containers)
Definition: OptionsCont.h:108
int SUMOTime
Definition: SUMOTime.h:43
Represents a single node (junction) during network building.
Definition: NBNode.h:75
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
bool operator<(const StreamPair &o) const
virtual NBTrafficLightLogic * myCompute(const NBEdgeCont &ec, unsigned int brakingTime)=0
Computes the traffic light logic finally in dependence to the type.
#define SUMOReal
Definition: config.h:218
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.
NBConnectionVector myControlledLinks
The list of controlled links.
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
virtual void setTLControllingInformation(const NBEdgeCont &ec) const =0
Informs edges about being controlled by a tls.
std::string mySubID
The tls program's subid.
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