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