Eclipse 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-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 /****************************************************************************/
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:
171 
173  bool corridorLike() const;
174 
181 
182 
187  int getToPrio(const NBEdge* const e);
188 
189 
195  double computeUnblockedWeightedStreamNumber(const NBEdge* const e1, const NBEdge* const e2);
196 
197 
202  std::pair<NBEdge*, NBEdge*> getBestCombination(const EdgeVector& edges);
203 
204 
212  std::pair<NBEdge*, NBEdge*> getBestPair(EdgeVector& incoming);
213 
214 
216  static bool hasCrossing(const NBEdge* from, const NBEdge* to, const std::vector<NBNode::Crossing*>& crossings);
217 
219  static EdgeVector getConnectedOuterEdges(const EdgeVector& incoming);
220 
221 
223  std::string allowCompatible(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
224  const std::vector<int>& fromLanes, const std::vector<int>& toLanes);
225 
226  std::string allowSingleEdge(std::string state, const EdgeVector& fromEdges);
227 
228  std::string allowFollowers(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges);
229 
230  std::string allowPredecessors(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
231  const std::vector<int>& fromLanes, const std::vector<int>& toLanes);
232 
233  std::string allowUnrelated(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
234  const std::vector<bool>& isTurnaround,
235  const std::vector<NBNode::Crossing*>& crossings);
236 
237  std::string allowByVClass(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges, SVCPermissions perm);
238 
240  bool forbidden(const std::string& state, int index, const EdgeVector& fromEdges, const EdgeVector& toEdges);
241 
253  std::string correctConflicting(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
254  const std::vector<bool>& isTurnaround,
255  const std::vector<int>& fromLanes,
256  const std::vector<bool>& hadGreenMajor,
257  bool& haveForbiddenLeftMover, std::vector<bool>& rightTurnConflicts);
258 
261 
266  public:
271  int operator()(const NBEdge* const e1, const NBEdge* const e2) const {
272  if (e1->getJunctionPriority(e1->getToNode()) != e2->getJunctionPriority(e2->getToNode())) {
273  return e1->getJunctionPriority(e1->getToNode()) > e2->getJunctionPriority(e2->getToNode());
274  }
275  return e1->getID() > e2->getID();
276  }
277  };
278 
279 
280 private:
283 
284 };
285 
286 
287 #endif
288 
289 /****************************************************************************/
290 
std::string allowCompatible(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, const std::vector< int > &fromLanes, const std::vector< int > &toLanes)
allow connections that are compatible with the chosen edges
Definition: NBOwnTLDef.cpp:792
void setSinglePhase()
Forces the definition not to compute an additional phase for left-movers.
Definition: NBOwnTLDef.h:105
bool forbidden(const std::string &state, int index, const EdgeVector &fromEdges, const EdgeVector &toEdges)
whether the given index is forbidden by a green link in the current state
Definition: NBOwnTLDef.cpp:926
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBOwnTLDef.cpp:736
long long int SUMOTime
Definition: SUMOTime.h:35
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:632
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:1843
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
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:937
The representation of a single edge during network building.
Definition: NBEdge.h:86
The base class for traffic light logic definitions.
std::string allowByVClass(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, SVCPermissions perm)
Definition: NBOwnTLDef.cpp:914
static EdgeVector getConnectedOuterEdges(const EdgeVector &incoming)
get edges that have connections
Definition: NBOwnTLDef.cpp:778
int operator()(const NBEdge *const e1, const NBEdge *const e2) const
comparing operator
Definition: NBOwnTLDef.h:271
std::pair< NBEdge *, NBEdge * > getBestPair(EdgeVector &incoming)
Returns the combination of two edges from the given which has most unblocked streams.
Definition: NBOwnTLDef.cpp:199
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:996
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBOwnTLDef.cpp:753
std::string allowFollowers(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges)
Definition: NBOwnTLDef.cpp:827
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:103
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:162
bool myHaveSinglePhase
Whether left-mover should not have an additional phase.
Definition: NBOwnTLDef.h:282
void checkCustomCrossingIndices(NBTrafficLightLogic *logic) const
fix states in regard to custom crossing indices
std::string allowUnrelated(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, const std::vector< bool > &isTurnaround, const std::vector< NBNode::Crossing *> &crossings)
Definition: NBOwnTLDef.cpp:890
~NBOwnTLDef()
Destructor.
Definition: NBOwnTLDef.cpp:77
const std::string & getID() const
Definition: NBEdge.h:1364
NBOwnTLDef(const std::string &id, const std::vector< NBNode *> &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBOwnTLDef.cpp:55
void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic *logic, const std::string &state)
std::string allowPredecessors(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, const std::vector< int > &fromLanes, const std::vector< int > &toLanes)
Definition: NBOwnTLDef.cpp:857
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
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:682
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBOwnTLDef.cpp:235
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
Definition: NBOwnTLDef.cpp:240
void collectLinks()
Collects the links participating in this traffic light.
Definition: NBOwnTLDef.cpp:730
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:651
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
bool corridorLike() const
test whether a joined tls with layout &#39;opposites&#39; would be built without dedicated left-turn phase ...
std::string allowSingleEdge(std::string state, const EdgeVector &fromEdges)
Definition: NBOwnTLDef.cpp:802
double getDirectionalWeight(LinkDirection dir)
Returns the weight of a stream given its direction.
Definition: NBOwnTLDef.cpp:87
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:758
Sorts edges by their priority within the node they end at.
Definition: NBOwnTLDef.h:265
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:486
int getToPrio(const NBEdge *const e)
Returns this edge&#39;s priority at the node it ends at.
Definition: NBOwnTLDef.cpp:81
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:748