SUMO - Simulation of Urban MObility
NBOwnTLDef.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 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 /****************************************************************************/
17 // A traffic light logics which must be computed (only nodes/edges are given)
18 /****************************************************************************/
19 #ifndef NBOwnTLDef_h
20 #define NBOwnTLDef_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <set>
32 #include "NBNode.h"
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
48 public:
55  NBOwnTLDef(const std::string& id,
56  const std::vector<NBNode*>& junctions,
57  SUMOTime offset,
58  TrafficLightType type);
59 
60 
67  NBOwnTLDef(const std::string& id, NBNode* junction, SUMOTime offset,
68  TrafficLightType type);
69 
70 
76  NBOwnTLDef(const std::string& id, SUMOTime offset, TrafficLightType type);
77 
78 
80  ~NBOwnTLDef();
81 
82 
85 
92  void remapRemoved(NBEdge* removed,
93  const EdgeVector& incoming, const EdgeVector& outgoing);
94 
95 
99  void setTLControllingInformation() const;
101 
102 
105  void setSinglePhase() {
106  myHaveSinglePhase = true;
107  }
108 
110  static void addPedestrianScramble(NBTrafficLightLogic* logic, int noLinksAll,
111  SUMOTime greenTime, SUMOTime yellowTime,
112  const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
113 
115  static std::string addPedestrianPhases(NBTrafficLightLogic* logic, SUMOTime greenTime,
116  SUMOTime minDur, SUMOTime maxDur,
117  std::string state, const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
118 
120  static std::string patchStateForCrossings(const std::string& state,
121  const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
122 
128  NBTrafficLightLogic* computeLogicAndConts(int brakingTimeSeconds, bool onlyConts = false);
129 
130  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
131  void initNeedsContRelation() const;
132 
133  /* build optional all-red phase */
134  void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic* logic, const std::string& state);
135 
137  int getMaxIndex();
138 
139 protected:
142 
148  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
149 
150 
155  void collectLinks();
156 
157 
165  void replaceRemoved(NBEdge* removed, int removedLane,
166  NBEdge* by, int byLane);
168 
169 
170 protected:
177 
178 
183  int getToPrio(const NBEdge* const e);
184 
185 
191  double computeUnblockedWeightedStreamNumber(const NBEdge* const e1, const NBEdge* const e2);
192 
193 
198  std::pair<NBEdge*, NBEdge*> getBestCombination(const EdgeVector& edges);
199 
200 
208  std::pair<NBEdge*, NBEdge*> getBestPair(EdgeVector& incoming);
209 
210 
212  static bool hasCrossing(const NBEdge* from, const NBEdge* to, const std::vector<NBNode::Crossing*>& crossings);
213 
215  static EdgeVector getConnectedOuterEdges(const EdgeVector& incoming);
216 
217 
219  std::string allowFollowersOfChosen(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges);
220 
232  std::string correctConflicting(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
233  const std::vector<bool>& isTurnaround,
234  const std::vector<int>& fromLanes,
235  const std::vector<bool>& hadGreenMajor,
236  bool& haveForbiddenLeftMover, std::vector<bool>& rightTurnConflicts);
237 
240 
245  public:
250  int operator()(const NBEdge* const e1, const NBEdge* const e2) const {
251  if (e1->getJunctionPriority(e1->getToNode()) != e2->getJunctionPriority(e2->getToNode())) {
252  return e1->getJunctionPriority(e1->getToNode()) > e2->getJunctionPriority(e2->getToNode());
253  }
254  return e1->getID() > e2->getID();
255  }
256  };
257 
258 
259 private:
262 
263 };
264 
265 
266 #endif
267 
268 /****************************************************************************/
269 
void setSinglePhase()
Forces the definition not to compute an additional phase for left-movers.
Definition: NBOwnTLDef.h:105
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBOwnTLDef.cpp:584
long long int SUMOTime
Definition: SUMOTime.h:36
static bool hasCrossing(const NBEdge *from, const NBEdge *to, const std::vector< NBNode::Crossing *> &crossings)
compute whether the given connection is crossed by pedestrians
Definition: NBOwnTLDef.cpp:480
A SUMO-compliant built logic for a traffic light.
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition: NBEdge.cpp:1781
std::string correctConflicting(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, const std::vector< bool > &isTurnaround, const std::vector< int > &fromLanes, const std::vector< bool > &hadGreenMajor, bool &haveForbiddenLeftMover, std::vector< bool > &rightTurnConflicts)
change &#39;G&#39; to &#39;g&#39; for conflicting connections
Definition: NBOwnTLDef.cpp:665
The representation of a single edge during network building.
Definition: NBEdge.h:65
std::string allowFollowersOfChosen(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges)
allow connections that follow on of the chosen edges
Definition: NBOwnTLDef.cpp:640
The base class for traffic light logic definitions.
const std::string & getID() const
Returns the id.
Definition: Named.h:78
static EdgeVector getConnectedOuterEdges(const EdgeVector &incoming)
get edges that have connections
Definition: NBOwnTLDef.cpp:626
int operator()(const NBEdge *const e1, const NBEdge *const e2) const
comparing operator
Definition: NBOwnTLDef.h:250
std::pair< NBEdge *, NBEdge * > getBestPair(EdgeVector &incoming)
Returns the combination of two edges from the given which has most unblocked streams.
Definition: NBOwnTLDef.cpp:150
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
static void addPedestrianScramble(NBTrafficLightLogic *logic, int noLinksAll, SUMOTime greenTime, SUMOTime yellowTime, const std::vector< NBNode::Crossing *> &crossings, const EdgeVector &fromEdges, const EdgeVector &toEdges)
add an additional pedestrian phase if there are crossings that did not get green yet ...
Definition: NBOwnTLDef.cpp:724
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBOwnTLDef.cpp:601
double computeUnblockedWeightedStreamNumber(const NBEdge *const e1, const NBEdge *const e2)
Returns how many streams outgoing from the edges can pass the junction without being blocked...
Definition: NBOwnTLDef.cpp:96
std::pair< NBEdge *, NBEdge * > getBestCombination(const EdgeVector &edges)
Returns the combination of two edges from the given which has most unblocked streams.
Definition: NBOwnTLDef.cpp:123
bool myHaveSinglePhase
Whether left-mover should not have an additional phase.
Definition: NBOwnTLDef.h:261
void checkCustomCrossingIndices(NBTrafficLightLogic *logic) const
fix states in regard to custom crossing indices
Definition: NBOwnTLDef.cpp:780
~NBOwnTLDef()
Destructor.
Definition: NBOwnTLDef.cpp:70
NBOwnTLDef(const std::string &id, const std::vector< NBNode *> &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBOwnTLDef.cpp:48
void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic *logic, const std::string &state)
Definition: NBOwnTLDef.cpp:766
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
Definition: NBOwnTLDef.cpp:804
static std::string patchStateForCrossings(const std::string &state, const std::vector< NBNode::Crossing *> &crossings, const EdgeVector &fromEdges, const EdgeVector &toEdges)
compute phase state in regard to pedestrian crossings
Definition: NBOwnTLDef.cpp:530
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBOwnTLDef.cpp:184
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
Definition: NBOwnTLDef.cpp:189
void collectLinks()
Collects the links participating in this traffic light.
Definition: NBOwnTLDef.cpp:578
static std::string addPedestrianPhases(NBTrafficLightLogic *logic, SUMOTime greenTime, SUMOTime minDur, SUMOTime maxDur, std::string state, const std::vector< NBNode::Crossing *> &crossings, const EdgeVector &fromEdges, const EdgeVector &toEdges)
add 1 or 2 phases depending on the presence of pedestrian crossings
Definition: NBOwnTLDef.cpp:499
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
double getDirectionalWeight(LinkDirection dir)
Returns the weight of a stream given its direction.
Definition: NBOwnTLDef.cpp:80
Represents a single node (junction) during network building.
Definition: NBNode.h:68
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:47
void initNeedsContRelation() const
Definition: NBOwnTLDef.cpp:606
Sorts edges by their priority within the node they end at.
Definition: NBOwnTLDef.h:244
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:441
int getToPrio(const NBEdge *const e)
Returns this edge&#39;s priority at the node it ends at.
Definition: NBOwnTLDef.cpp:74
TrafficLightType
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
Definition: NBOwnTLDef.cpp:596