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>
43 #include "NBCont.h"
44 #include "NBConnection.h"
45 #include "NBConnectionDefs.h"
47 
48 
49 // ===========================================================================
50 // class declarations
51 // ===========================================================================
52 class NBNode;
53 class OptionsCont;
55 
56 
57 // ===========================================================================
58 // class definitions
59 // ===========================================================================
73 public:
74 
75  static const std::string DefaultProgramID;
76 
81  enum TLColor {
92  };
93 
94 
102  NBTrafficLightDefinition(const std::string& id,
103  const std::vector<NBNode*>& junctions,
104  const std::string& programID,
105  SUMOTime offset,
106  TrafficLightType type);
107 
108 
116  NBTrafficLightDefinition(const std::string& id,
117  NBNode* junction,
118  const std::string& programID,
119  SUMOTime offset,
120  TrafficLightType type);
121 
122 
129  NBTrafficLightDefinition(const std::string& id, const std::string& programID,
130  SUMOTime offset,
131  TrafficLightType type);
132 
133 
135  virtual ~NBTrafficLightDefinition();
136 
137 
148 
149 
150 
153 
157  virtual void addNode(NBNode* node);
158 
159 
163  virtual void removeNode(NBNode* node);
164 
165 
169  const std::vector<NBNode*>& getNodes() const {
170  return myControlledNodes;
171  }
173 
174 
185  bool mustBrake(const NBEdge* const from, const NBEdge* const to) const;
186 
187 
195  bool mustBrake(const NBConnection& possProhibited,
196  const NBConnection& possProhibitor,
197  bool regardNonSignalisedLowerPriority) const;
198 
208  bool mustBrake(const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
209  const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
210  bool regardNonSignalisedLowerPriority) const;
211 
212 
222  bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
223  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
224  bool regardNonSignalisedLowerPriority) const;
225 
226 
234  bool foes(const NBEdge* const from1, const NBEdge* const to1,
235  const NBEdge* const from2, const NBEdge* const to2) const;
236 
237 
241  virtual void setTLControllingInformation(const NBEdgeCont& ec) const = 0;
242 
243 
246  virtual void setParticipantsInformation();
247 
248 
252  void addControlledInnerEdges(const std::vector<std::string>& edges);
253 
254 
260  virtual void remapRemoved(NBEdge* removed,
261  const EdgeVector& incoming, const EdgeVector& outgoing) = 0;
262 
263 
270  virtual void replaceRemoved(NBEdge* removed, int removedLane,
271  NBEdge* by, int byLane) = 0;
272 
273 
279  bool isLeftMover(const NBEdge* const from, const NBEdge* const to) const;
280 
281 
285  const EdgeVector& getIncomingEdges() const;
286 
287 
290  return myControlledLinks;
291  }
292 
293 
294  // @breif returns the controlled nodes
295  const std::vector<NBNode*>& getControlledNodes() const {
296  return myControlledNodes;
297  }
298 
299 
303  const std::string& getProgramID() const {
304  return mySubID;
305  };
306 
307 
311  void setProgramID(const std::string& programID) {
312  mySubID = programID;
313  }
314 
315 
320  return myOffset;
321  }
322 
323 
326  return myType;
327  }
328 
329 protected:
335  virtual NBTrafficLightLogic* myCompute(const NBEdgeCont& ec,
336  unsigned int brakingTime) = 0;
337 
338 
342  virtual void collectLinks() = 0;
343 
344 
347  void collectEdges();
348 
349 
355  unsigned int computeBrakingTime(SUMOReal minDecel) const;
356 
357 
358  // @return whether this traffic light is invalid and should be computed
359  virtual bool amInvalid() const;
360 
362  void collectAllLinks();
363 
364 
365 protected:
367  std::vector<NBNode*> myControlledNodes;
368 
371 
374 
377 
379  std::set<std::string> myControlledInnerEdges;
380 
382  std::string mySubID;
383 
386 
389 };
390 
391 
392 #endif
393 
394 /****************************************************************************/
395 
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.
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:221
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.