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 /****************************************************************************/
15 // A complete traffic light logic loaded from a sumo-net. (opted to reimplement
16 // since NBLoadedTLDef is quite vissim specific)
17 /****************************************************************************/
18 #ifndef NBLoadedSUMOTLDef_h
19 #define NBLoadedSUMOTLDef_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <string>
29 #include <set>
30 #include "NBNode.h"
31 #include "NBEdgeCont.h"
33 #include "NBTrafficLightLogic.h"
34 #include <utils/common/SUMOTime.h>
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
45 public:
46 
53  NBLoadedSUMOTLDef(const std::string& id, const std::string& programID, SUMOTime offset, TrafficLightType type);
54 
60 
61 
64 
67  void setTLControllingInformation() const;
68 
74  void remapRemoved(NBEdge* removed,
75  const EdgeVector& incoming, const EdgeVector& outgoing);
76 
77 
84  void replaceRemoved(NBEdge* removed, int removedLane,
85  NBEdge* by, int byLane);
86 
90  void shiftTLConnectionLaneIndex(NBEdge* edge, int offset, int threshold = -1);
91 
99  void addPhase(SUMOTime duration, const std::string& state, SUMOTime minDur, SUMOTime maxDur, const std::vector<int>& next, const std::string& name);
100 
102  void phasesLoaded() {
103  myPhasesLoaded = true;
104  }
105 
108  void addConnection(NBEdge* from, NBEdge* to, int fromLane, int toLane, int linkIndex, int linkIndex2, bool reconstruct = true);
109 
110 
115  void removeConnection(const NBConnection& conn, bool reconstruct = true);
116 
118  void registerModifications(bool addedConnections, bool removedConnections);
119 
123  return myTLLogic;
124  }
125 
129  void setOffset(SUMOTime offset);
130 
134  void setType(TrafficLightType type);
135 
137  bool rightOnRedConflict(int index, int foeIndex) const;
138 
139  /* @brief shortens phase states to remove states that are not referenced by
140  * any controlled link and returns whether states were shortened
141  */
142  bool cleanupStates();
143 
145  bool usingSignalGroups() const;
146 
149 
151  void guessMinMaxDuration();
152 
153 protected:
157  void collectLinks();
158 
161  void collectEdges();
162 
167  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
168 
169  bool amInvalid() const;
170 
171  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
172  void initNeedsContRelation() const;
173 
175  int getMaxIndex();
176 
178  int getMaxValidIndex();
179 
180 private:
181 
184 
186  std::set<NBNode*> myOriginalNodes;
187 
189  void patchIfCrossingsAdded();
190 
192  std::set<NBEdge*> myShifted;
193 
198 
204  void collectEdgeVectors(EdgeVector& fromEdges, EdgeVector& toEdges, std::vector<int>& fromLanes) const;
205 
207  void reconstructLogic();
208 
210  bool hasValidIndices() const;
211 
212 private:
215  public:
218 
219  bool operator()(const NBConnection& c) const {
220  return c.getFrom() == myC.getFrom() && c.getTo() == myC.getTo() &&
221  c.getFromLane() == myC.getFromLane() && c.getToLane() == myC.getToLane();
222  }
223  private:
225  private:
228 
229  };
230 
231 };
232 
233 
234 #endif
235 
236 /****************************************************************************/
237 
NBLoadedSUMOTLDef::reconstructLogic
void reconstructLogic()
adapt to removal or addition of connections
Definition: NBLoadedSUMOTLDef.cpp:443
SUMOTime.h
NBLoadedSUMOTLDef::myTLLogic
NBTrafficLightLogic * myTLLogic
phases are added directly to myTLLogic which is then returned in myCompute()
Definition: NBLoadedSUMOTLDef.h:183
NBLoadedSUMOTLDef::collectEdgeVectors
void collectEdgeVectors(EdgeVector &fromEdges, EdgeVector &toEdges, std::vector< int > &fromLanes) const
Collects the edges for each tlIndex.
Definition: NBLoadedSUMOTLDef.cpp:360
NBLoadedSUMOTLDef::removeConnection
void removeConnection(const NBConnection &conn, bool reconstruct=true)
removes the given connection from the traffic light if recontruct=true, reconstructs the logic and in...
Definition: NBLoadedSUMOTLDef.cpp:201
NBTrafficLightLogic.h
NBLoadedSUMOTLDef::hasValidIndices
bool hasValidIndices() const
return whether all tls link indices are valid
Definition: NBLoadedSUMOTLDef.cpp:578
EdgeVector
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
NBLoadedSUMOTLDef::~NBLoadedSUMOTLDef
~NBLoadedSUMOTLDef()
Destructor.
Definition: NBLoadedSUMOTLDef.cpp:77
NBLoadedSUMOTLDef::connection_equal::operator=
connection_equal & operator=(const connection_equal &s)
invalidated assignment operator
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1197
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
NBConnection::getFrom
NBEdge * getFrom() const
returns the from-edge (start of the connection)
Definition: NBConnection.cpp:89
NBLoadedSUMOTLDef::guessMinMaxDuration
void guessMinMaxDuration()
heuristically add minDur and maxDur when switching from tlType fixed to actuated
Definition: NBLoadedSUMOTLDef.cpp:638
NBEdgeCont.h
NBConnection::getTo
NBEdge * getTo() const
returns the to-edge (end of the connection)
Definition: NBConnection.cpp:95
NBLoadedSUMOTLDef::addPhase
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.
Definition: NBLoadedSUMOTLDef.cpp:172
NBLoadedSUMOTLDef::connection_equal
class for identifying connections
Definition: NBLoadedSUMOTLDef.h:214
NBTrafficLightDefinition.h
NBLoadedSUMOTLDef::setOffset
void setOffset(SUMOTime offset)
Sets the offset of this tls.
Definition: NBLoadedSUMOTLDef.cpp:223
NBLoadedSUMOTLDef::getLogic
NBTrafficLightLogic * getLogic()
Returns the internal logic.
Definition: NBLoadedSUMOTLDef.h:122
NBLoadedSUMOTLDef::getMaxIndex
int getMaxIndex()
return the highest known tls link index used by any controlled connection or crossing
Definition: NBLoadedSUMOTLDef.cpp:556
NBLoadedSUMOTLDef::initNeedsContRelation
void initNeedsContRelation() const
Definition: NBLoadedSUMOTLDef.cpp:381
NBLoadedSUMOTLDef::addConnection
void addConnection(NBEdge *from, NBEdge *to, int fromLane, int toLane, int linkIndex, int linkIndex2, bool reconstruct=true)
Adds a connection and immediately informs the edges.
Definition: NBLoadedSUMOTLDef.cpp:95
NBLoadedSUMOTLDef::registerModifications
void registerModifications(bool addedConnections, bool removedConnections)
register changes that necessitate recomputation
Definition: NBLoadedSUMOTLDef.cpp:437
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NBLoadedSUMOTLDef::myOriginalNodes
std::set< NBNode * > myOriginalNodes
The original nodes for which the loaded logic is valid.
Definition: NBLoadedSUMOTLDef.h:186
NBLoadedSUMOTLDef::rightOnRedConflict
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light
Definition: NBLoadedSUMOTLDef.cpp:424
NBLoadedSUMOTLDef::collectLinks
void collectLinks()
Collects the links participating in this traffic light (only if not previously loaded)
Definition: NBLoadedSUMOTLDef.cpp:281
NBLoadedSUMOTLDef::myReconstructAddedConnections
bool myReconstructAddedConnections
whether the logic must be reconstructed
Definition: NBLoadedSUMOTLDef.h:195
NBConnection::getToLane
int getToLane() const
returns the to-lane
Definition: NBConnection.cpp:240
NBLoadedSUMOTLDef::phasesLoaded
void phasesLoaded()
mark phases as load
Definition: NBLoadedSUMOTLDef.h:102
NBLoadedSUMOTLDef::myShifted
std::set< NBEdge * > myShifted
set of edges with shifted lane indices (to avoid shifting twice)
Definition: NBLoadedSUMOTLDef.h:192
NBConnection
Definition: NBConnection.h:43
NBLoadedSUMOTLDef::connection_equal::myC
const NBConnection & myC
Definition: NBLoadedSUMOTLDef.h:224
NBLoadedSUMOTLDef::cleanupStates
bool cleanupStates()
Definition: NBLoadedSUMOTLDef.cpp:597
NBLoadedSUMOTLDef::replaceRemoved
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBLoadedSUMOTLDef.cpp:163
NBLoadedSUMOTLDef::getMaxValidIndex
int getMaxValidIndex()
Returns the maximum index controlled by this traffic light.
Definition: NBLoadedSUMOTLDef.cpp:572
NBLoadedSUMOTLDef::myCompute
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBLoadedSUMOTLDef.cpp:83
NBLoadedSUMOTLDef::myReconstructRemovedConnections
bool myReconstructRemovedConnections
Definition: NBLoadedSUMOTLDef.h:196
NBLoadedSUMOTLDef::remapRemoved
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
Definition: NBLoadedSUMOTLDef.cpp:159
NBLoadedSUMOTLDef::NBLoadedSUMOTLDef
NBLoadedSUMOTLDef(const std::string &id, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBLoadedSUMOTLDef.cpp:46
NBLoadedSUMOTLDef::patchIfCrossingsAdded
void patchIfCrossingsAdded()
repair the plan if controlled nodes received pedestrian crossings
Definition: NBLoadedSUMOTLDef.cpp:305
config.h
NBLoadedSUMOTLDef::connection_equal::operator()
bool operator()(const NBConnection &c) const
Definition: NBLoadedSUMOTLDef.h:219
NBTrafficLightLogic
A SUMO-compliant built logic for a traffic light.
Definition: NBTrafficLightLogic.h:51
NBLoadedSUMOTLDef::amInvalid
bool amInvalid() const
Definition: NBLoadedSUMOTLDef.cpp:178
NBLoadedSUMOTLDef::myPhasesLoaded
bool myPhasesLoaded
Definition: NBLoadedSUMOTLDef.h:197
NBNode.h
NBLoadedSUMOTLDef::connection_equal::connection_equal
connection_equal(const NBConnection &c)
constructor
Definition: NBLoadedSUMOTLDef.h:217
NBConnection::getFromLane
int getFromLane() const
returns the from-lane
Definition: NBConnection.cpp:234
NBLoadedSUMOTLDef::joinLogic
void joinLogic(NBTrafficLightDefinition *def)
join nodes and states from the given logic (append red state)
Definition: NBLoadedSUMOTLDef.cpp:607
NBLoadedSUMOTLDef::setTLControllingInformation
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBLoadedSUMOTLDef.cpp:124
NBTrafficLightDefinition
The base class for traffic light logic definitions.
Definition: NBTrafficLightDefinition.h:67
NBLoadedSUMOTLDef::collectEdges
void collectEdges()
Build the list of participating edges.
Definition: NBLoadedSUMOTLDef.cpp:237
NBLoadedSUMOTLDef::usingSignalGroups
bool usingSignalGroups() const
whether this definition uses signal group (multiple connections with the same link index)
Definition: NBLoadedSUMOTLDef.cpp:617
NBLoadedSUMOTLDef::setType
void setType(TrafficLightType type)
Sets the algorithm type of this tls.
Definition: NBLoadedSUMOTLDef.cpp:230
NBLoadedSUMOTLDef::shiftTLConnectionLaneIndex
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...
Definition: NBLoadedSUMOTLDef.cpp:293
NBLoadedSUMOTLDef
A loaded (complete) traffic light logic.
Definition: NBLoadedSUMOTLDef.h:44