SUMO - Simulation of Urban MObility
NBLoadedSUMOTLDef.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A complete traffic light logic loaded from a sumo-net. (opted to reimplement
10 // since NBLoadedTLDef is quite vissim specific)
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2011-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <vector>
34 #include <set>
35 #include <cassert>
36 #include <iterator>
38 #include <utils/common/ToString.h>
40 #include "NBTrafficLightLogic.h"
41 #include "NBOwnTLDef.h"
43 #include "NBLoadedSUMOTLDef.h"
44 #include "NBOwnTLDef.h"
45 #include "NBNode.h"
46 
47 //#define DEBUG_RECONSTRUCTION
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 
53 NBLoadedSUMOTLDef::NBLoadedSUMOTLDef(const std::string& id, const std::string& programID,
54  SUMOTime offset, TrafficLightType type) :
55  NBTrafficLightDefinition(id, programID, offset, type),
56  myTLLogic(0),
57  myReconstructAddedConnections(false),
58  myReconstructRemovedConnections(false),
59  myPhasesLoaded(false) {
60  myTLLogic = new NBTrafficLightLogic(id, programID, 0, offset, type);
61 }
62 
63 
65  // allow for adding a new program for the same def: take the programID from the new logic
66  NBTrafficLightDefinition(def->getID(), logic->getProgramID(), def->getOffset(), def->getType()),
67  myTLLogic(new NBTrafficLightLogic(logic)),
68  myOriginalNodes(def->getNodes().begin(), def->getNodes().end()),
71  assert(def->getOffset() == logic->getOffset());
72  assert(def->getType() == logic->getType());
74  myControlledNodes = def->getNodes();
75 }
76 
77 
79  delete myTLLogic;
80 }
81 
82 
84 NBLoadedSUMOTLDef::myCompute(int brakingTimeSeconds) {
85  // @todo what to do with those parameters?
86  UNUSED_PARAMETER(brakingTimeSeconds);
88  myTLLogic->closeBuilding(false);
91  return new NBTrafficLightLogic(myTLLogic);
92 }
93 
94 
95 void
96 NBLoadedSUMOTLDef::addConnection(NBEdge* from, NBEdge* to, int fromLane, int toLane, int linkIndex, bool reconstruct) {
97  assert(myTLLogic->getNumLinks() > 0); // logic should be loaded by now
98  if (linkIndex >= (int)myTLLogic->getNumLinks()) {
99  throw ProcessError("Invalid linkIndex " + toString(linkIndex) + " for traffic light '" + getID() +
100  "' with " + toString(myTLLogic->getNumLinks()) + " links.");
101  }
102  NBConnection conn(from, fromLane, to, toLane, linkIndex);
103  // avoid duplicates
104  remove_if(myControlledLinks.begin(), myControlledLinks.end(), connection_equal(conn));
105  myControlledLinks.push_back(conn);
106  addNode(from->getToNode());
107  addNode(to->getFromNode());
108  myOriginalNodes.insert(from->getToNode());
109  myOriginalNodes.insert(to->getFromNode());
110  // added connections are definitely controlled. make sure none are removed because they lie within the tl
111  // myControlledInnerEdges.insert(from->getID()); // @todo recheck: this appears to be obsolete
112  // set this information now so that it can be used while loading diffs
113  from->setControllingTLInformation(conn, getID());
114  myReconstructAddedConnections |= reconstruct;
115 }
116 
117 
118 void
124  for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
125  (*i)->removeTrafficLight(&dummy);
126  }
127  }
129  return; // will be called again in reconstructLogic()
130  }
131  // if nodes have been removed our links may have been invalidated as well
132  // since no logic will be built anyway there is no reason to inform any edges
133  if (amInvalid()) {
134  return;
135  }
136  // set the information about the link's positions within the tl into the
137  // edges the links are starting at, respectively
138  for (NBConnectionVector::const_iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
139  const NBConnection& c = *it;
140  if (c.getTLIndex() >= (int)myTLLogic->getNumLinks()) {
141  throw ProcessError("Invalid linkIndex " + toString(c.getTLIndex()) + " for traffic light '" + getID() +
142  "' with " + toString(myTLLogic->getNumLinks()) + " links.");
143  }
144  NBEdge* edge = c.getFrom();
145  if (edge != 0 && edge->getNumLanes() > c.getFromLane()) {
146  // logic may have yet to be reconstructed
148  }
149  }
150 }
151 
152 
153 void
155 
156 
157 void
158 NBLoadedSUMOTLDef::replaceRemoved(NBEdge* removed, int removedLane, NBEdge* by, int byLane) {
159  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); ++it) {
160  (*it).replaceFrom(removed, removedLane, by, byLane);
161  (*it).replaceTo(removed, removedLane, by, byLane);
162  }
163 }
164 
165 
166 void
167 NBLoadedSUMOTLDef::addPhase(SUMOTime duration, const std::string& state, SUMOTime minDur, SUMOTime maxDur) {
168  myTLLogic->addStep(duration, state, minDur, maxDur);
169 }
170 
171 
172 bool
174  if (myControlledLinks.size() == 0) {
175  return true;
176  }
177  // make sure that myControlledNodes are the original nodes
178  if (myControlledNodes.size() != myOriginalNodes.size()) {
179  return true;
180  }
181  for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
182  if (myOriginalNodes.count(*i) != 1) {
183  return true;
184  }
185  }
186  return false;
187 }
188 
189 
190 void
191 NBLoadedSUMOTLDef::removeConnection(const NBConnection& conn, bool reconstruct) {
192  NBConnectionVector::iterator it = myControlledLinks.begin();
193  // find the connection but ignore its TLIndex since it might have been
194  // invalidated by an earlier removal
195  for (; it != myControlledLinks.end(); ++it) {
196  if (it->getFrom() == conn.getFrom() &&
197  it->getTo() == conn.getTo() &&
198  it->getFromLane() == conn.getFromLane() &&
199  it->getToLane() == conn.getToLane()) {
200  break;
201  }
202  }
203  if (it == myControlledLinks.end()) {
204  // a traffic light doesn't always controll all connections at a junction
205  // especially when using the option --tls.join
206  return;
207  }
208  myReconstructRemovedConnections |= reconstruct;
209 }
210 
211 
212 void
214  myOffset = offset;
215  myTLLogic->setOffset(offset);
216 }
217 
218 
219 void
221  myType = type;
222  myTLLogic->setType(type);
223 }
224 
225 
226 void
228  if (myControlledLinks.size() == 0) {
230  }
231  myIncomingEdges.clear();
232  EdgeVector myOutgoing;
233  // collect the edges from the participating nodes
234  for (std::vector<NBNode*>::iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
235  const EdgeVector& incoming = (*i)->getIncomingEdges();
236  copy(incoming.begin(), incoming.end(), back_inserter(myIncomingEdges));
237  const EdgeVector& outgoing = (*i)->getOutgoingEdges();
238  copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
239  }
240  // check which of the edges are completely within the junction
241  // and which are uncontrolled as well (we already know myControlledLinks)
242  for (EdgeVector::iterator j = myIncomingEdges.begin(); j != myIncomingEdges.end();) {
243  NBEdge* edge = *j;
244  // an edge lies within the logic if it is outgoing as well as incoming
245  EdgeVector::iterator k = find(myOutgoing.begin(), myOutgoing.end(), edge);
246  if (k != myOutgoing.end()) {
247  if (myControlledInnerEdges.count(edge->getID()) == 0) {
248  bool controlled = false;
249  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
250  if ((*it).getFrom() == edge) {
251  controlled = true;
252  break;
253  }
254  }
255  if (controlled) {
256  myControlledInnerEdges.insert(edge->getID());
257  } else {
258  myEdgesWithin.push_back(edge);
259  (*j)->setIsInnerEdge();
260  ++j; //j = myIncomingEdges.erase(j);
261  continue;
262  }
263  }
264  }
265  ++j;
266  }
267 }
268 
269 
270 void
272  if (myControlledLinks.size() == 0) {
273  // maybe we only loaded a different program for a default traffic light.
274  // Try to build links now.
275  myOriginalNodes.insert(myControlledNodes.begin(), myControlledNodes.end());
276  collectAllLinks();
277  }
278 }
279 
280 
282 void
284  // avoid shifting twice if the edge is incoming and outgoing to a joined TLS
285  if (myShifted.count(edge) == 0) {
287  myShifted.insert(edge);
288  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
289  (*it).shiftLaneIndex(edge, offset);
290  }
291  }
292 }
293 
294 void
296  const int size = myTLLogic->getNumLinks();
297  int noLinksAll = 0;
298  for (NBConnectionVector::const_iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
299  const NBConnection& c = *it;
301  noLinksAll = MAX2(noLinksAll, (int)c.getTLIndex() + 1);
302  }
303  }
304  const int numNormalLinks = noLinksAll;
305  int oldCrossings = 0;
306  // collect crossings
307  std::vector<NBNode::Crossing*> crossings;
308  for (std::vector<NBNode*>::iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
309  const std::vector<NBNode::Crossing*>& c = (*i)->getCrossings();
310  // set tl indices for crossings
311  (*i)->setCrossingTLIndices(getID(), noLinksAll);
312  copy(c.begin(), c.end(), std::back_inserter(crossings));
313  noLinksAll += (int)c.size();
314  oldCrossings += (*i)->numCrossingsFromSumoNet();
315  }
316  if ((int)crossings.size() != oldCrossings) {
317  std::vector<NBTrafficLightLogic::PhaseDefinition> phases = myTLLogic->getPhases();
318  if (phases.size() > 0) {
319  // collect edges
320  EdgeVector fromEdges(size, (NBEdge*)0);
321  EdgeVector toEdges(size, (NBEdge*)0);
322  std::vector<int> fromLanes(size, 0);
323  collectEdgeVectors(fromEdges, toEdges, fromLanes);
324  const std::string crossingDefaultState(crossings.size(), 'r');
325 
326  // rebuild the logic (see NBOwnTLDef.cpp::myCompute)
328  SUMOTime brakingTime = TIME2STEPS(3);
329  //std::cout << "patchIfCrossingsAdded for " << getID() << " numPhases=" << phases.size() << "\n";
330  for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
331  if ((*it).state.find_first_of("yY") != std::string::npos) {
332  brakingTime = MAX2(brakingTime, it->duration);
333  }
334  const std::string state = it->state.substr(0, numNormalLinks) + crossingDefaultState;
335  NBOwnTLDef::addPedestrianPhases(newLogic, it->duration, it->minDur, it->maxDur, state, crossings, fromEdges, toEdges);
336  }
337  NBOwnTLDef::addPedestrianScramble(newLogic, noLinksAll, TIME2STEPS(10), brakingTime, crossings, fromEdges, toEdges);
338 
339  delete myTLLogic;
340  myTLLogic = newLogic;
341  } else {
342  WRITE_WARNING("Could not patch tlLogic '" + getID() + "' for changed crossings");
343  }
344  }
345 }
346 
347 
348 void
349 NBLoadedSUMOTLDef::collectEdgeVectors(EdgeVector& fromEdges, EdgeVector& toEdges, std::vector<int>& fromLanes) const {
350  assert(fromEdges.size() > 0);
351  assert(fromEdges.size() == toEdges.size());
352  const int size = (int)fromEdges.size();
353 
354  for (NBConnectionVector::const_iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
355  const NBConnection& c = *it;
357  if (c.getTLIndex() >= size) {
358  throw ProcessError("Invalid linkIndex " + toString(c.getTLIndex()) + " for traffic light '" + getID() +
359  "' with " + toString(size) + " links.");
360  }
361  fromEdges[c.getTLIndex()] = c.getFrom();
362  toEdges[c.getTLIndex()] = c.getTo();
363  fromLanes[c.getTLIndex()] = c.getFromLane();
364  }
365  }
366 }
367 
368 
369 void
371  if (!amInvalid() && !myNeedsContRelationReady) {
372  myNeedsContRelation.clear();
373  myRightOnRedConflicts.clear();
374  const bool controlledWithin = !OptionsCont::getOptions().getBool("tls.uncontrolled-within");
375  const std::vector<NBTrafficLightLogic::PhaseDefinition> phases = myTLLogic->getPhases();
376  for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
377  const std::string state = (*it).state;
378  for (NBConnectionVector::const_iterator it1 = myControlledLinks.begin(); it1 != myControlledLinks.end(); it1++) {
379  const NBConnection& c1 = *it1;
380  const int i1 = c1.getTLIndex();
381  if (i1 == NBConnection::InvalidTlIndex || (state[i1] != 'g' && state[i1] != 's') || c1.getFrom() == 0 || c1.getTo() == 0) {
382  continue;
383  }
384  for (NBConnectionVector::const_iterator it2 = myControlledLinks.begin(); it2 != myControlledLinks.end(); it2++) {
385  const NBConnection& c2 = *it2;
386  const int i2 = c2.getTLIndex();
388  && i2 != i1
389  && (state[i2] == 'G' || state[i2] == 'g')
390  && c2.getFrom() != 0 && c2.getTo() != 0) {
391  const bool rightTurnConflict = NBNode::rightTurnConflict(
392  c1.getFrom(), c1.getTo(), c1.getFromLane(), c2.getFrom(), c2.getTo(), c2.getFromLane());
393  const bool forbidden = forbids(c2.getFrom(), c2.getTo(), c1.getFrom(), c1.getTo(), true, controlledWithin);
394  const bool isFoes = foes(c2.getFrom(), c2.getTo(), c1.getFrom(), c1.getTo()) && !c2.getFrom()->isTurningDirectionAt(c2.getTo());
395  if (forbidden || rightTurnConflict) {
396  myNeedsContRelation.insert(StreamPair(c1.getFrom(), c1.getTo(), c2.getFrom(), c2.getTo()));
397  }
398  if (isFoes) {
399  myRightOnRedConflicts.insert(std::make_pair(i1, i2));
400  }
401  //std::cout << getID() << " i1=" << i1 << " i2=" << i2 << " rightTurnConflict=" << rightTurnConflict << " forbidden=" << forbidden << " isFoes=" << isFoes << "\n";
402  }
403  }
404  }
405  }
406  }
409 }
410 
411 
412 bool
413 NBLoadedSUMOTLDef::rightOnRedConflict(int index, int foeIndex) const {
414  if (amInvalid()) {
415  return false;
416  }
420  }
421  return std::find(myRightOnRedConflicts.begin(), myRightOnRedConflicts.end(), std::make_pair(index, foeIndex)) != myRightOnRedConflicts.end();
422 }
423 
424 
425 void
426 NBLoadedSUMOTLDef::registerModifications(bool addedConnections, bool removedConnections) {
427  myReconstructAddedConnections |= addedConnections;
428  myReconstructRemovedConnections |= removedConnections;
429 }
430 
431 void
433 #ifdef DEBUG_RECONSTRUCTION
435  std::cout << " reconstructLogic added=" << myReconstructAddedConnections << " removed=" << myReconstructRemovedConnections << " oldLInks\n";
436  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); ++it) {
437  std::cout << " " << *it << "\n";
438  }
439 #endif
442  if (!myPhasesLoaded) {
443  // rebuild the logic from scratch
444  // XXX if a connection with the same from- and to-edge already exisits, its states could be copied instead
447  dummy.setProgramID(getProgramID());
452  for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
453  (*i)->removeTrafficLight(&dummy);
454  }
455  delete myTLLogic;
456  myTLLogic = newLogic;
457  if (newLogic != 0) {
458  newLogic->setID(getID());
459  newLogic->setType(getType());
460  newLogic->setOffset(getOffset());
462  }
463  } else {
465  }
466  }
467  if (myReconstructRemovedConnections) {
468  myReconstructRemovedConnections = false;
469  // for each connection, check whether it is still valid
470  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end();) {
471  const NBConnection& con = (*it);
472  if (// edge still exists
473  find(myIncomingEdges.begin(), myIncomingEdges.end(), con.getFrom()) != myIncomingEdges.end()
474  // connection still exists
475  && con.getFrom()->hasConnectionTo(con.getTo(), con.getToLane(), con.getFromLane())
476  // connection is still set to be controlled
477  && con.getFrom()->mayBeTLSControlled(con.getFromLane(), con.getTo(), con.getToLane())) {
478  it++;
479  } else {
480  // remove connection
481  const int removed = con.getTLIndex();
482  it = myControlledLinks.erase(it);
483  if (!myPhasesLoaded) {
484  // shift index off successive connections and remove entry from all phases
485  for (NBConnectionVector::iterator j = myControlledLinks.begin(); j != myControlledLinks.end(); j++) {
486  NBConnection& other = *j;
487  if (other.getTLIndex() > removed) {
488  other.setTLIndex(other.getTLIndex() - 1);
489  }
490  }
491  // rebuild the logic
492  const std::vector<NBTrafficLightLogic::PhaseDefinition> phases = myTLLogic->getPhases();
494  for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
495  std::string newState = it->state;
496  newState.erase(newState.begin() + removed);
497  newLogic->addStep(it->duration, newState);
498  }
499  delete myTLLogic;
500  myTLLogic = newLogic;
501  }
502  }
503  }
505  }
506 #ifdef DEBUG_RECONSTRUCTION
507  if (debugPrintModified) {
508  std::cout << " newLinks:\n";
509  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); ++it) {
510  std::cout << " " << *it << "\n";
511  }
512  }
513 #endif
514 }
515 
516 /****************************************************************************/
517 
void addPhase(SUMOTime duration, const std::string &state, SUMOTime minDur, SUMOTime maxDur)
Adds a phase to the logic the new phase is inserted at the end of the list of already added phases...
void removeConnection(const NBConnection &conn, bool reconstruct=true)
removes the given connection from the traffic light if recontruct=true, reconstructs the logic and in...
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
bool setControllingTLInformation(const NBConnection &c, const std::string &tlID)
Returns if the link could be set as to be controlled.
Definition: NBEdge.cpp:2486
TrafficLightType getType() const
get the algorithm type (static etc..)
TrafficLightType myType
The algorithm type for the traffic light.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
NBLoadedSUMOTLDef(const std::string &id, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled ...
Definition: NBConnection.h:100
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light ...
void collectEdges()
Build the list of participating edges.
void collectAllLinks()
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
static const std::string DummyID
id for temporary definitions
void setOffset(SUMOTime offset)
Sets the offset of this tls.
void reconstructLogic()
adapt to removal or addition of connections
int getNumLinks()
Returns the number of participating links.
RightOnRedConflicts myRightOnRedConflicts
A SUMO-compliant built logic for a traffic light.
TrafficLightType getType() const
get the algorithm type (static etc..)
bool myReconstructAddedConnections
whether the logic must be reconstructed
void registerModifications(bool addedConnections, bool removedConnections)
register changes that necessitate recomputation
EdgeVector myIncomingEdges
The list of incoming edges.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getProgramID() const
Returns the ProgramID.
The representation of a single edge during network building.
Definition: NBEdge.h:71
class for identifying connections
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
Definition: NBEdge.cpp:2475
int getFromLane() const
returns the from-lane
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
The base class for traffic light logic definitions.
void setOffset(SUMOTime offset)
Sets the offset of this tls.
T MAX2(T a, T b)
Definition: StdDefs.h:74
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
SUMOTime myOffset
The offset in the program.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:40
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
static bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane, bool lefthand=false)
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
Definition: NBNode.cpp:1375
void setTLIndex(int tlIndex)
Definition: NBConnection.h:105
SUMOTime getOffset()
Returns the offset.
void setType(TrafficLightType type)
set the algorithm type (static etc..)
const std::string & getID() const
Returns the id.
Definition: Named.h:66
static std::string addPedestrianPhases(NBTrafficLightLogic *logic, SUMOTime greenTime, SUMOTime minDur, SUMOTime maxDur, std::string state, const std::vector< NBNode::Crossing * > &crossings, const EdgeVector &fromEdges, const EdgeVector &toEdges)
add 1 or 2 phases depending on the presence of pedestrian crossings
Definition: NBOwnTLDef.cpp:460
virtual void collectEdges()
Build the list of participating edges.
static const int InvalidTlIndex
Definition: NBConnection.h:126
bool hasConnectionTo(NBEdge *destEdge, int destLane, int fromLane=-1) const
Retrieves info about a connection to a certain lane of a certain edge.
Definition: NBEdge.cpp:1064
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
std::set< std::string > myControlledInnerEdges
Set of inner edges that shall be controlled, though.
static void addPedestrianScramble(NBTrafficLightLogic *logic, int noLinksAll, SUMOTime greenTime, SUMOTime yellowTime, const std::vector< NBNode::Crossing * > &crossings, const EdgeVector &fromEdges, const EdgeVector &toEdges)
add an additional pedestrian phase if there are crossings that did not get green yet ...
Definition: NBOwnTLDef.cpp:668
const NBConnectionVector & getControlledLinks() const
returns the controlled links (depends on previous call to collectLinks)
void patchIfCrossingsAdded()
repair the plan if controlled nodes received pedestrian crossings
void addConnection(NBEdge *from, NBEdge *to, int fromLane, int toLane, int linkIndex, bool reconstruct=true)
Adds a connection and immediately informs the edges.
std::set< NBNode * > myOriginalNodes
The original nodes for which the loaded logic is valid.
void initNeedsContRelation() const
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:414
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition: NBEdge.cpp:2422
void setProgramID(const std::string &programID)
Sets the programID.
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
const std::vector< NBNode * > & getNodes() const
Returns the list of controlled nodes.
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.
void closeBuilding(bool checkVarDurations=true)
closes the building process
SUMOTime getOffset() const
Returns the offset of first switch.
std::set< NBEdge * > myShifted
set of edges with shifted lane indices (to avoid shifting twice)
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:435
void setID(const std::string &newID)
resets the id
Definition: Named.h:74
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:41
int getToLane() const
returns the to-lane
void collectLinks()
Collects the links participating in this traffic light (only if not previously loaded) ...
NBEdge * getTo() const
returns the to-edge (end of the connection)
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
~NBLoadedSUMOTLDef()
Destructor.
long long int SUMOTime
Definition: TraCIDefs.h:52
data structure for caching needsCont information
void setType(TrafficLightType type)
Sets the algorithm type of this tls.
void collectEdgeVectors(EdgeVector &fromEdges, EdgeVector &toEdges, std::vector< int > &fromLanes) const
Collects the edges for each tlIndex.
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:54
void addStep(SUMOTime duration, const std::string &state, int index=-1)
Adds a phase to the logic.
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBOwnTLDef.cpp:543
NBConnectionVector myControlledLinks
The list of controlled links.
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
void shiftTLConnectionLaneIndex(NBEdge *edge, int offset)
patches signal plans by modifying lane indices
NBTrafficLightLogic * myTLLogic
phases are added directly to myTLLogic which is then returned in myCompute()
TrafficLightType
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.
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:428