Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A complete traffic light logic loaded from a sumo-net. (opted to reimplement
17 // since NBLoadedTLDef is quite vissim specific)
18 /****************************************************************************/
19 #ifndef NBLoadedSUMOTLDef_h
20 #define NBLoadedSUMOTLDef_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <string>
30 #include <set>
31 #include "NBNode.h"
32 #include "NBEdgeCont.h"
34 #include "NBTrafficLightLogic.h"
35 #include <utils/common/SUMOTime.h>
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
46 public:
47 
54  NBLoadedSUMOTLDef(const std::string& id, const std::string& programID, SUMOTime offset, TrafficLightType type);
55 
61 
62 
65 
68  void setTLControllingInformation() const;
69 
75  void remapRemoved(NBEdge* removed,
76  const EdgeVector& incoming, const EdgeVector& outgoing);
77 
78 
85  void replaceRemoved(NBEdge* removed, int removedLane,
86  NBEdge* by, int byLane);
87 
91  void shiftTLConnectionLaneIndex(NBEdge* edge, int offset, int threshold = -1);
92 
100  void addPhase(SUMOTime duration, const std::string& state, SUMOTime minDur, SUMOTime maxDur, const std::vector<int>& next, const std::string& name);
101 
103  void phasesLoaded() {
104  myPhasesLoaded = true;
105  }
106 
109  void addConnection(NBEdge* from, NBEdge* to, int fromLane, int toLane, int linkIndex, bool reconstruct = true);
110 
111 
116  void removeConnection(const NBConnection& conn, bool reconstruct = true);
117 
119  void registerModifications(bool addedConnections, bool removedConnections);
120 
124  return myTLLogic;
125  }
126 
130  void setOffset(SUMOTime offset);
131 
135  void setType(TrafficLightType type);
136 
138  bool rightOnRedConflict(int index, int foeIndex) const;
139 
140  /* @brief shortens phase states to remove states that are not referenced by
141  * any controlled link and returns whether states were shortened
142  */
143  bool cleanupStates();
144 
146  bool usingSignalGroups() const;
147 
150 
152  void guessMinMaxDuration();
153 
154 protected:
158  void collectLinks();
159 
162  void collectEdges();
163 
168  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
169 
170  bool amInvalid() const;
171 
172  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
173  void initNeedsContRelation() const;
174 
176  int getMaxIndex();
177 
179  int getMaxValidIndex();
180 
181 private:
182 
185 
187  std::set<NBNode*> myOriginalNodes;
188 
190  void patchIfCrossingsAdded();
191 
193  std::set<NBEdge*> myShifted;
194 
199 
205  void collectEdgeVectors(EdgeVector& fromEdges, EdgeVector& toEdges, std::vector<int>& fromLanes) const;
206 
208  void reconstructLogic();
209 
211  bool hasValidIndices() const;
212 
213 private:
216  public:
219 
220  bool operator()(const NBConnection& c) const {
221  return c.getFrom() == myC.getFrom() && c.getTo() == myC.getTo() &&
222  c.getFromLane() == myC.getFromLane() && c.getToLane() == myC.getToLane();
223  }
224  private:
226  private:
229 
230  };
231 
232 };
233 
234 
235 #endif
236 
237 /****************************************************************************/
238 
void removeConnection(const NBConnection &conn, bool reconstruct=true)
removes the given connection from the traffic light if recontruct=true, reconstructs the logic and in...
long long int SUMOTime
Definition: SUMOTime.h:35
NBLoadedSUMOTLDef(const std::string &id, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
void guessMinMaxDuration()
heuristically add minDur and maxDur when switching from tlType fixed to actuated
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:86
class for identifying connections
void phasesLoaded()
mark phases as load
The base class for traffic light logic definitions.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
bool hasValidIndices() const
return whether all tls link indices are valid
void addPhase(SUMOTime duration, const std::string &state, SUMOTime minDur, SUMOTime maxDur, const std::vector< int > &next, const std::string &name)
Adds a phase to the logic the new phase is inserted at the end of the list of already added phases...
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
connection_equal(const NBConnection &c)
constructor
void initNeedsContRelation() const
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.
NBTrafficLightLogic * getLogic()
Returns the internal logic.
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light ...
int getMaxValidIndex()
Returns the maximum index controlled by this traffic light.
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
void joinLogic(NBTrafficLightDefinition *def)
join nodes and states from the given logic (append red state)
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
int getToLane() const
returns the to-lane
NBEdge * getTo() const
returns the to-edge (end of the connection)
std::set< NBEdge * > myShifted
set of edges with shifted lane indices (to avoid shifting twice)
bool operator()(const NBConnection &c) const
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
void collectLinks()
Collects the links participating in this traffic light (only if not previously loaded) ...
int getFromLane() const
returns the from-lane
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
~NBLoadedSUMOTLDef()
Destructor.
bool usingSignalGroups() const
whether this definition uses signal group (multiple connections with the same link index) ...
void setType(TrafficLightType type)
Sets the algorithm type of this tls.
void shiftTLConnectionLaneIndex(NBEdge *edge, int offset, int threshold=-1)
patches signal plans by modifying lane indices with the given offset, only indices with a value above...
connection_equal & operator=(const connection_equal &s)
invalidated assignment operator
NBTrafficLightLogic * myTLLogic
phases are added directly to myTLLogic which is then returned in myCompute()
int getMaxIndex()
return the highest known tls link index used by any controlled connection or crossing ...
TrafficLightType
void collectEdgeVectors(EdgeVector &fromEdges, EdgeVector &toEdges, std::vector< int > &fromLanes) const
Collects the edges for each tlIndex.