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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // A traffic light logics which must be computed (only nodes/edges are given)
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 
25 #include <vector>
26 #include <set>
29 #include "NBNode.h"
30 
31 
32 // ===========================================================================
33 // class declarations
34 // ===========================================================================
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
45 public:
52  NBOwnTLDef(const std::string& id,
53  const std::vector<NBNode*>& junctions,
54  SUMOTime offset,
55  TrafficLightType type);
56 
57 
64  NBOwnTLDef(const std::string& id, NBNode* junction, SUMOTime offset,
65  TrafficLightType type);
66 
67 
73  NBOwnTLDef(const std::string& id, SUMOTime offset, TrafficLightType type);
74 
75 
77  ~NBOwnTLDef();
78 
79 
82 
89  void remapRemoved(NBEdge* removed,
90  const EdgeVector& incoming, const EdgeVector& outgoing);
91 
92 
96  void setTLControllingInformation() const;
98 
99 
102  void setSinglePhase() {
103  myHaveSinglePhase = true;
104  }
105 
107  static void addPedestrianScramble(NBTrafficLightLogic* logic, int noLinksAll,
108  SUMOTime greenTime, SUMOTime yellowTime,
109  const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
110 
112  static std::string addPedestrianPhases(NBTrafficLightLogic* logic, SUMOTime greenTime,
113  SUMOTime minDur, SUMOTime maxDur,
114  std::string state, const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
115 
117  static std::string patchStateForCrossings(const std::string& state,
118  const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
119 
125  NBTrafficLightLogic* computeLogicAndConts(int brakingTimeSeconds, bool onlyConts = false);
126 
127  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
128  void initNeedsContRelation() const;
129 
130  /* build optional all-red phase */
131  void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic* logic, const std::string& state);
132 
134  int getMaxIndex();
135 
138  myLayout = layout;
139  }
140 
142  return myLayout;
143  }
144 
145 protected:
148 
154  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
155 
156 
161  void collectLinks();
162 
163 
171  void replaceRemoved(NBEdge* removed, int removedLane,
172  NBEdge* by, int byLane, bool incoming);
174 
175 
176 protected:
177 
179  bool corridorLike() const;
180 
187 
188 
193  int getToPrio(const NBEdge* const e);
194 
195 
201  double computeUnblockedWeightedStreamNumber(const NBEdge* const e1, const NBEdge* const e2);
202 
203 
208  std::pair<NBEdge*, NBEdge*> getBestCombination(const EdgeVector& edges);
209 
210 
218  std::pair<NBEdge*, NBEdge*> getBestPair(EdgeVector& incoming);
219 
220 
222  static bool hasCrossing(const NBEdge* from, const NBEdge* to, const std::vector<NBNode::Crossing*>& crossings);
223 
225  static EdgeVector getConnectedOuterEdges(const EdgeVector& incoming);
226 
227 
229  std::string allowCompatible(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
230  const std::vector<int>& fromLanes, const std::vector<int>& toLanes);
231 
232  std::string allowSingleEdge(std::string state, const EdgeVector& fromEdges);
233 
234  std::string allowFollowers(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges);
235 
236  std::string allowPredecessors(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
237  const std::vector<int>& fromLanes, const std::vector<int>& toLanes);
238 
239  std::string allowUnrelated(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
240  const std::vector<bool>& isTurnaround,
241  const std::vector<NBNode::Crossing*>& crossings);
242 
243  std::string allowByVClass(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges, SVCPermissions perm);
244 
246  bool forbidden(const std::string& state, int index, const EdgeVector& fromEdges, const EdgeVector& toEdges);
247 
260  std::string correctConflicting(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
261  const std::vector<bool>& isTurnaround,
262  const std::vector<int>& fromLanes,
263  const std::vector<int>& toLanes,
264  const std::vector<bool>& hadGreenMajor,
265  bool& haveForbiddenLeftMover,
266  std::vector<bool>& rightTurnConflicts,
267  std::vector<bool>& mergeConflicts);
268 
271 
273  void fixSuperfluousYellow(NBTrafficLightLogic* logic) const;
274 
276  void deactivateAlwaysGreen(NBTrafficLightLogic* logic) const;
277 
279  void deactivateInsideEdges(NBTrafficLightLogic* logic, const EdgeVector& fromEdges) const;
280 
282  SUMOTime computeEscapeTime(const std::string& state, const EdgeVector& fromEdges, const EdgeVector& toEdges) const;
283 
288  public:
293  int operator()(const NBEdge* const e1, const NBEdge* const e2) const {
294  if (e1->getJunctionPriority(e1->getToNode()) != e2->getJunctionPriority(e2->getToNode())) {
295  return e1->getJunctionPriority(e1->getToNode()) > e2->getJunctionPriority(e2->getToNode());
296  }
297  return e1->getID() > e2->getID();
298  }
299  };
300 
301 
302 private:
305 
308 
309 };
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
long long int SUMOTime
Definition: SUMOTime.h:31
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
TrafficLightType
TrafficLightLayout
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
The representation of a single edge during network building.
Definition: NBEdge.h:91
const std::string & getID() const
Definition: NBEdge.h:1423
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:516
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition: NBEdge.cpp:1920
Represents a single node (junction) during network building.
Definition: NBNode.h:66
Sorts edges by their priority within the node they end at.
Definition: NBOwnTLDef.h:287
int operator()(const NBEdge *const e1, const NBEdge *const e2) const
comparing operator
Definition: NBOwnTLDef.h:293
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:44
void setSinglePhase()
Forces the definition not to compute an additional phase for left-movers.
Definition: NBOwnTLDef.h:102
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:942
void fixSuperfluousYellow(NBTrafficLightLogic *logic) const
avoid yellow signal between successive green (major) phases
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< int > &toLanes, const std::vector< bool > &hadGreenMajor, bool &haveForbiddenLeftMover, std::vector< bool > &rightTurnConflicts, std::vector< bool > &mergeConflicts)
change 'G' to 'g' for conflicting connections
Definition: NBOwnTLDef.cpp:953
void setLayout(TrafficLightLayout layout)
sets the layout for the generated signal plan
Definition: NBOwnTLDef.h:137
void checkCustomCrossingIndices(NBTrafficLightLogic *logic) const
fix states in regard to custom crossing indices
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:697
std::string allowByVClass(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, SVCPermissions perm)
Definition: NBOwnTLDef.cpp:930
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
bool myHaveSinglePhase
Whether left-mover should not have an additional phase.
Definition: NBOwnTLDef.h:304
bool corridorLike() const
test whether a joined tls with layout 'opposites' would be built without dedicated left-turn phase
SUMOTime computeEscapeTime(const std::string &state, const EdgeVector &fromEdges, const EdgeVector &toEdges) const
compute time to clear all vehicles from within an alternateOneWay layout
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane, bool incoming)
Replaces a removed edge/lane.
Definition: NBOwnTLDef.cpp:769
std::pair< NBEdge *, NBEdge * > getBestPair(EdgeVector &incoming)
Returns the combination of two edges from the given which has most unblocked streams.
Definition: NBOwnTLDef.cpp:200
~NBOwnTLDef()
Destructor.
Definition: NBOwnTLDef.cpp:78
void collectLinks()
Collects the links participating in this traffic light.
Definition: NBOwnTLDef.cpp:745
void deactivateAlwaysGreen(NBTrafficLightLogic *logic) const
switch of signal for links that are always green
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
Definition: NBOwnTLDef.cpp:241
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:647
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:873
void deactivateInsideEdges(NBTrafficLightLogic *logic, const EdgeVector &fromEdges) const
switch of signal for links that are inside a joined tls
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:104
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:764
int getToPrio(const NBEdge *const e)
Returns this edge's priority at the node it ends at.
Definition: NBOwnTLDef.cpp:82
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:808
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBOwnTLDef.cpp:236
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:666
TrafficLightLayout getLayout() const
Definition: NBOwnTLDef.h:141
std::string allowFollowers(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges)
Definition: NBOwnTLDef.cpp:843
void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic *logic, const std::string &state)
double getDirectionalWeight(LinkDirection dir)
Returns the weight of a stream given its direction.
Definition: NBOwnTLDef.cpp:88
std::string allowSingleEdge(std::string state, const EdgeVector &fromEdges)
Definition: NBOwnTLDef.cpp:818
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:163
void initNeedsContRelation() const
Definition: NBOwnTLDef.cpp:774
NBOwnTLDef(const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBOwnTLDef.cpp:53
static EdgeVector getConnectedOuterEdges(const EdgeVector &incoming)
get edges that have connections
Definition: NBOwnTLDef.cpp:794
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
TrafficLightLayout myLayout
the layout for generated signal plans
Definition: NBOwnTLDef.h:307
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:906
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBOwnTLDef.cpp:752
The base class for traffic light logic definitions.
A SUMO-compliant built logic for a traffic light.