SUMO - Simulation of Urban MObility
NBOwnTLDef.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // A traffic light logics which must be computed (only nodes/edges are given)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-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 NBOwnTLDef_h
23 #define NBOwnTLDef_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 <set>
39 #include "NBNode.h"
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
55 public:
62  NBOwnTLDef(const std::string& id,
63  const std::vector<NBNode*>& junctions,
64  SUMOTime offset,
65  TrafficLightType type);
66 
67 
74  NBOwnTLDef(const std::string& id, NBNode* junction, SUMOTime offset,
75  TrafficLightType type);
76 
77 
83  NBOwnTLDef(const std::string& id, SUMOTime offset, TrafficLightType type);
84 
85 
87  ~NBOwnTLDef();
88 
89 
92 
99  void remapRemoved(NBEdge* removed,
100  const EdgeVector& incoming, const EdgeVector& outgoing);
101 
102 
106  void setTLControllingInformation() const;
108 
109 
112  void setSinglePhase() {
113  myHaveSinglePhase = true;
114  }
115 
117  static void addPedestrianScramble(NBTrafficLightLogic* logic, int noLinksAll,
118  SUMOTime greenTime, SUMOTime yellowTime,
119  const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
120 
122  static std::string addPedestrianPhases(NBTrafficLightLogic* logic, SUMOTime greenTime,
123  SUMOTime minDur, SUMOTime maxDur,
124  std::string state, const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
125 
127  static std::string patchStateForCrossings(const std::string& state,
128  const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
129 
135  NBTrafficLightLogic* computeLogicAndConts(int brakingTimeSeconds, bool onlyConts = false);
136 
137  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
138  void initNeedsContRelation() const;
139 
140  /* build optional all-red phase */
141  void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic* logic, const std::string& state);
142 
143 protected:
146 
152  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
153 
154 
159  void collectLinks();
160 
161 
169  void replaceRemoved(NBEdge* removed, int removedLane,
170  NBEdge* by, int byLane);
172 
173 
174 protected:
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 allowFollowersOfChosen(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges);
224 
236  std::string correctConflicting(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
237  const std::vector<bool>& isTurnaround,
238  const std::vector<int>& fromLanes,
239  const std::vector<bool>& hadGreenMajor,
240  bool& haveForbiddenLeftMover, std::vector<bool>& rightTurnConflicts);
241 
246  public:
251  int operator()(const NBEdge* const e1, const NBEdge* const e2) const {
252  if (e1->getJunctionPriority(e1->getToNode()) != e2->getJunctionPriority(e2->getToNode())) {
253  return e1->getJunctionPriority(e1->getToNode()) > e2->getJunctionPriority(e2->getToNode());
254  }
255  return e1->getID() > e2->getID();
256  }
257  };
258 
259 
260 private:
263 
264 };
265 
266 
267 #endif
268 
269 /****************************************************************************/
270 
void setSinglePhase()
Forces the definition not to compute an additional phase for left-movers.
Definition: NBOwnTLDef.h:112
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:489
A SUMO-compliant built logic for a traffic light.
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:624
The representation of a single edge during network building.
Definition: NBEdge.h:71
std::string allowFollowersOfChosen(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges)
allow connections that follow on of the chosen edges
Definition: NBOwnTLDef.cpp:599
The base class for traffic light logic definitions.
static EdgeVector getConnectedOuterEdges(const EdgeVector &incoming)
get edges that have connections
Definition: NBOwnTLDef.cpp:585
std::pair< NBEdge *, NBEdge * > getBestPair(EdgeVector &incoming)
Returns the combination of two edges from the given which has most unblocked streams.
Definition: NBOwnTLDef.cpp:157
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
const std::string & getID() const
Returns the id.
Definition: Named.h:66
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:460
int operator()(const NBEdge *const e1, const NBEdge *const e2) const
comparing operator
Definition: NBOwnTLDef.h:251
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:668
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBOwnTLDef.cpp:560
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:130
bool myHaveSinglePhase
Whether left-mover should not have an additional phase.
Definition: NBOwnTLDef.h:262
~NBOwnTLDef()
Destructor.
Definition: NBOwnTLDef.cpp:77
void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic *logic, const std::string &state)
Definition: NBOwnTLDef.cpp:708
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition: NBEdge.cpp:1575
NBOwnTLDef(const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBOwnTLDef.cpp:55
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:435
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBOwnTLDef.cpp:191
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
Definition: NBOwnTLDef.cpp:196
void collectLinks()
Collects the links participating in this traffic light If a link could not be found.
Definition: NBOwnTLDef.cpp:537
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:41
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:75
void initNeedsContRelation() const
Definition: NBOwnTLDef.cpp:565
long long int SUMOTime
Definition: TraCIDefs.h:52
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:441
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:54
Sorts edges by their priority within the node they end at.
Definition: NBOwnTLDef.h:245
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBOwnTLDef.cpp:543
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:555