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-2023 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// ===========================================================================
45public:
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
78
79
82
89 void remapRemoved(NBEdge* removed,
90 const EdgeVector& incoming, const EdgeVector& outgoing);
91
92
96 void setTLControllingInformation() const;
98
99
102 myHaveSinglePhase = true;
103 }
104
106 static void addPedestrianScramble(NBTrafficLightLogic* logic, int totalNumLinks, SUMOTime greenTime, SUMOTime yellowTime,
107 const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
108
110 static std::string addPedestrianPhases(NBTrafficLightLogic* logic, const SUMOTime greenTime, const SUMOTime minDur, const SUMOTime maxDur,
111 const SUMOTime earliestEnd, const SUMOTime latestEnd,
112 std::string state, const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
113
115 static std::string patchStateForCrossings(const std::string& state, const std::vector<NBNode::Crossing*>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges);
116
122 NBTrafficLightLogic* computeLogicAndConts(int brakingTimeSeconds, bool onlyConts = false);
123
124 /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
125 void initNeedsContRelation() const;
126
127 /* build optional all-red phase */
128 void buildAllRedState(SUMOTime allRedTime, NBTrafficLightLogic* logic, const std::string& state);
129
131 int getMaxIndex();
132
135 myLayout = layout;
136 }
137
139 return myLayout;
140 }
141
143 static const double MIN_SPEED_CROSSING_TIME;
144
145protected:
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
176protected:
177
179 bool corridorLike() const;
180
182 const EdgeVector& fromEdges,
183 const std::vector<std::pair<NBEdge*, NBEdge*> >& chosenList,
184 const std::vector<std::string>& straightStates,
185 const std::vector<std::string>& leftStates);
186
188 std::string filterState(std::string state, const EdgeVector& fromEdges, const NBEdge* e);
189
191 void filterMissingNames(std::vector<int>& vec, const std::map<int, int>& names, bool isBarrier);
192
194 void fixDurationSum(NBTrafficLightLogic* logic, const std::map<int, int>& names, int ring1a, int ring1b, int ring2a, int ring2b);
195
202
203
208 int getToPrio(const NBEdge* const e);
209
210
216 double computeUnblockedWeightedStreamNumber(const NBEdge* const e1, const NBEdge* const e2);
217
218
223 std::pair<NBEdge*, NBEdge*> getBestCombination(const EdgeVector& edges);
224
225
233 std::pair<NBEdge*, NBEdge*> getBestPair(EdgeVector& incoming);
234
235
237 static bool hasCrossing(const NBEdge* from, const NBEdge* to, const std::vector<NBNode::Crossing*>& crossings);
238
240 static EdgeVector getConnectedOuterEdges(const EdgeVector& incoming);
241
242
244 std::string allowCompatible(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
245 const std::vector<int>& fromLanes, const std::vector<int>& toLanes);
246
247 std::string allowSingleEdge(std::string state, const EdgeVector& fromEdges);
248
249 std::string allowFollowers(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges);
250
251 std::string allowPredecessors(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
252 const std::vector<int>& fromLanes, const std::vector<int>& toLanes);
253
254 std::string allowUnrelated(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
255 const std::vector<bool>& isTurnaround,
256 const std::vector<NBNode::Crossing*>& crossings);
257
258 std::string allowByVClass(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges, SVCPermissions perm);
259
261 bool forbidden(const std::string& state, int index, const EdgeVector& fromEdges, const EdgeVector& toEdges);
262
275 std::string correctConflicting(std::string state, const EdgeVector& fromEdges, const EdgeVector& toEdges,
276 const std::vector<bool>& isTurnaround,
277 const std::vector<int>& fromLanes,
278 const std::vector<int>& toLanes,
279 const std::vector<bool>& hadGreenMajor,
280 bool& haveForbiddenLeftMover,
281 std::vector<bool>& rightTurnConflicts,
282 std::vector<bool>& mergeConflicts);
283
285 std::string correctMixed(std::string state, const EdgeVector& fromEdges,
286 const std::vector<int>& fromLanes,
287 bool& buildMixedGreenPhase, std::vector<bool>& mixedGreen);
288
291
293 void fixSuperfluousYellow(NBTrafficLightLogic* logic) const;
294
297
299 void deactivateInsideEdges(NBTrafficLightLogic* logic, const EdgeVector& fromEdges) const;
300
302 SUMOTime computeEscapeTime(const std::string& state, const EdgeVector& fromEdges, const EdgeVector& toEdges) const;
303
305 bool hasStraightConnection(const NBEdge* fromEdge);
306
311 public:
316 int operator()(const NBEdge* const e1, const NBEdge* const e2) const {
317 if (e1->getJunctionPriority(e1->getToNode()) != e2->getJunctionPriority(e2->getToNode())) {
318 return e1->getJunctionPriority(e1->getToNode()) > e2->getJunctionPriority(e2->getToNode());
319 }
320 return e1->getID() > e2->getID();
321 }
322 };
323
324
325private:
328
331
332};
long long int SUMOTime
Definition: GUI.h:36
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:42
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:92
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:536
const std::string & getID() const
Definition: NBEdge.h:1515
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition: NBEdge.cpp:2048
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:310
int operator()(const NBEdge *const e1, const NBEdge *const e2) const
comparing operator
Definition: NBOwnTLDef.h:316
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:101
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
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
void setLayout(TrafficLightLayout layout)
sets the layout for the generated signal plan
Definition: NBOwnTLDef.h:134
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:880
std::string allowByVClass(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, SVCPermissions perm)
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:327
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:952
std::pair< NBEdge *, NBEdge * > getBestPair(EdgeVector &incoming)
Returns the combination of two edges from the given which has most unblocked streams.
Definition: NBOwnTLDef.cpp:221
~NBOwnTLDef()
Destructor.
Definition: NBOwnTLDef.cpp:85
void collectLinks()
Collects the links participating in this traffic light.
Definition: NBOwnTLDef.cpp:928
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:274
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:830
std::string allowPredecessors(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, const std::vector< int > &fromLanes, const std::vector< int > &toLanes)
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:111
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurrences of the removed edge in incoming/outgoing edges of all definitions.
Definition: NBOwnTLDef.cpp:947
int getToPrio(const NBEdge *const e)
Returns this edge's priority at the node it ends at.
Definition: NBOwnTLDef.cpp:89
NBTrafficLightLogic * buildNemaPhases(const EdgeVector &fromEdges, const std::vector< std::pair< NBEdge *, NBEdge * > > &chosenList, const std::vector< std::string > &straightStates, const std::vector< std::string > &leftStates)
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:991
std::string correctMixed(std::string state, const EdgeVector &fromEdges, const std::vector< int > &fromLanes, bool &buildMixedGreenPhase, std::vector< bool > &mixedGreen)
prevent green and red from the same lane
void fixDurationSum(NBTrafficLightLogic *logic, const std::map< int, int > &names, int ring1a, int ring1b, int ring2a, int ring2b)
ensure that phase max durations before each barrier have the same sum in both rings
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBOwnTLDef.cpp:268
std::string filterState(std::string state, const EdgeVector &fromEdges, const NBEdge *e)
mask out all greens that do not originate at the given edge
TrafficLightLayout getLayout() const
Definition: NBOwnTLDef.h:138
std::string allowFollowers(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges)
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:95
std::string allowSingleEdge(std::string state, const EdgeVector &fromEdges)
bool hasStraightConnection(const NBEdge *fromEdge)
check whether there is a straight connection from this edge
Definition: NBOwnTLDef.cpp:257
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:182
void initNeedsContRelation() const
Definition: NBOwnTLDef.cpp:957
static void addPedestrianScramble(NBTrafficLightLogic *logic, int totalNumLinks, 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
NBOwnTLDef(const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBOwnTLDef.cpp:60
static EdgeVector getConnectedOuterEdges(const EdgeVector &incoming)
get edges that have connections
Definition: NBOwnTLDef.cpp:977
void filterMissingNames(std::vector< int > &vec, const std::map< int, int > &names, bool isBarrier)
keep only valid NEMA phase names (for params)
TrafficLightLayout myLayout
the layout for generated signal plans
Definition: NBOwnTLDef.h:330
static std::string addPedestrianPhases(NBTrafficLightLogic *logic, const SUMOTime greenTime, const SUMOTime minDur, const SUMOTime maxDur, const SUMOTime earliestEnd, const SUMOTime latestEnd, 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:849
std::string allowUnrelated(std::string state, const EdgeVector &fromEdges, const EdgeVector &toEdges, const std::vector< bool > &isTurnaround, const std::vector< NBNode::Crossing * > &crossings)
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBOwnTLDef.cpp:935
static const double MIN_SPEED_CROSSING_TIME
minimum speed for computing time to cross intersection
Definition: NBOwnTLDef.h:143
The base class for traffic light logic definitions.
A SUMO-compliant built logic for a traffic light.