SUMO - Simulation of Urban MObility
NBLoadedSUMOTLDef.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // A complete traffic light logic loaded from a sumo-net. (opted to reimplement
9 // since NBLoadedTLDef is quite vissim specific)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2011-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef NBLoadedSUMOTLDef_h
23 #define NBLoadedSUMOTLDef_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
36 #include <string>
37 #include <set>
38 #include "NBNode.h"
39 #include "NBEdgeCont.h"
41 #include "NBTrafficLightLogic.h"
42 #include <utils/common/SUMOTime.h>
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
53 public:
54 
61  NBLoadedSUMOTLDef(const std::string& id, const std::string& programID, SUMOTime offset, TrafficLightType type);
62 
68 
69 
72 
75  void setTLControllingInformation() const;
76 
82  void remapRemoved(NBEdge* removed,
83  const EdgeVector& incoming, const EdgeVector& outgoing);
84 
85 
92  void replaceRemoved(NBEdge* removed, int removedLane,
93  NBEdge* by, int byLane);
94 
96  void shiftTLConnectionLaneIndex(NBEdge* edge, int offset);
97 
105  void addPhase(SUMOTime duration, const std::string& state, SUMOTime minDur, SUMOTime maxDur);
106 
108  void phasesLoaded() {
109  myPhasesLoaded = true;
110  }
111 
114  void addConnection(NBEdge* from, NBEdge* to, int fromLane, int toLane, int linkIndex, bool reconstruct = true);
115 
116 
121  void removeConnection(const NBConnection& conn, bool reconstruct = true);
122 
124  void registerModifications(bool addedConnections, bool removedConnections);
125 
129  return myTLLogic;
130  }
131 
135  void setOffset(SUMOTime offset);
136 
140  void setType(TrafficLightType type);
141 
143  bool rightOnRedConflict(int index, int foeIndex) const;
144 
145 protected:
149  void collectLinks();
150 
153  void collectEdges();
154 
159  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
160 
161  bool amInvalid() const;
162 
163  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
164  void initNeedsContRelation() const;
165 
166 private:
167 
170 
172  std::set<NBNode*> myOriginalNodes;
173 
175  void patchIfCrossingsAdded();
176 
178  std::set<NBEdge*> myShifted;
179 
184 
190  void collectEdgeVectors(EdgeVector& fromEdges, EdgeVector& toEdges, std::vector<int>& fromLanes) const;
191 
193  void reconstructLogic();
194 
195 private:
198  public:
201 
202  bool operator()(const NBConnection& c) const {
203  return c.getFrom() == myC.getFrom() && c.getTo() == myC.getTo() &&
204  c.getFromLane() == myC.getFromLane() && c.getToLane() == myC.getToLane();
205  }
206  private:
208  private:
211 
212  };
213 
214 };
215 
216 
217 #endif
218 
219 /****************************************************************************/
220 
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:71
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:41
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:52
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