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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A traffic light logics which must be computed (only nodes/edges are given)
20 /****************************************************************************/
21 #ifndef NBOwnTLDef_h
22 #define NBOwnTLDef_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <set>
38 #include "NBNode.h"
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
54 public:
61  NBOwnTLDef(const std::string& id,
62  const std::vector<NBNode*>& junctions,
63  SUMOTime offset,
64  TrafficLightType type);
65 
66 
73  NBOwnTLDef(const std::string& id, NBNode* junction, SUMOTime offset,
74  TrafficLightType type);
75 
76 
82  NBOwnTLDef(const std::string& id, SUMOTime offset, TrafficLightType type);
83 
84 
86  ~NBOwnTLDef();
87 
88 
91 
98  void remapRemoved(NBEdge* removed,
99  const EdgeVector& incoming, const EdgeVector& outgoing);
100 
101 
105  void setTLControllingInformation() const;
107 
108 
111  void setSinglePhase() {
112  myHaveSinglePhase = true;
113  }
114 
116  static void addPedestrianScramble(NBTrafficLightLogic* logic, int noLinksAll,
117  SUMOTime greenTime, SUMOTime yellowTime,
118  const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
119 
121  static std::string addPedestrianPhases(NBTrafficLightLogic* logic, SUMOTime greenTime,
122  SUMOTime minDur, SUMOTime maxDur,
123  std::string state, const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
124 
126  static std::string patchStateForCrossings(const std::string& state,
127  const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
128 
134  NBTrafficLightLogic* computeLogicAndConts(int brakingTimeSeconds, bool onlyConts = false);
135 
136  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
137  void initNeedsContRelation() const;
138 
139  /* build optional all-red phase */
140  void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic* logic, const std::string& state);
141 
142 protected:
145 
151  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
152 
153 
158  void collectLinks();
159 
160 
168  void replaceRemoved(NBEdge* removed, int removedLane,
169  NBEdge* by, int byLane);
171 
172 
173 protected:
180 
181 
186  int getToPrio(const NBEdge* const e);
187 
188 
194  double computeUnblockedWeightedStreamNumber(const NBEdge* const e1, const NBEdge* const e2);
195 
196 
201  std::pair<NBEdge*, NBEdge*> getBestCombination(const EdgeVector& edges);
202 
203 
211  std::pair<NBEdge*, NBEdge*> getBestPair(EdgeVector& incoming);
212 
213 
215  static bool hasCrossing(const NBEdge* from, const NBEdge* to, const std::vector<NBNode::Crossing*>& crossings);
216 
218  static EdgeVector getConnectedOuterEdges(const EdgeVector& incoming);
219 
220 
222  std::string allowFollowersOfChosen(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges);
223 
235  std::string correctConflicting(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
236  const std::vector<bool>& isTurnaround,
237  const std::vector<int>& fromLanes,
238  const std::vector<bool>& hadGreenMajor,
239  bool& haveForbiddenLeftMover, std::vector<bool>& rightTurnConflicts);
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:111
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBOwnTLDef.cpp:542
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:440
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:1591
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:623
The representation of a single edge during network building.
Definition: NBEdge.h:70
std::string allowFollowersOfChosen(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges)
allow connections that follow on of the chosen edges
Definition: NBOwnTLDef.cpp:598
The base class for traffic light logic definitions.
const std::string & getID() const
Returns the id.
Definition: Named.h:65
static EdgeVector getConnectedOuterEdges(const EdgeVector &incoming)
get edges that have connections
Definition: NBOwnTLDef.cpp:584
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:156
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:682
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBOwnTLDef.cpp:559
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:102
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:129
bool myHaveSinglePhase
Whether left-mover should not have an additional phase.
Definition: NBOwnTLDef.h:261
~NBOwnTLDef()
Destructor.
Definition: NBOwnTLDef.cpp:76
NBOwnTLDef(const std::string &id, const std::vector< NBNode *> &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBOwnTLDef.cpp:54
void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic *logic, const std::string &state)
Definition: NBOwnTLDef.cpp:722
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:488
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBOwnTLDef.cpp:190
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
Definition: NBOwnTLDef.cpp:195
void collectLinks()
Collects the links participating in this traffic light.
Definition: NBOwnTLDef.cpp:536
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:459
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:40
double getDirectionalWeight(LinkDirection dir)
Returns the weight of a stream given its direction.
Definition: NBOwnTLDef.cpp:86
Represents a single node (junction) during network building.
Definition: NBNode.h:74
long long int SUMOTime
Definition: TraCIDefs.h:51
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:53
void initNeedsContRelation() const
Definition: NBOwnTLDef.cpp:564
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:433
int getToPrio(const NBEdge *const e)
Returns this edge&#39;s priority at the node it ends at.
Definition: NBOwnTLDef.cpp:80
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:554