SUMO - Simulation of Urban MObility
NBLoadedSUMOTLDef.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2011-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 complete traffic light logic loaded from a sumo-net. (opted to reimplement
19 // since NBLoadedTLDef is quite vissim specific)
20 /****************************************************************************/
21 #ifndef NBLoadedSUMOTLDef_h
22 #define NBLoadedSUMOTLDef_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 <set>
37 #include "NBNode.h"
38 #include "NBEdgeCont.h"
40 #include "NBTrafficLightLogic.h"
41 #include <utils/common/SUMOTime.h>
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
52 public:
53 
60  NBLoadedSUMOTLDef(const std::string& id, const std::string& programID, SUMOTime offset, TrafficLightType type);
61 
67 
68 
71 
74  void setTLControllingInformation() const;
75 
81  void remapRemoved(NBEdge* removed,
82  const EdgeVector& incoming, const EdgeVector& outgoing);
83 
84 
91  void replaceRemoved(NBEdge* removed, int removedLane,
92  NBEdge* by, int byLane);
93 
95  void shiftTLConnectionLaneIndex(NBEdge* edge, int offset);
96 
104  void addPhase(SUMOTime duration, const std::string& state, SUMOTime minDur, SUMOTime maxDur);
105 
107  void phasesLoaded() {
108  myPhasesLoaded = true;
109  }
110 
113  void addConnection(NBEdge* from, NBEdge* to, int fromLane, int toLane, int linkIndex, bool reconstruct = true);
114 
115 
120  void removeConnection(const NBConnection& conn, bool reconstruct = true);
121 
123  void registerModifications(bool addedConnections, bool removedConnections);
124 
128  return myTLLogic;
129  }
130 
134  void setOffset(SUMOTime offset);
135 
139  void setType(TrafficLightType type);
140 
142  bool rightOnRedConflict(int index, int foeIndex) const;
143 
144  /* @brief shortens phase states to remove states that are not referenced by
145  * any controlled link and returns whether states were shortened
146  */
147  bool cleanupStates();
148 
149 protected:
153  void collectLinks();
154 
157  void collectEdges();
158 
163  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
164 
165  bool amInvalid() const;
166 
167  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
168  void initNeedsContRelation() const;
169 
170 private:
171 
174 
176  std::set<NBNode*> myOriginalNodes;
177 
179  void patchIfCrossingsAdded();
180 
182  std::set<NBEdge*> myShifted;
183 
188 
194  void collectEdgeVectors(EdgeVector& fromEdges, EdgeVector& toEdges, std::vector<int>& fromLanes) const;
195 
197  void reconstructLogic();
198 
199 private:
202  public:
205 
206  bool operator()(const NBConnection& c) const {
207  return c.getFrom() == myC.getFrom() && c.getTo() == myC.getTo() &&
208  c.getFromLane() == myC.getFromLane() && c.getToLane() == myC.getToLane();
209  }
210  private:
212  private:
215 
216  };
217 
218 };
219 
220 
221 #endif
222 
223 /****************************************************************************/
224 
void addPhase(SUMOTime duration, const std::string &state, SUMOTime minDur, SUMOTime maxDur)
Adds a phase to the logic the new phase is inserted at the end of the list of already added phases...
void removeConnection(const NBConnection &conn, bool reconstruct=true)
removes the given connection from the traffic light if recontruct=true, reconstructs the logic and in...
NBLoadedSUMOTLDef(const std::string &id, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light ...
void collectEdges()
Build the list of participating edges.
void setOffset(SUMOTime offset)
Sets the offset of this tls.
void reconstructLogic()
adapt to removal or addition of connections
A loaded (complete) traffic light logic.
A SUMO-compliant built logic for a traffic light.
bool myReconstructAddedConnections
whether the logic must be reconstructed
void registerModifications(bool addedConnections, bool removedConnections)
register changes that necessitate recomputation
The representation of a single edge during network building.
Definition: NBEdge.h:70
class for identifying connections
int getFromLane() const
returns the from-lane
void phasesLoaded()
mark phases as load
The base class for traffic light logic definitions.
bool operator()(const NBConnection &c) const
NBEdge * getFrom() const
returns the from-edge (start of the connection)
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
connection_equal(const NBConnection &c)
constructor
void patchIfCrossingsAdded()
repair the plan if controlled nodes received pedestrian crossings
void addConnection(NBEdge *from, NBEdge *to, int fromLane, int toLane, int linkIndex, bool reconstruct=true)
Adds a connection and immediately informs the edges.
std::set< NBNode * > myOriginalNodes
The original nodes for which the loaded logic is valid.
void initNeedsContRelation() const
NBTrafficLightLogic * getLogic()
Returns the internal logic.
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
std::set< NBEdge * > myShifted
set of edges with shifted lane indices (to avoid shifting twice)
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:40
int getToLane() const
returns the to-lane
void collectLinks()
Collects the links participating in this traffic light (only if not previously loaded) ...
NBEdge * getTo() const
returns the to-edge (end of the connection)
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
~NBLoadedSUMOTLDef()
Destructor.
long long int SUMOTime
Definition: TraCIDefs.h:51
void setType(TrafficLightType type)
Sets the algorithm type of this tls.
void collectEdgeVectors(EdgeVector &fromEdges, EdgeVector &toEdges, std::vector< int > &fromLanes) const
Collects the edges for each tlIndex.
connection_equal & operator=(const connection_equal &s)
invalidated assignment operator
void shiftTLConnectionLaneIndex(NBEdge *edge, int offset)
patches signal plans by modifying lane indices
NBTrafficLightLogic * myTLLogic
phases are added directly to myTLLogic which is then returned in myCompute()
TrafficLightType