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-2026 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 myExtraConflictsReady(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 myExtraConflictsReady(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 myExtraConflictsReady(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 if (ret->getType() == TrafficLightType::ACTUATED) {
130 for (const std::string& param : {
131 "jam-threshold", "passing-time", "detector-gap", "detector-length", "inactive-threshold"
132 }) {
133 if (!oc.isDefault("tls.actuated." + param) && !ret->hasParameter(param)) {
134 ret->setParameter(param, oc.getValueString("tls.actuated." + param));
135 }
136 }
137 if (!oc.isDefault("tls.actuated.show-detectors") && !ret->hasParameter("show-detectors")) {
138 ret->setParameter("show-detectors", oc.getValueString("tls.actuated.show-detectors"));
139 }
140
141 }
142 return ret;
143}
144
145
146bool
148 return myControlledLinks.size() == 0;
149}
150
151
152int
154 if (myIncomingEdges.empty()) {
155 // don't crash
156 return MIN_YELLOW_SECONDS;
157 }
158 const double vmax = NBContHelper::maxSpeed(myIncomingEdges);
159 if (vmax < 71 / 3.6) {
160 // up to 50kmh: 3 seconds , 60km/h: 4, 70kmh: 5
161 // @note: these are German regulations, other countries may differ
162 return MIN_YELLOW_SECONDS + (int)MAX2(0.0, (floor((vmax - 50 / 3.6) * 0.37)));
163 } else {
164 // above 70km/h we use a function that grows according to the "natural"
165 // formula (vmax / 2 * minDecel) but continues smoothly where the german
166 // rules leave of
167 return (int)(1.8 + vmax / 2 / minDecel);
168 }
169}
170
171
172void
174 // collect the information about participating edges and links
175 collectEdges();
176 collectLinks();
177}
178
179std::set<NBEdge*>
180NBTrafficLightDefinition::collectReachable(EdgeVector outer, const EdgeVector& within, bool checkControlled) {
181 std::set<NBEdge*> reachable;
182 while (outer.size() > 0) {
183 NBEdge* from = outer.back();
184 outer.pop_back();
185 std::vector<NBEdge::Connection>& cons = from->getConnections();
186 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); k++) {
187 NBEdge* to = (*k).toEdge;
188 if (reachable.count(to) == 0 &&
189 (find(within.begin(), within.end(), to) != within.end()) &&
190 (!checkControlled || from->mayBeTLSControlled((*k).fromLane, to, (*k).toLane))) {
191 reachable.insert(to);
192 outer.push_back(to);
193 }
194 }
195 }
196 return reachable;
197}
198
199
200void
202 myIncomingEdges.clear();
203 myEdgesWithin.clear();
204 EdgeVector myOutgoing;
205 // collect the edges from the participating nodes
206 for (std::vector<NBNode*>::iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
207 const EdgeVector& incoming = (*i)->getIncomingEdges();
208 copy(incoming.begin(), incoming.end(), back_inserter(myIncomingEdges));
209 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
210 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
211 }
212 EdgeVector outer;
213 // check which of the edges are completely within the junction
214 // add them to the list of edges lying within the node
215 for (NBEdge* edge : myIncomingEdges) {
216 edge->setInsideTLS(false); // reset
217 // an edge lies within the logic if it is outgoing as well as incoming
218 EdgeVector::iterator k = std::find(myOutgoing.begin(), myOutgoing.end(), edge);
219 if (k != myOutgoing.end()) {
220 myEdgesWithin.push_back(edge);
221 } else {
222 outer.push_back(edge);
223 }
224 }
225 // collect edges that are reachable from the outside via controlled connections
226 std::set<NBEdge*> reachable = collectReachable(outer, myEdgesWithin, true);
227 // collect edges that are reachable from the outside regardless of controllability
228 std::set<NBEdge*> reachable2 = collectReachable(outer, myEdgesWithin, false);
229
230 const bool uncontrolledWithin = OptionsCont::getOptions().getBool("tls.uncontrolled-within");
231 for (EdgeVector::iterator j = myEdgesWithin.begin(); j != myEdgesWithin.end(); ++j) {
232 NBEdge* edge = *j;
233 // edges that are marked as 'inner' will not get their own phase when
234 // computing traffic light logics (unless they cannot be reached from the outside at all)
235 if (reachable.count(edge) == 1) {
236 edge->setInsideTLS(true);
237 // legacy behavior
238 if (uncontrolledWithin && myControlledInnerEdges.count(edge->getID()) == 0) {
239 myIncomingEdges.erase(find(myIncomingEdges.begin(), myIncomingEdges.end(), edge));
240 }
241 }
242 if (reachable2.count(edge) == 0 && edge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD, true) >= 0
243 && getID() != DummyID) {
244 WRITE_WARNINGF(TL("Unreachable edge '%' within tlLogic '%'"), edge->getID(), getID());
245 }
246 }
247}
248
249
250bool
251NBTrafficLightDefinition::mustBrake(const NBEdge* const from, const NBEdge* const to) const {
252 std::vector<NBNode*>::const_iterator i =
253 find_if(myControlledNodes.begin(), myControlledNodes.end(),
255 assert(i != myControlledNodes.end());
256 NBNode* node = *i;
257 if (!node->hasOutgoing(to)) {
258 return true; // !!!
259 }
260 // @todo recheck relevance of lane indices
261 return node->mustBrake(from, to, -1, -1, true);
262}
263
264
265bool
266NBTrafficLightDefinition::mustBrake(const NBEdge* const possProhibitedFrom,
267 const NBEdge* const possProhibitedTo,
268 const NBEdge* const possProhibitorFrom,
269 const NBEdge* const possProhibitorTo,
270 bool regardNonSignalisedLowerPriority) const {
271 return forbids(possProhibitorFrom, possProhibitorTo,
272 possProhibitedFrom, possProhibitedTo,
273 regardNonSignalisedLowerPriority);
274}
275
276
277bool
279 const NBConnection& possProhibitor,
280 bool regardNonSignalisedLowerPriority) const {
281 return forbids(possProhibitor.getFrom(), possProhibitor.getTo(),
282 possProhibited.getFrom(), possProhibited.getTo(),
283 regardNonSignalisedLowerPriority);
284}
285
286
287bool
288NBTrafficLightDefinition::forbids(const NBEdge* const possProhibitorFrom,
289 const NBEdge* const possProhibitorTo,
290 const NBEdge* const possProhibitedFrom,
291 const NBEdge* const possProhibitedTo,
292 bool regardNonSignalisedLowerPriority,
293 bool sameNodeOnly) const {
294 if (possProhibitorFrom == nullptr || possProhibitorTo == nullptr || possProhibitedFrom == nullptr || possProhibitedTo == nullptr) {
295 return false;
296 }
297 // retrieve both nodes
298 std::vector<NBNode*>::const_iterator incoming =
299 find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorFrom));
300 std::vector<NBNode*>::const_iterator outgoing =
301 find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_outgoing_finder(possProhibitedTo));
302 assert(incoming != myControlledNodes.end());
303 NBNode* incnode = *incoming;
304 NBNode* outnode = *outgoing;
305 EdgeVector::const_iterator i;
306
307#ifdef DEBUG_RIGHT_OF_WAY
308 if (DEBUGCOND) {
309 std::cout << "forbids tls=" << getID() << " from=" << possProhibitedFrom->getID() << " to=" << possProhibitedTo->getID() << " foeFrom=" << possProhibitorFrom->getID() << " foeTo=" << possProhibitorTo->getID() << " rnslp=" << regardNonSignalisedLowerPriority << " sameNodeOnly=" << sameNodeOnly;
310 }
311#endif
312 if (incnode != outnode) {
313 if (sameNodeOnly) {
314#ifdef DEBUG_RIGHT_OF_WAY
315 if (DEBUGCOND) {
316 std::cout << " differentNodes: allows (no check)\n";
317 }
318#endif
319 return false;
320 }
321 // the links are located at different nodes
322 const EdgeVector& ev1 = possProhibitedTo->getConnectedEdges();
323 // go through the following edge,
324 // check whether one of these connections is prohibited
325 for (i = ev1.begin(); i != ev1.end(); ++i) {
326 std::vector<NBNode*>::const_iterator outgoing2 =
328 if (outgoing2 == myControlledNodes.end()) {
329 continue;
330 }
331 NBNode* outnode2 = *outgoing2;
332 if (incnode != outnode2) {
333 continue;
334 }
335 if (incnode->getDirection(possProhibitedTo, *i) != LinkDirection::STRAIGHT) {
336 continue;
337 }
338 bool ret1 = incnode->foes(possProhibitorFrom, possProhibitorTo,
339 possProhibitedTo, *i);
340 bool ret2 = incnode->forbids(possProhibitorFrom, possProhibitorTo,
341 possProhibitedTo, *i,
342 regardNonSignalisedLowerPriority);
343 bool ret = ret1 || ret2;
344 if (ret) {
345#ifdef DEBUG_RIGHT_OF_WAY
346 if (DEBUGCOND) {
347 std::cout << " differentNodes: forbids\n";
348 }
349#endif
350 return true;
351 }
352 }
353
354 const EdgeVector& ev2 = possProhibitorTo->getConnectedEdges();
355 // go through the following edge,
356 // check whether one of these connections is prohibited
357 for (i = ev2.begin(); i != ev2.end(); ++i) {
358 std::vector<NBNode*>::const_iterator incoming2 =
359 find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorTo));
360 if (incoming2 == myControlledNodes.end()) {
361 continue;
362 }
363 NBNode* incnode2 = *incoming2;
364 if (incnode2 != outnode) {
365 continue;
366 }
367 if (incnode2->getDirection(possProhibitorTo, *i) != LinkDirection::STRAIGHT) {
368 continue;
369 }
370 bool ret1 = incnode2->foes(possProhibitorTo, *i,
371 possProhibitedFrom, possProhibitedTo);
372 bool ret2 = incnode2->forbids(possProhibitorTo, *i,
373 possProhibitedFrom, possProhibitedTo,
374 regardNonSignalisedLowerPriority);
375 bool ret = ret1 || ret2;
376 if (ret) {
377#ifdef DEBUG_RIGHT_OF_WAY
378 if (DEBUGCOND) {
379 std::cout << " differentNodes: forbids (2)\n";
380 }
381#endif
382 return true;
383 }
384 }
385#ifdef DEBUG_RIGHT_OF_WAY
386 if (DEBUGCOND) {
387 std::cout << " differentNodes: allows\n";
388 }
389#endif
390 return false;
391 }
392 // both links are located at the same node
393 // check using this node's information
394 const bool result = incnode->forbids(possProhibitorFrom, possProhibitorTo,
395 possProhibitedFrom, possProhibitedTo,
396 regardNonSignalisedLowerPriority);
397#ifdef DEBUG_RIGHT_OF_WAY
398 if (DEBUGCOND) {
399 std::cout << " sameNodes: " << (result ? "forbids" : "allows") << "\n";
400 }
401#endif
402 return result;
403}
404
405
406bool
407NBTrafficLightDefinition::foes(const NBEdge* const from1, const NBEdge* const to1,
408 const NBEdge* const from2, const NBEdge* const to2) const {
409 if (to1 == nullptr || to2 == nullptr) {
410 return false;
411 }
412 // retrieve both nodes (it is possible that a connection
413 std::vector<NBNode*>::const_iterator incoming =
414 find_if(myControlledNodes.begin(), myControlledNodes.end(),
416 std::vector<NBNode*>::const_iterator outgoing =
417 find_if(myControlledNodes.begin(), myControlledNodes.end(),
419 assert(incoming != myControlledNodes.end());
420 NBNode* incnode = *incoming;
421 NBNode* outnode = *outgoing;
422 if (incnode != outnode) {
423 return false;
424 }
425 return incnode->foes(from1, to1, from2, to2);
426}
427
428
429void
431 if (std::find(myControlledNodes.begin(), myControlledNodes.end(), node) == myControlledNodes.end()) {
432 myControlledNodes.push_back(node);
434 }
435 node->addTrafficLight(this);
436}
437
438
439void
441 std::vector<NBNode*>::iterator i = std::find(myControlledNodes.begin(), myControlledNodes.end(), node);
442 if (i != myControlledNodes.end()) {
443 myControlledNodes.erase(i);
444 }
445 // !!! remove in node?
446}
447
448
449void
450NBTrafficLightDefinition::addControlledInnerEdges(const std::vector<std::string>& edges) {
451 myControlledInnerEdges.insert(edges.begin(), edges.end());
452}
453
454
455std::vector<std::string>
457 return std::vector<std::string>(myControlledInnerEdges.begin(), myControlledInnerEdges.end());
458}
459
460
461const EdgeVector&
465
466
467void
469 int tlIndex = 0;
470 // build the list of links which are controlled by the traffic light
471 std::vector<int> indirectLeft;
472 for (EdgeVector::iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
473 NBEdge* incoming = *i;
474 int noLanes = incoming->getNumLanes();
475 for (int j = 0; j < noLanes; j++) {
476 std::vector<NBEdge::Connection> connected = incoming->getConnectionsFromLane(j);
477 for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
478 const NBEdge::Connection& el = *k;
479 if (incoming->mayBeTLSControlled(el.fromLane, el.toEdge, el.toLane)) {
480 if (el.toEdge != nullptr && el.toLane >= (int) el.toEdge->getNumLanes()) {
481 throw ProcessError("Connection '" + incoming->getID() + "_" + toString(j) + "->" + el.toEdge->getID() + "_" + toString(el.toLane) + "' yields in a not existing lane.");
482 }
484 && isRailway(incoming->getPermissions())) {
485 // railways stay uncontrolled at rail crossing but they
486 // must be registered in MSRailCrossing
487 into.push_back(NBConnection(incoming, el.fromLane, el.toEdge, el.toLane, -1));
488 } else if (incoming->getToNode()->getType() == SumoXMLNodeType::RAIL_SIGNAL
489 && incoming->getToNode()->getDirection(incoming, el.toEdge) == LinkDirection::TURN
490 // assume explicit connections at sharp turn-arounds are either for reversal or due to a geometry glitch
491 // (the might also be due to faulty connection
492 // input but they would not come from guessing)
493 && (incoming->getBidiEdge() == el.toEdge)
494 ) {
495 // turnarounds stay uncontrolled at rail signal
496 } else if (incoming->getToNode()->getType() == SumoXMLNodeType::RAIL_SIGNAL && railSignalUncontrolled(incoming, el.toEdge)) {
497 // rail signals may stay uncontrolled in a particular direction
498 } else {
499 into.push_back(NBConnection(incoming, el.fromLane, el.toEdge, el.toLane, tlIndex++));
500 if (el.indirectLeft) {
501 indirectLeft.push_back((int)into.size() - 1);
502 }
503 }
504 }
505 }
506 }
507 }
508 if (indirectLeft.size() > 0) {
509 // assign linkIndex2 to indirect left turns
510 for (int i : indirectLeft) {
511 NBConnection& c = into[i];
512 // find straight connection with the same toEdge
513 for (const NBConnection& c2 : into) {
514 if (c2.getTo() == c.getTo() && c2.getFrom() != c.getFrom()) {
515 LinkDirection dir = c.getFrom()->getToNode()->getDirection(c2.getFrom(), c2.getTo());
516 if (dir == LinkDirection::STRAIGHT) {
517 c.setTLIndex2(c2.getTLIndex());
518 break;
519 }
520 }
521 }
522 }
523 }
524
525 if (into.size() > 0 && tlIndex == 0) {
526 WRITE_WARNINGF(TL("The rail crossing '%' does not have any roads."), getID());
527 }
528}
529
530bool
532 const NBNode* n = in->getToNode();
536 return true;
537 }
538 } else {
539 WRITE_WARNINGF(TL("Could not interpret rail signal direction at junction '%' due to inconsistent directions of edge '%' (%) and edge '%' (%)"),
540 n->getID(),
541 in->getID(), in->getParameter(OSM_DIRECTION),
542 out->getID(), out->getParameter(OSM_DIRECTION));
543 }
544 }
545 return false;
546}
547
548bool
549NBTrafficLightDefinition::needsCont(const NBEdge* fromE, const NBEdge* toE, const NBEdge* otherFromE, const NBEdge* otherToE) const {
553 }
554 return std::find(myNeedsContRelation.begin(), myNeedsContRelation.end(),
555 StreamPair(fromE, toE, otherFromE, otherToE)) != myNeedsContRelation.end();
556}
557
558
559void
561 if (!amInvalid()) {
563 dummy.initNeedsContRelation();
565 for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
566 (*i)->removeTrafficLight(&dummy);
567 }
568 }
570}
571
572
573void
578 NBTrafficLightLogic* tllDummy = dummy.computeLogicAndConts(0, true);
579 delete tllDummy;
581 for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
582 (*i)->removeTrafficLight(&dummy);
583 }
585 //std::cout << " extraConflicts tls=" << getID() << " pro=" << getProgramID() << "\n";
586 //for (auto item : myExtraConflicts) {
587 // std::cout << " " << item.first << ", " << item.second << "\n";
588 //}
589 }
590}
591
592
593bool
594NBTrafficLightDefinition::extraConflict(int index, int foeIndex) const {
596 return std::find(myExtraConflicts.begin(), myExtraConflicts.end(), std::make_pair(index, foeIndex)) != myExtraConflicts.end();
597}
598
599std::string
601 return getID() + ':' + getProgramID() + '@' + toString(this);
602}
603
604
605/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define DEBUGCOND(PED)
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define TL(string)
Definition MsgHandler.h:304
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 (exclusive) 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:86
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
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:4543
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition NBEdge.h:1047
NBNode * getToNode() const
Returns the destination node of the edge.
Definition NBEdge.h:552
void setInsideTLS(bool inside)
Marks this edge being within an intersection.
Definition NBEdge.h:1147
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
Definition NBEdge.cpp:4603
const std::string & getID() const
Definition NBEdge.h:1551
int getNumLanes() const
Returns the number of lanes.
Definition NBEdge.h:526
std::vector< Connection > getConnectionsFromLane(int lane, const NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
Definition NBEdge.cpp:1310
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
Definition NBEdge.cpp:3861
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
Definition NBEdge.cpp:1404
const NBEdge * getBidiEdge() const
Definition NBEdge.h:1537
EdgeVector getIncomingEdges() const
Returns the list of incoming edges unsorted.
Definition NBEdge.cpp:1416
Used for sorting the cells by the begin time they describe.
Definition NBNode.h:807
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:2507
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:2153
SumoXMLNodeType getType() const
Returns the type of this node.
Definition NBNode.h:287
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:2337
static const int FORWARD
edge directions (for pedestrian related stuff)
Definition NBNode.h:218
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:2347
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 ~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 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
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
virtual bool extraConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex (i.e. while turning right on a red light)
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.
TrafficLightType getType() const
get the algorithm type (static etc..)
Base class for objects which have an id.
Definition Named.h:53
const std::string & getID() const
Returns the id.
Definition Named.h:73
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)
std::string getValueString(const std::string &name) const
Returns the string-value of the named option (all options)
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.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
void updateParameters(const Parameterised::Map &mapArg)
Adds or updates all given parameters from the map.
unsigned node
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