SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBTrafficLightDefinition.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // The base class for traffic light logic definitions
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2013 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 NBTrafficLightDefinition_h
22 #define NBTrafficLightDefinition_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 <bitset>
37 #include <utility>
38 #include <set>
39 #include <utils/common/Named.h>
41 #include <utils/common/SUMOTime.h>
44 #include "NBCont.h"
45 #include "NBConnection.h"
46 #include "NBConnectionDefs.h"
48 
49 
50 // ===========================================================================
51 // class declarations
52 // ===========================================================================
53 class NBNode;
54 class OptionsCont;
56 
57 
58 // ===========================================================================
59 // class definitions
60 // ===========================================================================
74 public:
75 
76  static const std::string DefaultProgramID;
77 
82  enum TLColor {
93  };
94 
95 
103  NBTrafficLightDefinition(const std::string& id,
104  const std::vector<NBNode*>& junctions,
105  const std::string& programID,
106  SUMOTime offset,
107  TrafficLightType type);
108 
109 
117  NBTrafficLightDefinition(const std::string& id,
118  NBNode* junction,
119  const std::string& programID,
120  SUMOTime offset,
121  TrafficLightType type);
122 
123 
130  NBTrafficLightDefinition(const std::string& id, const std::string& programID,
131  SUMOTime offset,
132  TrafficLightType type);
133 
134 
136  virtual ~NBTrafficLightDefinition();
137 
138 
149 
150 
151 
154 
158  virtual void addNode(NBNode* node);
159 
160 
164  virtual void removeNode(NBNode* node);
165 
166 
170  const std::vector<NBNode*>& getNodes() const {
171  return myControlledNodes;
172  }
174 
175 
186  bool mustBrake(const NBEdge* const from, const NBEdge* const to) const;
187 
188 
196  bool mustBrake(const NBConnection& possProhibited,
197  const NBConnection& possProhibitor,
198  bool regardNonSignalisedLowerPriority) const;
199 
209  bool mustBrake(const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
210  const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
211  bool regardNonSignalisedLowerPriority) const;
212 
213 
223  bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
224  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
225  bool regardNonSignalisedLowerPriority) const;
226 
227 
235  bool foes(const NBEdge* const from1, const NBEdge* const to1,
236  const NBEdge* const from2, const NBEdge* const to2) const;
237 
238 
242  virtual void setTLControllingInformation(const NBEdgeCont& ec) const = 0;
243 
244 
247  virtual void setParticipantsInformation();
248 
249 
253  void addControlledInnerEdges(const std::vector<std::string>& edges);
254 
255 
261  virtual void remapRemoved(NBEdge* removed,
262  const EdgeVector& incoming, const EdgeVector& outgoing) = 0;
263 
264 
271  virtual void replaceRemoved(NBEdge* removed, int removedLane,
272  NBEdge* by, int byLane) = 0;
273 
274 
280  bool isLeftMover(const NBEdge* const from, const NBEdge* const to) const;
281 
282 
286  const EdgeVector& getIncomingEdges() const;
287 
288 
291  return myControlledLinks;
292  }
293 
294 
295  // @breif returns the controlled nodes
296  const std::vector<NBNode*>& getControlledNodes() const {
297  return myControlledNodes;
298  }
299 
300 
304  const std::string& getProgramID() const {
305  return mySubID;
306  };
307 
308 
312  void setProgramID(const std::string& programID) {
313  mySubID = programID;
314  }
315 
316 
321  return myOffset;
322  }
323 
324 
327  return myType;
328  }
329 
330 protected:
336  virtual NBTrafficLightLogic* myCompute(const NBEdgeCont& ec,
337  unsigned int brakingTime) = 0;
338 
339 
343  virtual void collectLinks() = 0;
344 
345 
348  void collectEdges();
349 
350 
356  unsigned int computeBrakingTime(SUMOReal minDecel) const;
357 
358 
359  // @return whether this traffic light is invalid and should be computed
360  virtual bool amInvalid() const;
361 
363  void collectAllLinks();
364 
365 
366 protected:
368  std::vector<NBNode*> myControlledNodes;
369 
372 
375 
378 
380  std::set<std::string> myControlledInnerEdges;
381 
383  std::string mySubID;
384 
387 
390 
391 
392 };
393 
394 
395 #endif
396 
397 /****************************************************************************/
398 
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
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
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.
const std::vector< NBNode * > & getControlledNodes() const
SUMOTime myOffset
The offset in the program.
virtual void collectLinks()=0
Collects the links participating in this traffic light If a link could not be found.
SUMOTime getOffset()
Returns the offset.
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)
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 edges not 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:46
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.
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:38
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:74
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 &quot;prohibited&quot; flow must let &quot;prohibitor&quot; flow pass.
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:215
bool isLeftMover(const NBEdge *const from, const NBEdge *const to) const
returns the information whether the given link is a left-mover
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&#39;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.