Eclipse SUMO - Simulation of Urban MObility
NBTrafficLightDefinition.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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";
48
49
50// ===========================================================================
51// method definitions
52// ===========================================================================
54 const std::vector<NBNode*>& junctions, const std::string& programID,
55 SUMOTime offset, TrafficLightType type) :
56 Named(id),
57 myControlledNodes(junctions),
58 mySubID(programID), myOffset(offset),
59 myType(type),
60 myNeedsContRelationReady(false),
61 myRightOnRedConflictsReady(false) {
62 std::vector<NBNode*>::iterator i = myControlledNodes.begin();
63 while (i != myControlledNodes.end()) {
64 for (std::vector<NBNode*>::iterator j = i + 1; j != myControlledNodes.end();) {
65 if (*i == *j) {
66 j = myControlledNodes.erase(j);
67 } else {
68 j++;
69 }
70 }
71 i++;
72 }
74 for (NBNode* const node : junctions) {
75 node->addTrafficLight(this);
76 }
77}
78
79
81 NBNode* junction, const std::string& programID, SUMOTime offset, TrafficLightType type) :
82 Named(id),
83 mySubID(programID),
84 myOffset(offset),
85 myType(type),
86 myNeedsContRelationReady(false),
87 myRightOnRedConflictsReady(false) {
88 addNode(junction);
89}
90
91
92NBTrafficLightDefinition::NBTrafficLightDefinition(const std::string& id, const std::string& programID,
93 SUMOTime offset, TrafficLightType type) :
94 Named(id),
95 mySubID(programID),
96 myOffset(offset),
97 myType(type),
98 myNeedsContRelationReady(false),
99 myRightOnRedConflictsReady(false) {
100}
101
102
104
105
108 // it is not really a traffic light if no incoming edge exists
109 if (amInvalid()) {
110 // make a copy of myControlledNodes because it will be modified;
111 std::vector<NBNode*> nodes = myControlledNodes;
112 for (auto it : nodes) {
113 it->removeTrafficLight(this);
114 }
115 WRITE_WARNING("The traffic light '" + getID() + "' does not control any links; it will not be build.");
116 return nullptr;
117 }
118 // compute the time needed to brake
119 int brakingTime = computeBrakingTime(oc.getFloat("tls.yellow.min-decel"));
120 // perform the computation depending on whether the traffic light
121 // definition was loaded or shall be computed new completely
122 if (!oc.isDefault("tls.yellow.time")) {
123 brakingTime = oc.getInt("tls.yellow.time");
124 }
125 NBTrafficLightLogic* ret = myCompute(brakingTime);
127 return ret;
128}
129
130
131bool
133 return myControlledLinks.size() == 0;
134}
135
136
137int
139 if (myIncomingEdges.empty()) {
140 // don't crash
141 return MIN_YELLOW_SECONDS;
142 }
143 const double vmax = NBContHelper::maxSpeed(myIncomingEdges);
144 if (vmax < 71 / 3.6) {
145 // up to 50kmh: 3 seconds , 60km/h: 4, 70kmh: 5
146 // @note: these are German regulations, other countries may differ
147 return MIN_YELLOW_SECONDS + (int)MAX2(0.0, (floor((vmax - 50 / 3.6) * 0.37)));
148 } else {
149 // above 70km/h we use a function that grows according to the "natural"
150 // formula (vmax / 2 * minDecel) but continues smoothly where the german
151 // rules leave of
152 return (int)(1.8 + vmax / 2 / minDecel);
153 }
154}
155
156
157void
159 // collect the information about participating edges and links
160 collectEdges();
161 collectLinks();
162}
163
164std::set<NBEdge*>
165NBTrafficLightDefinition::collectReachable(EdgeVector outer, const EdgeVector& within, bool checkControlled) {
166 std::set<NBEdge*> reachable;
167 while (outer.size() > 0) {
168 NBEdge* from = outer.back();
169 outer.pop_back();
170 std::vector<NBEdge::Connection>& cons = from->getConnections();
171 for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); k++) {
172 NBEdge* to = (*k).toEdge;
173 if (reachable.count(to) == 0 &&
174 (find(within.begin(), within.end(), to) != within.end()) &&
175 (!checkControlled || from->mayBeTLSControlled((*k).fromLane, to, (*k).toLane))) {
176 reachable.insert(to);
177 outer.push_back(to);
178 }
179 }
180 }
181 return reachable;
182}
183
184
185void
187 myIncomingEdges.clear();
188 myEdgesWithin.clear();
189 EdgeVector myOutgoing;
190 // collect the edges from the participating nodes
191 for (std::vector<NBNode*>::iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
192 const EdgeVector& incoming = (*i)->getIncomingEdges();
193 copy(incoming.begin(), incoming.end(), back_inserter(myIncomingEdges));
194 const EdgeVector& outgoing = (*i)->getOutgoingEdges();
195 copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
196 }
197 EdgeVector outer;
198 // check which of the edges are completely within the junction
199 // add them to the list of edges lying within the node
200 for (NBEdge* edge : myIncomingEdges) {
201 edge->setInsideTLS(false); // reset
202 // an edge lies within the logic if it is outgoing as well as incoming
203 EdgeVector::iterator k = std::find(myOutgoing.begin(), myOutgoing.end(), edge);
204 if (k != myOutgoing.end()) {
205 myEdgesWithin.push_back(edge);
206 } else {
207 outer.push_back(edge);
208 }
209 }
210 // collect edges that are reachable from the outside via controlled connections
211 std::set<NBEdge*> reachable = collectReachable(outer, myEdgesWithin, true);
212 // collect edges that are reachable from the outside regardless of controllability
213 std::set<NBEdge*> reachable2 = collectReachable(outer, myEdgesWithin, false);
214
215 const bool uncontrolledWithin = OptionsCont::getOptions().getBool("tls.uncontrolled-within");
216 for (EdgeVector::iterator j = myEdgesWithin.begin(); j != myEdgesWithin.end(); ++j) {
217 NBEdge* edge = *j;
218 // edges that are marked as 'inner' will not get their own phase when
219 // computing traffic light logics (unless they cannot be reached from the outside at all)
220 if (reachable.count(edge) == 1) {
221 edge->setInsideTLS(true);
222 // legacy behavior
223 if (uncontrolledWithin && myControlledInnerEdges.count(edge->getID()) == 0) {
224 myIncomingEdges.erase(find(myIncomingEdges.begin(), myIncomingEdges.end(), edge));
225 }
226 }
227 if (reachable2.count(edge) == 0 && edge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD, true) >= 0
228 && getID() != DummyID) {
229 WRITE_WARNING("Unreachable edge '" + edge->getID() + "' within tlLogic '" + getID() + "'");
230 }
231 }
232}
233
234
235bool
236NBTrafficLightDefinition::mustBrake(const NBEdge* const from, const NBEdge* const to) const {
237 std::vector<NBNode*>::const_iterator i =
238 find_if(myControlledNodes.begin(), myControlledNodes.end(),
240 assert(i != myControlledNodes.end());
241 NBNode* node = *i;
242 if (!node->hasOutgoing(to)) {
243 return true; // !!!
244 }
245 // @todo recheck relevance of lane indices
246 return node->mustBrake(from, to, -1, -1, true);
247}
248
249
250bool
251NBTrafficLightDefinition::mustBrake(const NBEdge* const possProhibitedFrom,
252 const NBEdge* const possProhibitedTo,
253 const NBEdge* const possProhibitorFrom,
254 const NBEdge* const possProhibitorTo,
255 bool regardNonSignalisedLowerPriority) const {
256 return forbids(possProhibitorFrom, possProhibitorTo,
257 possProhibitedFrom, possProhibitedTo,
258 regardNonSignalisedLowerPriority);
259}
260
261
262bool
264 const NBConnection& possProhibitor,
265 bool regardNonSignalisedLowerPriority) const {
266 return forbids(possProhibitor.getFrom(), possProhibitor.getTo(),
267 possProhibited.getFrom(), possProhibited.getTo(),
268 regardNonSignalisedLowerPriority);
269}
270
271
272bool
273NBTrafficLightDefinition::forbids(const NBEdge* const possProhibitorFrom,
274 const NBEdge* const possProhibitorTo,
275 const NBEdge* const possProhibitedFrom,
276 const NBEdge* const possProhibitedTo,
277 bool regardNonSignalisedLowerPriority,
278 bool sameNodeOnly) const {
279 if (possProhibitorFrom == nullptr || possProhibitorTo == nullptr || possProhibitedFrom == nullptr || possProhibitedTo == nullptr) {
280 return false;
281 }
282 // retrieve both nodes
283 std::vector<NBNode*>::const_iterator incoming =
284 find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorFrom));
285 std::vector<NBNode*>::const_iterator outgoing =
286 find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_outgoing_finder(possProhibitedTo));
287 assert(incoming != myControlledNodes.end());
288 NBNode* incnode = *incoming;
289 NBNode* outnode = *outgoing;
290 EdgeVector::const_iterator i;
291
292#ifdef DEBUG_RIGHT_OF_WAY
293 if (DEBUGCOND) {
294 std::cout << "foribds tls=" << getID() << " from=" << possProhibitedFrom->getID() << " to=" << possProhibitedTo->getID() << " foeFrom=" << possProhibitorFrom->getID() << " foeTo=" << possProhibitorTo->getID() << " rnslp=" << regardNonSignalisedLowerPriority << " sameNodeOnly=" << sameNodeOnly;
295 }
296#endif
297 if (incnode != outnode) {
298 if (sameNodeOnly) {
299#ifdef DEBUG_RIGHT_OF_WAY
300 if (DEBUGCOND) {
301 std::cout << " differentNodes: allows (no check)\n";
302 }
303#endif
304 return false;
305 }
306 // the links are located at different nodes
307 const EdgeVector& ev1 = possProhibitedTo->getConnectedEdges();
308 // go through the following edge,
309 // check whether one of these connections is prohibited
310 for (i = ev1.begin(); i != ev1.end(); ++i) {
311 std::vector<NBNode*>::const_iterator outgoing2 =
313 if (outgoing2 == myControlledNodes.end()) {
314 continue;
315 }
316 NBNode* outnode2 = *outgoing2;
317 if (incnode != outnode2) {
318 continue;
319 }
320 if (incnode->getDirection(possProhibitedTo, *i) != LinkDirection::STRAIGHT) {
321 continue;
322 }
323 bool ret1 = incnode->foes(possProhibitorFrom, possProhibitorTo,
324 possProhibitedTo, *i);
325 bool ret2 = incnode->forbids(possProhibitorFrom, possProhibitorTo,
326 possProhibitedTo, *i,
327 regardNonSignalisedLowerPriority);
328 bool ret = ret1 || ret2;
329 if (ret) {
330#ifdef DEBUG_RIGHT_OF_WAY
331 if (DEBUGCOND) {
332 std::cout << " differentNodes: forbids\n";
333 }
334#endif
335 return true;
336 }
337 }
338
339 const EdgeVector& ev2 = possProhibitorTo->getConnectedEdges();
340 // go through the following edge,
341 // check whether one of these connections is prohibited
342 for (i = ev2.begin(); i != ev2.end(); ++i) {
343 std::vector<NBNode*>::const_iterator incoming2 =
344 find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorTo));
345 if (incoming2 == myControlledNodes.end()) {
346 continue;
347 }
348 NBNode* incnode2 = *incoming2;
349 if (incnode2 != outnode) {
350 continue;
351 }
352 if (incnode2->getDirection(possProhibitorTo, *i) != LinkDirection::STRAIGHT) {
353 continue;
354 }
355 bool ret1 = incnode2->foes(possProhibitorTo, *i,
356 possProhibitedFrom, possProhibitedTo);
357 bool ret2 = incnode2->forbids(possProhibitorTo, *i,
358 possProhibitedFrom, possProhibitedTo,
359 regardNonSignalisedLowerPriority);
360 bool ret = ret1 || ret2;
361 if (ret) {
362#ifdef DEBUG_RIGHT_OF_WAY
363 if (DEBUGCOND) {
364 std::cout << " differentNodes: forbids (2)\n";
365 }
366#endif
367 return true;
368 }
369 }
370#ifdef DEBUG_RIGHT_OF_WAY
371 if (DEBUGCOND) {
372 std::cout << " differentNodes: allows\n";
373 }
374#endif
375 return false;
376 }
377 // both links are located at the same node
378 // check using this node's information
379 const bool result = incnode->forbids(possProhibitorFrom, possProhibitorTo,
380 possProhibitedFrom, possProhibitedTo,
381 regardNonSignalisedLowerPriority);
382#ifdef DEBUG_RIGHT_OF_WAY
383 if (DEBUGCOND) {
384 std::cout << " sameNodes: " << (result ? "forbids" : "allows") << "\n";
385 }
386#endif
387 return result;
388}
389
390
391bool
392NBTrafficLightDefinition::foes(const NBEdge* const from1, const NBEdge* const to1,
393 const NBEdge* const from2, const NBEdge* const to2) const {
394 if (to1 == nullptr || to2 == nullptr) {
395 return false;
396 }
397 // retrieve both nodes (it is possible that a connection
398 std::vector<NBNode*>::const_iterator incoming =
399 find_if(myControlledNodes.begin(), myControlledNodes.end(),
401 std::vector<NBNode*>::const_iterator outgoing =
402 find_if(myControlledNodes.begin(), myControlledNodes.end(),
404 assert(incoming != myControlledNodes.end());
405 NBNode* incnode = *incoming;
406 NBNode* outnode = *outgoing;
407 if (incnode != outnode) {
408 return false;
409 }
410 return incnode->foes(from1, to1, from2, to2);
411}
412
413
414void
416 if (std::find(myControlledNodes.begin(), myControlledNodes.end(), node) == myControlledNodes.end()) {
417 myControlledNodes.push_back(node);
419 }
420 node->addTrafficLight(this);
421}
422
423
424void
426 std::vector<NBNode*>::iterator i = std::find(myControlledNodes.begin(), myControlledNodes.end(), node);
427 if (i != myControlledNodes.end()) {
428 myControlledNodes.erase(i);
429 }
430 // !!! remove in node?
431}
432
433
434void
435NBTrafficLightDefinition::addControlledInnerEdges(const std::vector<std::string>& edges) {
436 myControlledInnerEdges.insert(edges.begin(), edges.end());
437}
438
439
440std::vector<std::string>
442 return std::vector<std::string>(myControlledInnerEdges.begin(), myControlledInnerEdges.end());
443}
444
445
446const EdgeVector&
448 return myIncomingEdges;
449}
450
451
452void
454 int tlIndex = 0;
455 // build the list of links which are controled by the traffic light
456 std::vector<int> indirectLeft;
457 for (EdgeVector::iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
458 NBEdge* incoming = *i;
459 int noLanes = incoming->getNumLanes();
460 for (int j = 0; j < noLanes; j++) {
461 std::vector<NBEdge::Connection> connected = incoming->getConnectionsFromLane(j);
462 for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
463 const NBEdge::Connection& el = *k;
464 if (incoming->mayBeTLSControlled(el.fromLane, el.toEdge, el.toLane)) {
465 if (el.toEdge != nullptr && el.toLane >= (int) el.toEdge->getNumLanes()) {
466 throw ProcessError("Connection '" + incoming->getID() + "_" + toString(j) + "->" + el.toEdge->getID() + "_" + toString(el.toLane) + "' yields in a not existing lane.");
467 }
469 && isRailway(incoming->getPermissions())) {
470 // railways stay uncontrolled at rail crossing but they
471 // must be registered in MSRailCrossing
472 into.push_back(NBConnection(incoming, el.fromLane, el.toEdge, el.toLane, -1));
473 } else if (incoming->getToNode()->getType() == SumoXMLNodeType::RAIL_SIGNAL
474 && incoming->getToNode()->getDirection(incoming, el.toEdge) == LinkDirection::TURN) {
475 // turnarounds stay uncontrolled at rail signal
476 } else {
477 into.push_back(NBConnection(incoming, el.fromLane, el.toEdge, el.toLane, tlIndex++));
478 if (el.indirectLeft) {
479 indirectLeft.push_back((int)into.size() - 1);
480 }
481 }
482 }
483 }
484 }
485 }
486 if (indirectLeft.size() > 0) {
487 // assign linkIndex2 to indirect left turns
488 for (int i : indirectLeft) {
489 NBConnection& c = into[i];
490 // find straight connection with the same toEdge
491 for (const NBConnection& c2 : into) {
492 if (c2.getTo() == c.getTo() && c2.getFrom() != c.getFrom()) {
493 LinkDirection dir = c.getFrom()->getToNode()->getDirection(c2.getFrom(), c2.getTo());
494 if (dir == LinkDirection::STRAIGHT) {
495 c.setTLIndex2(c2.getTLIndex());
496 break;
497 }
498 }
499 }
500 }
501 }
502
503 if (into.size() > 0 && tlIndex == 0) {
504 WRITE_WARNINGF(TL("The rail crossing '%' does not have any roads."), getID());
505 }
506}
507
508
509bool
510NBTrafficLightDefinition::needsCont(const NBEdge* fromE, const NBEdge* toE, const NBEdge* otherFromE, const NBEdge* otherToE) const {
514 }
515 return std::find(myNeedsContRelation.begin(), myNeedsContRelation.end(),
516 StreamPair(fromE, toE, otherFromE, otherToE)) != myNeedsContRelation.end();
517}
518
519
520void
522 if (!amInvalid()) {
524 dummy.initNeedsContRelation();
526 for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
527 (*i)->removeTrafficLight(&dummy);
528 }
529 }
531}
532
533
534bool
535NBTrafficLightDefinition::rightOnRedConflict(int index, int foeIndex) const {
539 NBTrafficLightLogic* tllDummy = dummy.computeLogicAndConts(0, true);
540 delete tllDummy;
542 for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
543 (*i)->removeTrafficLight(&dummy);
544 }
546 //std::cout << " rightOnRedConflicts tls=" << getID() << " pro=" << getProgramID() << "\n";
547 //for (RightOnRedConflicts::const_iterator it = myRightOnRedConflicts.begin(); it != myRightOnRedConflicts.end(); ++it) {
548 // std::cout << " " << it->first << ", " << it->second << "\n";
549 //}
550 }
551 return std::find(myRightOnRedConflicts.begin(), myRightOnRedConflicts.end(), std::make_pair(index, foeIndex)) != myRightOnRedConflicts.end();
552}
553
554std::string
556 return getID() + ':' + getProgramID() + '@' + toString(this);
557}
558
559
560/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:266
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:265
#define TL(string)
Definition: MsgHandler.h:282
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:42
#define DEBUGCOND
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
TrafficLightType
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:77
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)
Definition: NBConnection.h:102
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:4137
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:1043
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:1143
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
Definition: NBEdge.cpp:4197
const std::string & getID() const
Definition: NBEdge.h:1526
std::vector< Connection > getConnectionsFromLane(int lane, NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
Definition: NBEdge.cpp:1241
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:526
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
Definition: NBEdge.cpp:3481
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
Definition: NBEdge.cpp:1335
Used for sorting the cells by the begin time they describe.
Definition: NBNode.h:760
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:2229
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:1896
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:275
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:2069
bool hasOutgoing(const NBEdge *const e) const
Returns whether the given edge starts at this node.
Definition: NBNode.cpp:1752
static const int FORWARD
edge directions (for pedestrian related stuff)
Definition: NBNode.h:206
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:2079
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
Definition: NBNode.cpp:365
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
Definition: NBOwnTLDef.cpp:260
void initNeedsContRelation() const
Definition: NBOwnTLDef.cpp:914
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 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.
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)
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.
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
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.
std::string getDescription() const
get ID and programID together (for convenient debugging)
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.
Definition: OptionsCont.cpp:59
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:278
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:227
int toLane
The lane the connections yields in.
Definition: NBEdge.h:233
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:230
data structure for caching needsCont information