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 /****************************************************************************/
16 // A traffic light logics which must be computed (only nodes/edges are given)
17 /****************************************************************************/
18 #ifndef NBOwnTLDef_h
19 #define NBOwnTLDef_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <set>
31 #include "NBNode.h"
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
47 public:
54  NBOwnTLDef(const std::string& id,
55  const std::vector<NBNode*>& junctions,
56  SUMOTime offset,
57  TrafficLightType type);
58 
59 
66  NBOwnTLDef(const std::string& id, NBNode* junction, SUMOTime offset,
67  TrafficLightType type);
68 
69 
75  NBOwnTLDef(const std::string& id, SUMOTime offset, TrafficLightType type);
76 
77 
79  ~NBOwnTLDef();
80 
81 
84 
91  void remapRemoved(NBEdge* removed,
92  const EdgeVector& incoming, const EdgeVector& outgoing);
93 
94 
98  void setTLControllingInformation() const;
100 
101 
104  void setSinglePhase() {
105  myHaveSinglePhase = true;
106  }
107 
109  static void addPedestrianScramble(NBTrafficLightLogic* logic, int noLinksAll,
110  SUMOTime greenTime, SUMOTime yellowTime,
111  const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
112 
114  static std::string addPedestrianPhases(NBTrafficLightLogic* logic, SUMOTime greenTime,
115  SUMOTime minDur, SUMOTime maxDur,
116  std::string state, const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
117 
119  static std::string patchStateForCrossings(const std::string& state,
120  const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
121 
127  NBTrafficLightLogic* computeLogicAndConts(int brakingTimeSeconds, bool onlyConts = false);
128 
129  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
130  void initNeedsContRelation() const;
131 
132  /* build optional all-red phase */
133  void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic* logic, const std::string& state);
134 
136  int getMaxIndex();
137 
138 protected:
141 
147  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
148 
149 
154  void collectLinks();
155 
156 
164  void replaceRemoved(NBEdge* removed, int removedLane,
165  NBEdge* by, int byLane);
167 
168 
169 protected:
170 
172  bool corridorLike() const;
173 
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 allowCompatible(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
223  const std::vector<int>& fromLanes, const std::vector<int>& toLanes);
224 
225  std::string allowSingleEdge(std::string state, const EdgeVector& fromEdges);
226 
227  std::string allowFollowers(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges);
228 
229  std::string allowPredecessors(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
230  const std::vector<int>& fromLanes, const std::vector<int>& toLanes);
231 
232  std::string allowUnrelated(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
233  const std::vector<bool>& isTurnaround,
234  const std::vector<NBNode::Crossing*>& crossings);
235 
236  std::string allowByVClass(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges, SVCPermissions perm);
237 
239  bool forbidden(const std::string& state, int index, const EdgeVector& fromEdges, const EdgeVector& toEdges);
240 
252  std::string correctConflicting(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
253  const std::vector<bool>& isTurnaround,
254  const std::vector<int>& fromLanes,
255  const std::vector<bool>& hadGreenMajor,
256  bool& haveForbiddenLeftMover, std::vector<bool>& rightTurnConflicts);
257 
260 
265  public:
270  int operator()(const NBEdge* const e1, const NBEdge* const e2) const {
271  if (e1->getJunctionPriority(e1->getToNode()) != e2->getJunctionPriority(e2->getToNode())) {
272  return e1->getJunctionPriority(e1->getToNode()) > e2->getJunctionPriority(e2->getToNode());
273  }
274  return e1->getID() > e2->getID();
275  }
276  };
277 
278 
279 private:
282 
283 };
284 
285 
286 #endif
287 
288 /****************************************************************************/
289 
NBOwnTLDef::replaceRemoved
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBOwnTLDef.cpp:752
NBOwnTLDef::getConnectedOuterEdges
static EdgeVector getConnectedOuterEdges(const EdgeVector &incoming)
get edges that have connections
Definition: NBOwnTLDef.cpp:777
NBOwnTLDef::NBOwnTLDef
NBOwnTLDef(const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBOwnTLDef.cpp:54
NBOwnTLDef::initNeedsContRelation
void initNeedsContRelation() const
Definition: NBOwnTLDef.cpp:757
NBOwnTLDef::addPedestrianPhases
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:650
NBOwnTLDef::edge_by_incoming_priority_sorter
Sorts edges by their priority within the node they end at.
Definition: NBOwnTLDef.h:264
EdgeVector
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
NBOwnTLDef::buildAllRedState
void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic *logic, const std::string &state)
Definition: NBOwnTLDef.cpp:1037
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1197
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
NBOwnTLDef::addPedestrianScramble
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:995
NBOwnTLDef
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:46
NBTrafficLightDefinition.h
NBOwnTLDef::allowSingleEdge
std::string allowSingleEdge(std::string state, const EdgeVector &fromEdges)
Definition: NBOwnTLDef.cpp:801
NBOwnTLDef::hasCrossing
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:631
NBOwnTLDef::~NBOwnTLDef
~NBOwnTLDef()
Destructor.
Definition: NBOwnTLDef.cpp:76
LinkDirection
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
Definition: SUMOXMLDefinitions.h:1176
NBOwnTLDef::allowCompatible
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:791
NBOwnTLDef::collectLinks
void collectLinks()
Collects the links participating in this traffic light.
Definition: NBOwnTLDef.cpp:729
NBOwnTLDef::allowUnrelated
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:889
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NBEdge::getToNode
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:498
NBOwnTLDef::corridorLike
bool corridorLike() const
test whether a joined tls with layout 'opposites' would be built without dedicated left-turn phase
Definition: NBOwnTLDef.cpp:1087
SVCPermissions
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
Definition: SUMOVehicleClass.h:218
NBOwnTLDef::remapRemoved
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:747
NBOwnTLDef::setSinglePhase
void setSinglePhase()
Forces the definition not to compute an additional phase for left-movers.
Definition: NBOwnTLDef.h:104
NBOwnTLDef::forbidden
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:925
NBOwnTLDef::edge_by_incoming_priority_sorter::operator()
int operator()(const NBEdge *const e1, const NBEdge *const e2) const
comparing operator
Definition: NBOwnTLDef.h:270
NBOwnTLDef::getBestPair
std::pair< NBEdge *, NBEdge * > getBestPair(EdgeVector &incoming)
Returns the combination of two edges from the given which has most unblocked streams.
Definition: NBOwnTLDef.cpp:198
NBOwnTLDef::getToPrio
int getToPrio(const NBEdge *const e)
Returns this edge's priority at the node it ends at.
Definition: NBOwnTLDef.cpp:80
NBOwnTLDef::getDirectionalWeight
double getDirectionalWeight(LinkDirection dir)
Returns the weight of a stream given its direction.
Definition: NBOwnTLDef.cpp:86
NBOwnTLDef::computeLogicAndConts
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
Definition: NBOwnTLDef.cpp:239
NBOwnTLDef::patchStateForCrossings
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:681
NBEdge::getJunctionPriority
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition: NBEdge.cpp:1816
NBOwnTLDef::allowByVClass
std::string allowByVClass(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, SVCPermissions perm)
Definition: NBOwnTLDef.cpp:913
NBOwnTLDef::computeUnblockedWeightedStreamNumber
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
NBOwnTLDef::correctConflicting
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 'G' to 'g' for conflicting connections
Definition: NBOwnTLDef.cpp:936
config.h
NBOwnTLDef::allowFollowers
std::string allowFollowers(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges)
Definition: NBOwnTLDef.cpp:826
NBTrafficLightLogic
A SUMO-compliant built logic for a traffic light.
Definition: NBTrafficLightLogic.h:51
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:67
NBOwnTLDef::setTLControllingInformation
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBOwnTLDef.cpp:735
NBNode.h
SUMOXMLDefinitions.h
NBOwnTLDef::myHaveSinglePhase
bool myHaveSinglePhase
Whether left-mover should not have an additional phase.
Definition: NBOwnTLDef.h:281
NBOwnTLDef::getBestCombination
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:161
NBOwnTLDef::myCompute
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBOwnTLDef.cpp:234
NBOwnTLDef::checkCustomCrossingIndices
void checkCustomCrossingIndices(NBTrafficLightLogic *logic) const
fix states in regard to custom crossing indices
Definition: NBOwnTLDef.cpp:1051
NBTrafficLightDefinition
The base class for traffic light logic definitions.
Definition: NBTrafficLightDefinition.h:67
NBOwnTLDef::getMaxIndex
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
Definition: NBOwnTLDef.cpp:1075
NBOwnTLDef::allowPredecessors
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:856
NBEdge::getID
const std::string & getID() const
Definition: NBEdge.h:1380