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 
NBLoadedSUMOTLDef::reconstructLogic
void reconstructLogic()
adapt to removal or addition of connections
Definition: NBLoadedSUMOTLDef.cpp:440
SUMOTime.h
NBLoadedSUMOTLDef::myTLLogic
NBTrafficLightLogic * myTLLogic
phases are added directly to myTLLogic which is then returned in myCompute()
Definition: NBLoadedSUMOTLDef.h:184
NBLoadedSUMOTLDef::collectEdgeVectors
void collectEdgeVectors(EdgeVector &fromEdges, EdgeVector &toEdges, std::vector< int > &fromLanes) const
Collects the edges for each tlIndex.
Definition: NBLoadedSUMOTLDef.cpp:357
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:198
NBTrafficLightLogic.h
NBLoadedSUMOTLDef::hasValidIndices
bool hasValidIndices() const
return whether all tls link indices are valid
Definition: NBLoadedSUMOTLDef.cpp:575
EdgeVector
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
NBLoadedSUMOTLDef::~NBLoadedSUMOTLDef
~NBLoadedSUMOTLDef()
Destructor.
Definition: NBLoadedSUMOTLDef.cpp:78
NBLoadedSUMOTLDef::connection_equal::operator=
connection_equal & operator=(const connection_equal &s)
invalidated assignment operator
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1192
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
NBConnection::getFrom
NBEdge * getFrom() const
returns the from-edge (start of the connection)
Definition: NBConnection.cpp:86
NBLoadedSUMOTLDef::guessMinMaxDuration
void guessMinMaxDuration()
heuristically add minDur and maxDur when switching from tlType fixed to actuated
Definition: NBLoadedSUMOTLDef.cpp:635
NBEdgeCont.h
NBConnection::getTo
NBEdge * getTo() const
returns the to-edge (end of the connection)
Definition: NBConnection.cpp:92
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:169
NBLoadedSUMOTLDef::connection_equal
class for identifying connections
Definition: NBLoadedSUMOTLDef.h:215
NBTrafficLightDefinition.h
NBLoadedSUMOTLDef::setOffset
void setOffset(SUMOTime offset)
Sets the offset of this tls.
Definition: NBLoadedSUMOTLDef.cpp:220
NBLoadedSUMOTLDef::getLogic
NBTrafficLightLogic * getLogic()
Returns the internal logic.
Definition: NBLoadedSUMOTLDef.h:123
NBLoadedSUMOTLDef::getMaxIndex
int getMaxIndex()
return the highest known tls link index used by any controlled connection or crossing
Definition: NBLoadedSUMOTLDef.cpp:553
NBLoadedSUMOTLDef::initNeedsContRelation
void initNeedsContRelation() const
Definition: NBLoadedSUMOTLDef.cpp:378
NBLoadedSUMOTLDef::registerModifications
void registerModifications(bool addedConnections, bool removedConnections)
register changes that necessitate recomputation
Definition: NBLoadedSUMOTLDef.cpp:434
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:86
NBLoadedSUMOTLDef::addConnection
void addConnection(NBEdge *from, NBEdge *to, int fromLane, int toLane, int linkIndex, bool reconstruct=true)
Adds a connection and immediately informs the edges.
Definition: NBLoadedSUMOTLDef.cpp:96
NBLoadedSUMOTLDef::myOriginalNodes
std::set< NBNode * > myOriginalNodes
The original nodes for which the loaded logic is valid.
Definition: NBLoadedSUMOTLDef.h:187
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:421
NBLoadedSUMOTLDef::collectLinks
void collectLinks()
Collects the links participating in this traffic light (only if not previously loaded)
Definition: NBLoadedSUMOTLDef.cpp:278
NBLoadedSUMOTLDef::myReconstructAddedConnections
bool myReconstructAddedConnections
whether the logic must be reconstructed
Definition: NBLoadedSUMOTLDef.h:196
NBConnection::getToLane
int getToLane() const
returns the to-lane
Definition: NBConnection.cpp:236
NBLoadedSUMOTLDef::phasesLoaded
void phasesLoaded()
mark phases as load
Definition: NBLoadedSUMOTLDef.h:103
NBLoadedSUMOTLDef::myShifted
std::set< NBEdge * > myShifted
set of edges with shifted lane indices (to avoid shifting twice)
Definition: NBLoadedSUMOTLDef.h:193
NBConnection
Definition: NBConnection.h:44
NBLoadedSUMOTLDef::connection_equal::myC
const NBConnection & myC
Definition: NBLoadedSUMOTLDef.h:225
NBLoadedSUMOTLDef::cleanupStates
bool cleanupStates()
Definition: NBLoadedSUMOTLDef.cpp:594
NBLoadedSUMOTLDef::replaceRemoved
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBLoadedSUMOTLDef.cpp:160
NBLoadedSUMOTLDef::getMaxValidIndex
int getMaxValidIndex()
Returns the maximum index controlled by this traffic light.
Definition: NBLoadedSUMOTLDef.cpp:569
NBLoadedSUMOTLDef::myCompute
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBLoadedSUMOTLDef.cpp:84
NBLoadedSUMOTLDef::myReconstructRemovedConnections
bool myReconstructRemovedConnections
Definition: NBLoadedSUMOTLDef.h:197
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:156
NBLoadedSUMOTLDef::NBLoadedSUMOTLDef
NBLoadedSUMOTLDef(const std::string &id, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBLoadedSUMOTLDef.cpp:47
NBLoadedSUMOTLDef::patchIfCrossingsAdded
void patchIfCrossingsAdded()
repair the plan if controlled nodes received pedestrian crossings
Definition: NBLoadedSUMOTLDef.cpp:302
config.h
NBLoadedSUMOTLDef::connection_equal::operator()
bool operator()(const NBConnection &c) const
Definition: NBLoadedSUMOTLDef.h:220
NBTrafficLightLogic
A SUMO-compliant built logic for a traffic light.
Definition: NBTrafficLightLogic.h:52
NBLoadedSUMOTLDef::amInvalid
bool amInvalid() const
Definition: NBLoadedSUMOTLDef.cpp:175
NBLoadedSUMOTLDef::myPhasesLoaded
bool myPhasesLoaded
Definition: NBLoadedSUMOTLDef.h:198
NBNode.h
NBLoadedSUMOTLDef::connection_equal::connection_equal
connection_equal(const NBConnection &c)
constructor
Definition: NBLoadedSUMOTLDef.h:218
NBConnection::getFromLane
int getFromLane() const
returns the from-lane
Definition: NBConnection.cpp:230
NBLoadedSUMOTLDef::joinLogic
void joinLogic(NBTrafficLightDefinition *def)
join nodes and states from the given logic (append red state)
Definition: NBLoadedSUMOTLDef.cpp:604
NBLoadedSUMOTLDef::setTLControllingInformation
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBLoadedSUMOTLDef.cpp:121
NBTrafficLightDefinition
The base class for traffic light logic definitions.
Definition: NBTrafficLightDefinition.h:68
NBLoadedSUMOTLDef::collectEdges
void collectEdges()
Build the list of participating edges.
Definition: NBLoadedSUMOTLDef.cpp:234
NBLoadedSUMOTLDef::usingSignalGroups
bool usingSignalGroups() const
whether this definition uses signal group (multiple connections with the same link index)
Definition: NBLoadedSUMOTLDef.cpp:614
NBLoadedSUMOTLDef::setType
void setType(TrafficLightType type)
Sets the algorithm type of this tls.
Definition: NBLoadedSUMOTLDef.cpp:227
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:290
NBLoadedSUMOTLDef
A loaded (complete) traffic light logic.
Definition: NBLoadedSUMOTLDef.h:45