Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NBTrafficLightDefinition.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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// The base class for traffic light logic definitions
21/****************************************************************************/
22#include <config.h>
23
24#include <vector>
25#include <string>
26#include <algorithm>
27#include <cassert>
28#include <iterator>
34#include "NBTrafficLightLogic.h"
35#include "NBOwnTLDef.h"
36#include "NBContHelper.h"
37
38//#define DEBUG_RIGHT_OF_WAY
39#define DEBUGCOND true
40
41// ===========================================================================
42// static members
43// ===========================================================================
44const std::string NBTrafficLightDefinition::DefaultProgramID = "0";
45const std::string NBTrafficLightDefinition::DummyID = "dummy";
48const std::string NBTrafficLightDefinition::OSM_DIRECTION("osm:direction");
49const std::string NBTrafficLightDefinition::OSM_SIGNAL_DIRECTION("railway:signal:direction");
50
51
52// ===========================================================================
53// method definitions
54// ===========================================================================
56 const std::vector<NBNode*>& junctions, const std::string& programID,
57 SUMOTime offset, TrafficLightType type) :
58 Named(id),
59 myControlledNodes(junctions),
60 mySubID(programID), myOffset(offset),
61 myType(type),
62 myNeedsContRelationReady(false),
63 myRightOnRedConflictsReady(false) {
64 std::vector<NBNode*>::iterator i = myControlledNodes.begin();
65 while (i != myControlledNodes.end()) {
66 for (std::vector<NBNode*>::iterator j = i + 1; j != myControlledNodes.end();) {
67 if (*i == *j) {
68 j = myControlledNodes.erase(j);
69 } else {
70 j++;
71 }
72 }
73 i++;
74 }
76 for (NBNode* const node : junctions) {
77 node->addTrafficLight(this);
78 }
79}
80
81
83 NBNode* junction, const std::string& programID, SUMOTime offset, TrafficLightType type) :
84 Named(id),
85 mySubID(programID),
86 myOffset(offset),
87 myType(type),
88 myNeedsContRelationReady(false),
89 myRightOnRedConflictsReady(false) {
90 addNode(junction);
91}
92
93
94NBTrafficLightDefinition::NBTrafficLightDefinition(const std::string& id, const std::string& programID,
95 SUMOTime offset, TrafficLightType type) :
96 Named(id),
97 mySubID(programID),
98 myOffset(offset),
99 myType(type),
100 myNeedsContRelationReady(false),
101 myRightOnRedConflictsReady(false) {
102}
103
104
106
107
110 // it is not really a traffic light if no incoming edge exists
111 if (amInvalid()) {
112 // make a copy of myControlledNodes because it will be modified;
113 std::vector<NBNode*> nodes = myControlledNodes;
114 for (auto it : nodes) {
115 it->removeTrafficLight(this);
116 }
117 WRITE_WARNINGF(TL("The traffic light '%' does not control any links; it will not be build."), getID());
118 return nullptr;
119 }
120 // compute the time needed to brake
121 int brakingTime = computeBrakingTime(oc.getFloat("tls.yellow.min-decel"));
122 // perform the computation depending on whether the traffic light
123 // definition was loaded or shall be computed new completely
124 if (!oc.isDefault("tls.yellow.time")) {
125 brakingTime = oc.getInt("tls.yellow.time");
126 }
127 NBTrafficLightLogic* ret = myCompute(brakingTime);
129 return ret;
130}
131
132
133bool
135 return myControlledLinks.size() == 0;
136}
137
138
139int
141 if (myIncomingEdges.empty()) {
142 // don't crash
143 return MIN_YELLOW_SECONDS;
144 }
145 const double vmax = NBContHelper::maxSpeed(myIncomingEdges);
146 if (vmax < 71 / 3.6) {
147 // up to 50kmh: 3 seconds , 60km/h: 4, 70kmh: 5
148 // @note: these are German regulations, other countries may differ
149 return MIN_YELLOW_SECONDS + (int)MAX2(0.0, (floor((vmax - 50 / 3.6) * 0.37)));
150 } else {
151 // above 70km/h we use a function that grows according to the "natural"
152 // formula (vmax / 2 * minDecel) but continues smoothly where the german
153 // rules leave of
154 return (int)(1.8 + vmax / 2 / minDecel);
155 }
156}
157
158
159void
161 // collect the information about participating edges and links
162 collectEdges();
163 collectLinks();
164}
165
166std::set<NBEdge*>
167NBTrafficLightDefinition::collectReachable(EdgeVector outer, const EdgeVector& within, bool checkControlled) {
168 std::set<NBEdge*> reachable;
169 while (outer.size() > 0) {
170 NBEdge* from = outer.back();
171 outer.pop_back();
172 std::vector<NBEdge::Connection>& cons = from->getConnections();
173 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); k++) {
174 NBEdge* to = (*k).toEdge;
175 if (reachable.count(to) == 0 &&
176 (find(within.begin(), within.end(), to) != within.end()) &&
177 (!checkControlled || from->mayBeTLSControlled((*k).fromLane, to, (*k).toLane))) {
178 reachable.insert(to);
179 outer.push_back(to);
180 }
181 }
182 }
183 return reachable;
184}
185
186
187void
189 myIncomingEdges.clear();
190 myEdgesWithin.clear();
191 EdgeVector myOutgoing;
192 // collect the edges from the participating nodes
193 for (std::vector<NBNode*>::iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
194 const EdgeVector& incoming = (*i)->getIncomingEdges();
195 copy(incoming.begin(), incoming.end(), back_inserter(myIncomingEdges));
196 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
197 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
198 }
199 EdgeVector outer;
200 // check which of the edges are completely within the junction
201 // add them to the list of edges lying within the node
202 for (NBEdge* edge : myIncomingEdges) {
203 edge->setInsideTLS(false); // reset
204 // an edge lies within the logic if it is outgoing as well as incoming
205 EdgeVector::iterator k = std::find(myOutgoing.begin(), myOutgoing.end(), edge);
206 if (k != myOutgoing.end()) {
207 myEdgesWithin.push_back(edge);
208 } else {
209 outer.push_back(edge);
210 }
211 }
212 // collect edges that are reachable from the outside via controlled connections
213 std::set<NBEdge*> reachable = collectReachable(outer, myEdgesWithin, true);
214 // collect edges that are reachable from the outside regardless of controllability
215 std::set<NBEdge*> reachable2 = collectReachable(outer, myEdgesWithin, false);
216
217 const bool uncontrolledWithin = OptionsCont::getOptions().getBool("tls.uncontrolled-within");
218 for (EdgeVector::iterator j = myEdgesWithin.begin(); j != myEdgesWithin.end(); ++j) {
219 NBEdge* edge = *j;
220 // edges that are marked as 'inner' will not get their own phase when
221 // computing traffic light logics (unless they cannot be reached from the outside at all)
222 if (reachable.count(edge) == 1) {
223 edge->setInsideTLS(true);
224 // legacy behavior
225 if (uncontrolledWithin && myControlledInnerEdges.count(edge->getID()) == 0) {
226 myIncomingEdges.erase(find(myIncomingEdges.begin(), myIncomingEdges.end(), edge));
227 }
228 }
229 if (reachable2.count(edge) == 0 && edge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD, true) >= 0
230 && getID() != DummyID) {
231 WRITE_WARNINGF(TL("Unreachable edge '%' within tlLogic '%'"), edge->getID(), getID());
232 }
233 }
234}
235
236
237bool
238NBTrafficLightDefinition::mustBrake(const NBEdge* const from, const NBEdge* const to) const {
239 std::vector<NBNode*>::const_iterator i =
240 find_if(myControlledNodes.begin(), myControlledNodes.end(),
242 assert(i != myControlledNodes.end());
243 NBNode* node = *i;
244 if (!node->hasOutgoing(to)) {
245 return true; // !!!
246 }
247 // @todo recheck relevance of lane indices
248 return node->mustBrake(from, to, -1, -1, true);
249}
250
251
252bool
253NBTrafficLightDefinition::mustBrake(const NBEdge* const possProhibitedFrom,
254 const NBEdge* const possProhibitedTo,
255 const NBEdge* const possProhibitorFrom,
256 const NBEdge* const possProhibitorTo,
257 bool regardNonSignalisedLowerPriority) const {
258 return forbids(possProhibitorFrom, possProhibitorTo,
259 possProhibitedFrom, possProhibitedTo,
260 regardNonSignalisedLowerPriority);
261}
262
263
264bool
266 const NBConnection& possProhibitor,
267 bool regardNonSignalisedLowerPriority) const {
268 return forbids(possProhibitor.getFrom(), possProhibitor.getTo(),
269 possProhibited.getFrom(), possProhibited.getTo(),
270 regardNonSignalisedLowerPriority);
271}
272
273
274bool
275NBTrafficLightDefinition::forbids(const NBEdge* const possProhibitorFrom,
276 const NBEdge* const possProhibitorTo,
277 const NBEdge* const possProhibitedFrom,
278 const NBEdge* const possProhibitedTo,
279 bool regardNonSignalisedLowerPriority,
280 bool sameNodeOnly) const {
281 if (possProhibitorFrom == nullptr || possProhibitorTo == nullptr || possProhibitedFrom == nullptr || possProhibitedTo == nullptr) {
282 return false;
283 }
284 // retrieve both nodes
285 std::vector<NBNode*>::const_iterator incoming =
286 find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorFrom));
287 std::vector<NBNode*>::const_iterator outgoing =
288 find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_outgoing_finder(possProhibitedTo));
289 assert(incoming != myControlledNodes.end());
290 NBNode* incnode = *incoming;
291 NBNode* outnode = *outgoing;
292 EdgeVector::const_iterator i;
293
294#ifdef DEBUG_RIGHT_OF_WAY
295 if (DEBUGCOND) {
296 std::cout << "foribds tls=" << getID() << " from=" << possProhibitedFrom->getID() << " to=" << possProhibitedTo->getID() << " foeFrom=" << possProhibitorFrom->getID() << " foeTo=" << possProhibitorTo->getID() << " rnslp=" << regardNonSignalisedLowerPriority << " sameNodeOnly=" << sameNodeOnly;
297 }
298#endif
299 if (incnode != outnode) {
300 if (sameNodeOnly) {
301#ifdef DEBUG_RIGHT_OF_WAY
302 if (DEBUGCOND) {
303 std::cout << " differentNodes: allows (no check)\n";
304 }
305#endif
306 return false;
307 }
308 // the links are located at different nodes
309 const EdgeVector& ev1 = possProhibitedTo->getConnectedEdges();
310 // go through the following edge,
311 // check whether one of these connections is prohibited
312 for (i = ev1.begin(); i != ev1.end(); ++i) {
313 std::vector<NBNode*>::const_iterator outgoing2 =
315 if (outgoing2 == myControlledNodes.end()) {
316 continue;
317 }
318 NBNode* outnode2 = *outgoing2;
319 if (incnode != outnode2) {
320 continue;
321 }
322 if (incnode->getDirection(possProhibitedTo, *i) != LinkDirection::STRAIGHT) {
323 continue;
324 }
325 bool ret1 = incnode->foes(possProhibitorFrom, possProhibitorTo,
326 possProhibitedTo, *i);
327 bool ret2 = incnode->forbids(possProhibitorFrom, possProhibitorTo,
328 possProhibitedTo, *i,
329 regardNonSignalisedLowerPriority);
330 bool ret = ret1 || ret2;
331 if (ret) {
332#ifdef DEBUG_RIGHT_OF_WAY
333 if (DEBUGCOND) {
334 std::cout << " differentNodes: forbids\n";
335 }
336#endif
337 return true;
338 }
339 }
340
341 const EdgeVector& ev2 = possProhibitorTo->getConnectedEdges();
342 // go through the following edge,
343 // check whether one of these connections is prohibited
344 for (i = ev2.begin(); i != ev2.end(); ++i) {
345 std::vector<NBNode*>::const_iterator incoming2 =
346 find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorTo));
347 if (incoming2 == myControlledNodes.end()) {
348 continue;
349 }
350 NBNode* incnode2 = *incoming2;
351 if (incnode2 != outnode) {
352 continue;
353 }
354 if (incnode2->getDirection(possProhibitorTo, *i) != LinkDirection::STRAIGHT) {
355 continue;
356 }
357 bool ret1 = incnode2->foes(possProhibitorTo, *i,
358 possProhibitedFrom, possProhibitedTo);
359 bool ret2 = incnode2->forbids(possProhibitorTo, *i,
360 possProhibitedFrom, possProhibitedTo,
361 regardNonSignalisedLowerPriority);
362 bool ret = ret1 || ret2;
363 if (ret) {
364#ifdef DEBUG_RIGHT_OF_WAY
365 if (DEBUGCOND) {
366 std::cout << " differentNodes: forbids (2)\n";
367 }
368#endif
369 return true;
370 }
371 }
372#ifdef DEBUG_RIGHT_OF_WAY
373 if (DEBUGCOND) {
374 std::cout << " differentNodes: allows\n";
375 }
376#endif
377 return false;
378 }
379 // both links are located at the same node
380 // check using this node's information
381 const bool result = incnode->forbids(possProhibitorFrom, possProhibitorTo,
382 possProhibitedFrom, possProhibitedTo,
383 regardNonSignalisedLowerPriority);
384#ifdef DEBUG_RIGHT_OF_WAY
385 if (DEBUGCOND) {
386 std::cout << " sameNodes: " << (result ? "forbids" : "allows") << "\n";
387 }
388#endif
389 return result;
390}
391
392
393bool
394NBTrafficLightDefinition::foes(const NBEdge* const from1, const NBEdge* const to1,
395 const NBEdge* const from2, const NBEdge* const to2) const {
396 if (to1 == nullptr || to2 == nullptr) {
397 return false;
398 }
399 // retrieve both nodes (it is possible that a connection
400 std::vector<NBNode*>::const_iterator incoming =
401 find_if(myControlledNodes.begin(), myControlledNodes.end(),
403 std::vector<NBNode*>::const_iterator outgoing =
404 find_if(myControlledNodes.begin(), myControlledNodes.end(),
406 assert(incoming != myControlledNodes.end());
407 NBNode* incnode = *incoming;
408 NBNode* outnode = *outgoing;
409 if (incnode != outnode) {
410 return false;
411 }
412 return incnode->foes(from1, to1, from2, to2);
413}
414
415
416void
418 if (std::find(myControlledNodes.begin(), myControlledNodes.end(), node) == myControlledNodes.end()) {
419 myControlledNodes.push_back(node);
421 }
422 node->addTrafficLight(this);
423}
424
425
426void
428 std::vector<NBNode*>::iterator i = std::find(myControlledNodes.begin(), myControlledNodes.end(), node);
429 if (i != myControlledNodes.end()) {
430 myControlledNodes.erase(i);
431 }
432 // !!! remove in node?
433}
434
435
436void
437NBTrafficLightDefinition::addControlledInnerEdges(const std::vector<std::string>& edges) {
438 myControlledInnerEdges.insert(edges.begin(), edges.end());
439}
440
441
442std::vector<std::string>
444 return std::vector<std::string>(myControlledInnerEdges.begin(), myControlledInnerEdges.end());
445}
446
447
448const EdgeVector&
452
453
454void
456 int tlIndex = 0;
457 // build the list of links which are controlled by the traffic light
458 std::vector<int> indirectLeft;
459 for (EdgeVector::iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
460 NBEdge* incoming = *i;
461 int noLanes = incoming->getNumLanes();
462 for (int j = 0; j < noLanes; j++) {
463 std::vector<NBEdge::Connection> connected = incoming->getConnectionsFromLane(j);
464 for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
465 const NBEdge::Connection& el = *k;
466 if (incoming->mayBeTLSControlled(el.fromLane, el.toEdge, el.toLane)) {
467 if (el.toEdge != nullptr && el.toLane >= (int) el.toEdge->getNumLanes()) {
468 throw ProcessError("Connection '" + incoming->getID() + "_" + toString(j) + "->" + el.toEdge->getID() + "_" + toString(el.toLane) + "' yields in a not existing lane.");
469 }
471 && isRailway(incoming->getPermissions())) {
472 // railways stay uncontrolled at rail crossing but they
473 // must be registered in MSRailCrossing
474 into.push_back(NBConnection(incoming, el.fromLane, el.toEdge, el.toLane, -1));
475 } else if (incoming->getToNode()->getType() == SumoXMLNodeType::RAIL_SIGNAL
476 && incoming->getToNode()->getDirection(incoming, el.toEdge) == LinkDirection::TURN
477 // assume explicit connections at sharp turn-arounds are either for reversal or due to a geometry glitch
478 // (the might also be due to faulty connection
479 // input but they would not come from guessing)
480 && (incoming->getBidiEdge() == el.toEdge)
481 ) {
482 // turnarounds stay uncontrolled at rail signal
483 } else if (incoming->getToNode()->getType() == SumoXMLNodeType::RAIL_SIGNAL && railSignalUncontrolled(incoming, el.toEdge)) {
484 // rail signals may stay uncontrolled in a particular direction
485 } else {
486 into.push_back(NBConnection(incoming, el.fromLane, el.toEdge, el.toLane, tlIndex++));
487 if (el.indirectLeft) {
488 indirectLeft.push_back((int)into.size() - 1);
489 }
490 }
491 }
492 }
493 }
494 }
495 if (indirectLeft.size() > 0) {
496 // assign linkIndex2 to indirect left turns
497 for (int i : indirectLeft) {
498 NBConnection& c = into[i];
499 // find straight connection with the same toEdge
500 for (const NBConnection& c2 : into) {
501 if (c2.getTo() == c.getTo() && c2.getFrom() != c.getFrom()) {
502 LinkDirection dir = c.getFrom()->getToNode()->getDirection(c2.getFrom(), c2.getTo());
503 if (dir == LinkDirection::STRAIGHT) {
504 c.setTLIndex2(c2.getTLIndex());
505 break;
506 }
507 }
508 }
509 }
510 }
511
512 if (into.size() > 0 && tlIndex == 0) {
513 WRITE_WARNINGF(TL("The rail crossing '%' does not have any roads."), getID());
514 }
515}
516
517bool
519 const NBNode* n = in->getToNode();
523 return true;
524 }
525 } else {
526 WRITE_WARNINGF(TL("Could not interpret rail signal direction at junction '%' due to inconsistent directions of edge '%' (%) and edge '%' (%)"),
527 n->getID(),
528 in->getID(), in->getParameter(OSM_DIRECTION),
529 out->getID(), out->getParameter(OSM_DIRECTION));
530 }
531 }
532 return false;
533}
534
535bool
536NBTrafficLightDefinition::needsCont(const NBEdge* fromE, const NBEdge* toE, const NBEdge* otherFromE, const NBEdge* otherToE) const {
540 }
541 return std::find(myNeedsContRelation.begin(), myNeedsContRelation.end(),
542 StreamPair(fromE, toE, otherFromE, otherToE)) != myNeedsContRelation.end();
543}
544
545
546void
548 if (!amInvalid()) {
550 dummy.initNeedsContRelation();
552 for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
553 (*i)->removeTrafficLight(&dummy);
554 }
555 }
557}
558
559
560void
565 NBTrafficLightLogic* tllDummy = dummy.computeLogicAndConts(0, true);
566 delete tllDummy;
568 for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
569 (*i)->removeTrafficLight(&dummy);
570 }
572 //std::cout << " rightOnRedConflicts tls=" << getID() << " pro=" << getProgramID() << "\n";
573 //for (RightOnRedConflicts::const_iterator it = myRightOnRedConflicts.begin(); it != myRightOnRedConflicts.end(); ++it) {
574 // std::cout << " " << it->first << ", " << it->second << "\n";
575 //}
576 }
577}
578
579
580bool
581NBTrafficLightDefinition::rightOnRedConflict(int index, int foeIndex) const {
583 return std::find(myRightOnRedConflicts.begin(), myRightOnRedConflicts.end(), std::make_pair(index, foeIndex)) != myRightOnRedConflicts.end();
584}
585
586std::string
588 return getID() + ':' + getProgramID() + '@' + toString(this);
589}
590
591
592/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define DEBUGCOND(PED)
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define TL(string)
Definition MsgHandler.h:315
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition NBCont.h:42
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a railway edge.
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ TURN
The link is a 180 degree turn.
@ STRAIGHT
The link is a straight direction.
T MAX2(T a, T b)
Definition StdDefs.h:82
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
NBEdge * getFrom() const
returns the from-edge (start of the connection)
void setTLIndex2(int tlIndex)
NBEdge * getTo() const
returns the to-edge (end of the connection)
static double maxSpeed(const EdgeVector &ev)
The representation of a single edge during network building.
Definition NBEdge.h:92
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition NBEdge.cpp:4378
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition NBEdge.h:1041
NBNode * getToNode() const
Returns the destination node of the edge.
Definition NBEdge.h:546
void setInsideTLS(bool inside)
Marks this edge being within an intersection.
Definition NBEdge.h:1141
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
Definition NBEdge.cpp:4438
const std::string & getID() const
Definition NBEdge.h:1528
int getNumLanes() const
Returns the number of lanes.
Definition NBEdge.h:520
std::vector< Connection > getConnectionsFromLane(int lane, const NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
Definition NBEdge.cpp:1286
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
Definition NBEdge.cpp:3715
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
Definition NBEdge.cpp:1380
const NBEdge * getBidiEdge() const
Definition NBEdge.h:1514
EdgeVector getIncomingEdges() const
Returns the list of incoming edges unsorted.
Definition NBEdge.cpp:1392
Used for sorting the cells by the begin time they describe.
Definition NBNode.h:788
Represents a single node (junction) during network building.
Definition NBNode.h:66
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
Definition NBNode.cpp:2358
bool mustBrake(const NBEdge *const from, const NBEdge *const to, int fromLane, int toLane, bool includePedCrossings) const
Returns the information whether the described flow must let any other flow pass.
Definition NBNode.cpp:2006
SumoXMLNodeType getType() const
Returns the type of this node.
Definition NBNode.h:285
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
Definition NBNode.cpp:2188
bool hasOutgoing(const NBEdge *const e) const
Returns whether the given edge starts at this node.
Definition NBNode.cpp:1862
static const int FORWARD
edge directions (for pedestrian related stuff)
Definition NBNode.h:216
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
Definition NBNode.cpp:2198
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
Definition NBNode.cpp:396
A traffic light logics which must be computed (only nodes/edges are given)
Definition NBOwnTLDef.h:44
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
void initNeedsContRelation() const
virtual bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turning right on a red light
virtual ~NBTrafficLightDefinition()
Destructor.
const std::string & getProgramID() const
Returns the ProgramID.
void addControlledInnerEdges(const std::vector< std::string > &edges)
Adds the given ids into the list of inner edges controlled by the tls.
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
bool needsCont(const NBEdge *fromE, const NBEdge *toE, const NBEdge *otherFromE, const NBEdge *otherToE) const
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
virtual void initRightOnRedConflicts() const
virtual void removeNode(NBNode *node)
Removes the given node from the list of controlled nodes.
EdgeVector myIncomingEdges
The list of incoming edges.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
NBTrafficLightLogic * compute(const OptionsCont &oc)
Computes the traffic light logic.
std::vector< std::string > getControlledInnerEdges() const
Retrieve the ids of edges explicitly controlled by the tls.
virtual NBTrafficLightLogic * myCompute(int brakingTime)=0
Computes the traffic light logic finally in dependence to the type.
static std::set< NBEdge * > collectReachable(EdgeVector outer, const EdgeVector &within, bool checkControlled)
static const std::string OSM_DIRECTION
processing parameter for rail signal edges and nodes
RightOnRedConflicts myRightOnRedConflicts
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
static const std::string DummyID
id for temporary definitions
virtual void collectLinks()=0
Collects the links participating in this traffic light.
int computeBrakingTime(double minDecel) const
Computes the time vehicles may need to brake.
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority, bool sameNodeOnly=false) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
NBConnectionVector myControlledLinks
The list of controlled links.
static const std::string DefaultProgramID
bool mustBrake(const NBEdge *const from, const NBEdge *const to) const
Returns the information whether the described flow must let any other flow pass.
virtual void initNeedsContRelation() const
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
void collectAllLinks(NBConnectionVector &into)
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
NBTrafficLightDefinition(const std::string &id, const std::vector< NBNode * > &junctions, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
static const SUMOTime UNSPECIFIED_DURATION
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
static const std::string OSM_SIGNAL_DIRECTION
std::string getDescription() const
get ID and programID together (for convenient debugging)
static bool railSignalUncontrolled(const NBEdge *in, const NBEdge *out)
virtual void collectEdges()
Build the list of participating edges.
std::set< std::string > myControlledInnerEdges
Set of inner edges that shall be controlled, though.
A SUMO-compliant built logic for a traffic light.
Base class for objects which have an id.
Definition Named.h:54
const std::string & getID() const
Returns the id.
Definition Named.h:74
A storage for options typed value containers)
Definition OptionsCont.h:89
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void updateParameters(const Parameterised::Map &mapArg)
Adds or updates all given parameters from the map.
A structure which describes a connection between edges or lanes.
Definition NBEdge.h:201
bool indirectLeft
Whether this connection is an indirect left turn.
Definition NBEdge.h:261
int fromLane
The lane the connections starts at.
Definition NBEdge.h:210
int toLane
The lane the connections yields in.
Definition NBEdge.h:216
NBEdge * toEdge
The edge the connections yields in.
Definition NBEdge.h:213
data structure for caching needsCont information