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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A complete traffic light logic loaded from a sumo-net. (opted to reimplement
18 // since NBLoadedTLDef is quite vissim specific)
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <vector>
27 #include <set>
28 #include <cassert>
29 #include <iterator>
31 #include <utils/common/ToString.h>
33 #include "NBTrafficLightLogic.h"
34 #include "NBOwnTLDef.h"
36 #include "NBLoadedSUMOTLDef.h"
37 #include "NBNetBuilder.h"
38 #include "NBOwnTLDef.h"
39 #include "NBNode.h"
40 
41 //#define DEBUG_RECONSTRUCTION
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 
47 NBLoadedSUMOTLDef::NBLoadedSUMOTLDef(const std::string& id, const std::string& programID,
48  SUMOTime offset, TrafficLightType type) :
49  NBTrafficLightDefinition(id, programID, offset, type),
50  myTLLogic(nullptr),
51  myReconstructAddedConnections(false),
52  myReconstructRemovedConnections(false),
53  myPhasesLoaded(false) {
54  myTLLogic = new NBTrafficLightLogic(id, programID, 0, offset, type);
55 }
56 
57 
59  // allow for adding a new program for the same def: take the programID from the new logic
60  NBTrafficLightDefinition(def->getID(), logic->getProgramID(), def->getOffset(), def->getType()),
61  myTLLogic(new NBTrafficLightLogic(logic)),
62  myOriginalNodes(def->getNodes().begin(), def->getNodes().end()),
65  myPhasesLoaded(false) {
66  assert(def->getOffset() == logic->getOffset());
67  assert(def->getType() == logic->getType());
69  myControlledNodes = def->getNodes();
70  NBLoadedSUMOTLDef* sumoDef = dynamic_cast<NBLoadedSUMOTLDef*>(def);
72  if (sumoDef != nullptr) {
75  }
76 }
77 
78 
80  delete myTLLogic;
81 }
82 
83 
85 NBLoadedSUMOTLDef::myCompute(int brakingTimeSeconds) {
86  // @todo what to do with those parameters?
87  UNUSED_PARAMETER(brakingTimeSeconds);
89  myTLLogic->closeBuilding(false);
92  return new NBTrafficLightLogic(myTLLogic);
93 }
94 
95 
96 void
97 NBLoadedSUMOTLDef::addConnection(NBEdge* from, NBEdge* to, int fromLane, int toLane, int linkIndex, bool reconstruct) {
98  assert(myTLLogic->getNumLinks() > 0); // logic should be loaded by now
99  if (linkIndex >= (int)myTLLogic->getNumLinks()) {
100  throw ProcessError("Invalid linkIndex " + toString(linkIndex) + " for traffic light '" + getID() +
101  "' with " + toString(myTLLogic->getNumLinks()) + " links.");
102  }
103  NBConnection conn(from, fromLane, to, toLane, linkIndex);
104  // avoid duplicates
105  auto newEnd = remove_if(myControlledLinks.begin(), myControlledLinks.end(), connection_equal(conn));
106  // remove_if does not remove, only re-order
107  myControlledLinks.erase(newEnd, myControlledLinks.end());
108  myControlledLinks.push_back(conn);
109  addNode(from->getToNode());
110  addNode(to->getFromNode());
111  myOriginalNodes.insert(from->getToNode());
112  myOriginalNodes.insert(to->getFromNode());
113  // added connections are definitely controlled. make sure none are removed because they lie within the tl
114  // myControlledInnerEdges.insert(from->getID()); // @todo recheck: this appears to be obsolete
115  // set this information now so that it can be used while loading diffs
116  from->setControllingTLInformation(conn, getID());
117  myReconstructAddedConnections |= reconstruct;
118 }
119 
120 
121 void
127  for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
128  (*i)->removeTrafficLight(&dummy);
129  }
130  }
132  return; // will be called again in reconstructLogic()
133  }
134  // if nodes have been removed our links may have been invalidated as well
135  // since no logic will be built anyway there is no reason to inform any edges
136  if (amInvalid()) {
137  return;
138  }
139  // set the information about the link's positions within the tl into the
140  // edges the links are starting at, respectively
141  for (NBConnectionVector::const_iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
142  const NBConnection& c = *it;
143  if (c.getTLIndex() >= (int)myTLLogic->getNumLinks()) {
144  throw ProcessError("Invalid linkIndex " + toString(c.getTLIndex()) + " for traffic light '" + getID() +
145  "' with " + toString(myTLLogic->getNumLinks()) + " links.");
146  }
147  NBEdge* edge = c.getFrom();
148  if (edge != nullptr && edge->getNumLanes() > c.getFromLane()) {
149  // logic may have yet to be reconstructed
151  }
152  }
153 }
154 
155 
156 void
158 
159 
160 void
161 NBLoadedSUMOTLDef::replaceRemoved(NBEdge* removed, int removedLane, NBEdge* by, int byLane) {
162  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); ++it) {
163  (*it).replaceFrom(removed, removedLane, by, byLane);
164  (*it).replaceTo(removed, removedLane, by, byLane);
165  }
166 }
167 
168 
169 void
170 NBLoadedSUMOTLDef::addPhase(SUMOTime duration, const std::string& state, SUMOTime minDur, SUMOTime maxDur) {
171  myTLLogic->addStep(duration, state, minDur, maxDur);
172 }
173 
174 
175 bool
177  if (myControlledLinks.size() == 0) {
178  return true;
179  }
180  // make sure that myControlledNodes are the original nodes
181  if (myControlledNodes.size() != myOriginalNodes.size()) {
182  //std::cout << " myControlledNodes=" << myControlledNodes.size() << " myOriginalNodes=" << myOriginalNodes.size() << "\n";
183  return true;
184  }
185  if (myIncomingEdges.size() == 0) {
186  return true;
187  }
188  for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
189  if (myOriginalNodes.count(*i) != 1) {
190  //std::cout << " node " << (*i)->getID() << " missing from myOriginalNodes\n";
191  return true;
192  }
193  }
194  return false;
195 }
196 
197 
198 void
199 NBLoadedSUMOTLDef::removeConnection(const NBConnection& conn, bool reconstruct) {
200  NBConnectionVector::iterator it = myControlledLinks.begin();
201  // find the connection but ignore its TLIndex since it might have been
202  // invalidated by an earlier removal
203  for (; it != myControlledLinks.end(); ++it) {
204  if (it->getFrom() == conn.getFrom() &&
205  it->getTo() == conn.getTo() &&
206  it->getFromLane() == conn.getFromLane() &&
207  it->getToLane() == conn.getToLane()) {
208  break;
209  }
210  }
211  if (it == myControlledLinks.end()) {
212  // a traffic light doesn't always controll all connections at a junction
213  // especially when using the option --tls.join
214  return;
215  }
216  myReconstructRemovedConnections |= reconstruct;
217 }
218 
219 
220 void
222  myOffset = offset;
223  myTLLogic->setOffset(offset);
224 }
225 
226 
227 void
229  myType = type;
230  myTLLogic->setType(type);
231 }
232 
233 
234 void
236  if (myControlledLinks.size() == 0) {
238  }
239  myIncomingEdges.clear();
240  EdgeVector myOutgoing;
241  // collect the edges from the participating nodes
242  for (std::vector<NBNode*>::iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
243  const EdgeVector& incoming = (*i)->getIncomingEdges();
244  copy(incoming.begin(), incoming.end(), back_inserter(myIncomingEdges));
245  const EdgeVector& outgoing = (*i)->getOutgoingEdges();
246  copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
247  }
248  // check which of the edges are completely within the junction
249  // and which are uncontrolled as well (we already know myControlledLinks)
250  for (EdgeVector::iterator j = myIncomingEdges.begin(); j != myIncomingEdges.end();) {
251  NBEdge* edge = *j;
252  // an edge lies within the logic if it is outgoing as well as incoming
253  EdgeVector::iterator k = find(myOutgoing.begin(), myOutgoing.end(), edge);
254  if (k != myOutgoing.end()) {
255  if (myControlledInnerEdges.count(edge->getID()) == 0) {
256  bool controlled = false;
257  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
258  if ((*it).getFrom() == edge) {
259  controlled = true;
260  break;
261  }
262  }
263  if (controlled) {
264  myControlledInnerEdges.insert(edge->getID());
265  } else {
266  myEdgesWithin.push_back(edge);
267  (*j)->setInternal();
268  ++j; //j = myIncomingEdges.erase(j);
269  continue;
270  }
271  }
272  }
273  ++j;
274  }
275 }
276 
277 
278 void
280  if (myControlledLinks.size() == 0) {
281  // maybe we only loaded a different program for a default traffic light.
282  // Try to build links now.
283  myOriginalNodes.insert(myControlledNodes.begin(), myControlledNodes.end());
284  collectAllLinks();
285  }
286 }
287 
288 
290 void
291 NBLoadedSUMOTLDef::shiftTLConnectionLaneIndex(NBEdge* edge, int offset, int threshold) {
292  // avoid shifting twice if the edge is incoming and outgoing to a joined TLS
293  if (myShifted.count(edge) == 0) {
295  myShifted.insert(edge);
296  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
297  (*it).shiftLaneIndex(edge, offset, threshold);
298  }
299  }
300 }
301 
302 void
304  const int size = myTLLogic->getNumLinks();
305  int noLinksAll = 0;
306  for (NBConnectionVector::const_iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
307  const NBConnection& c = *it;
309  noLinksAll = MAX2(noLinksAll, (int)c.getTLIndex() + 1);
310  }
311  }
312  const int numNormalLinks = noLinksAll;
313  int oldCrossings = 0;
314  // collect crossings
315  bool customIndex = false;
316  std::vector<NBNode::Crossing*> crossings;
317  for (std::vector<NBNode*>::iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
318  const std::vector<NBNode::Crossing*>& c = (*i)->getCrossings();
319  // set tl indices for crossings
320  customIndex |= (*i)->setCrossingTLIndices(getID(), noLinksAll);
321  copy(c.begin(), c.end(), std::back_inserter(crossings));
322  noLinksAll += (int)c.size();
323  oldCrossings += (*i)->numCrossingsFromSumoNet();
324  }
325  if ((int)crossings.size() != oldCrossings) {
326  std::vector<NBTrafficLightLogic::PhaseDefinition> phases = myTLLogic->getPhases();
327  // do not rebuilt crossing states there are custom indices and the state string is long enough
328  if (phases.size() > 0 && (
329  (int)(phases.front().state.size()) < noLinksAll ||
330  ((int)(phases.front().state.size()) > noLinksAll && !customIndex))) {
331  // collect edges
332  EdgeVector fromEdges(size, (NBEdge*)nullptr);
333  EdgeVector toEdges(size, (NBEdge*)nullptr);
334  std::vector<int> fromLanes(size, 0);
335  collectEdgeVectors(fromEdges, toEdges, fromLanes);
336  const std::string crossingDefaultState(crossings.size(), 'r');
337 
338  // rebuild the logic (see NBOwnTLDef.cpp::myCompute)
340  SUMOTime brakingTime = TIME2STEPS(computeBrakingTime(OptionsCont::getOptions().getFloat("tls.yellow.min-decel")));
341  //std::cout << "patchIfCrossingsAdded for " << getID() << " numPhases=" << phases.size() << "\n";
342  for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
343  const std::string state = it->state.substr(0, numNormalLinks) + crossingDefaultState;
344  NBOwnTLDef::addPedestrianPhases(newLogic, it->duration, it->minDur, it->maxDur, state, crossings, fromEdges, toEdges);
345  }
346  NBOwnTLDef::addPedestrianScramble(newLogic, noLinksAll, TIME2STEPS(10), brakingTime, crossings, fromEdges, toEdges);
347 
348  delete myTLLogic;
349  myTLLogic = newLogic;
350  } else if (phases.size() == 0) {
351  WRITE_WARNING("Could not patch tlLogic '" + getID() + "' for changed crossings");
352  }
353  }
354 }
355 
356 
357 void
358 NBLoadedSUMOTLDef::collectEdgeVectors(EdgeVector& fromEdges, EdgeVector& toEdges, std::vector<int>& fromLanes) const {
359  assert(fromEdges.size() > 0);
360  assert(fromEdges.size() == toEdges.size());
361  const int size = (int)fromEdges.size();
362 
363  for (NBConnectionVector::const_iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
364  const NBConnection& c = *it;
366  if (c.getTLIndex() >= size) {
367  throw ProcessError("Invalid linkIndex " + toString(c.getTLIndex()) + " for traffic light '" + getID() +
368  "' with " + toString(size) + " links.");
369  }
370  fromEdges[c.getTLIndex()] = c.getFrom();
371  toEdges[c.getTLIndex()] = c.getTo();
372  fromLanes[c.getTLIndex()] = c.getFromLane();
373  }
374  }
375 }
376 
377 
378 void
380  if (!amInvalid() && !myNeedsContRelationReady) {
381  myNeedsContRelation.clear();
382  myRightOnRedConflicts.clear();
383  const bool controlledWithin = !OptionsCont::getOptions().getBool("tls.uncontrolled-within");
384  const std::vector<NBTrafficLightLogic::PhaseDefinition> phases = myTLLogic->getPhases();
385  for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
386  const std::string state = (*it).state;
387  for (NBConnectionVector::const_iterator it1 = myControlledLinks.begin(); it1 != myControlledLinks.end(); it1++) {
388  const NBConnection& c1 = *it1;
389  const int i1 = c1.getTLIndex();
390  if (i1 == NBConnection::InvalidTlIndex || (state[i1] != 'g' && state[i1] != 's') || c1.getFrom() == nullptr || c1.getTo() == nullptr) {
391  continue;
392  }
393  for (NBConnectionVector::const_iterator it2 = myControlledLinks.begin(); it2 != myControlledLinks.end(); it2++) {
394  const NBConnection& c2 = *it2;
395  const int i2 = c2.getTLIndex();
397  && i2 != i1
398  && (state[i2] == 'G' || state[i2] == 'g')
399  && c2.getFrom() != nullptr && c2.getTo() != nullptr) {
400  const bool rightTurnConflict = NBNode::rightTurnConflict(
401  c1.getFrom(), c1.getTo(), c1.getFromLane(), c2.getFrom(), c2.getTo(), c2.getFromLane());
402  const bool forbidden = forbids(c2.getFrom(), c2.getTo(), c1.getFrom(), c1.getTo(), true, controlledWithin);
403  const bool isFoes = foes(c2.getFrom(), c2.getTo(), c1.getFrom(), c1.getTo()) && !c2.getFrom()->isTurningDirectionAt(c2.getTo());
404  if (forbidden || rightTurnConflict) {
405  myNeedsContRelation.insert(StreamPair(c1.getFrom(), c1.getTo(), c2.getFrom(), c2.getTo()));
406  }
407  if (isFoes) {
408  myRightOnRedConflicts.insert(std::make_pair(i1, i2));
409  }
410  //std::cout << getID() << " i1=" << i1 << " i2=" << i2 << " rightTurnConflict=" << rightTurnConflict << " forbidden=" << forbidden << " isFoes=" << isFoes << "\n";
411  }
412  }
413  }
414  }
415  }
418 }
419 
420 
421 bool
422 NBLoadedSUMOTLDef::rightOnRedConflict(int index, int foeIndex) const {
423  if (amInvalid()) {
424  return false;
425  }
429  }
430  return std::find(myRightOnRedConflicts.begin(), myRightOnRedConflicts.end(), std::make_pair(index, foeIndex)) != myRightOnRedConflicts.end();
431 }
432 
433 
434 void
435 NBLoadedSUMOTLDef::registerModifications(bool addedConnections, bool removedConnections) {
436  myReconstructAddedConnections |= addedConnections;
437  myReconstructRemovedConnections |= removedConnections;
438 }
439 
440 void
442  const bool netedit = NBNetBuilder::runningNetedit();
443 #ifdef DEBUG_RECONSTRUCTION
445  std::cout << " reconstructLogic added=" << myReconstructAddedConnections << " removed=" << myReconstructRemovedConnections << " valid=" << hasValidIndices() << " oldLinks:\n";
446  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); ++it) {
447  std::cout << " " << *it << "\n";
448  }
449 #endif
452  // do not rebuild the logic when running netedit and all links are already covered by the program
453  if (!myPhasesLoaded && !(netedit && hasValidIndices())) {
454  // rebuild the logic from scratch
455  // XXX if a connection with the same from- and to-edge already exisits, its states could be copied instead
458  dummy.setProgramID(getProgramID());
463  for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
464  (*i)->removeTrafficLight(&dummy);
465  }
466  delete myTLLogic;
467  myTLLogic = newLogic;
468  if (newLogic != nullptr) {
469  newLogic->setID(getID());
470  newLogic->setType(getType());
471  newLogic->setOffset(getOffset());
473  // reset crossing custom indices
474  for (NBNode* n : myControlledNodes) {
475  for (NBNode::Crossing* c : n->getCrossings()) {
476  c->customTLIndex = NBConnection::InvalidTlIndex;
477  }
478  }
479 
480  }
481  } else {
483  }
484  }
487  // for each connection, check whether it is still valid
488  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end();) {
489  const NBConnection con = (*it);
490  if (// edge still exists
491  find(myIncomingEdges.begin(), myIncomingEdges.end(), con.getFrom()) != myIncomingEdges.end()
492  // connection still exists
493  && con.getFrom()->hasConnectionTo(con.getTo(), con.getToLane(), con.getFromLane())
494  // connection is still set to be controlled
495  && con.getFrom()->mayBeTLSControlled(con.getFromLane(), con.getTo(), con.getToLane())) {
496  it++;
497  } else {
498  // remove connection
499  const int removed = con.getTLIndex();
500  it = myControlledLinks.erase(it);
501  // no automatic modificaions when running netedit
502  if (!myPhasesLoaded && !(netedit && hasValidIndices())) {
503  // shift index off successive connections and remove entry from all phases if the tlIndex was only used by this connection
504  bool exclusive = true;
505  for (NBConnection& other : myControlledLinks) {
506  if (other != con && other.getTLIndex() == removed) {
507  exclusive = false;
508  break;
509  }
510  }
511  if (exclusive) {
512  // shift indices above the removed index downward
513  for (NBConnection& other : myControlledLinks) {
514  if (other.getTLIndex() > removed) {
515  other.setTLIndex(other.getTLIndex() - 1);
516  }
517  }
518  // shift crossing custom indices above the removed index downward
519  for (NBNode* n : myControlledNodes) {
520  for (NBNode::Crossing* c : n->getCrossings()) {
521  if (c->customTLIndex > removed) {
522  c->customTLIndex--;
523  }
524  }
525  }
526  // rebuild the logic
527  const std::vector<NBTrafficLightLogic::PhaseDefinition> phases = myTLLogic->getPhases();
529  for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
530  std::string newState = it->state;
531  newState.erase(newState.begin() + removed);
532  newLogic->addStep(it->duration, newState);
533  }
534  delete myTLLogic;
535  myTLLogic = newLogic;
536  }
537  }
538  }
539  }
541  }
542 #ifdef DEBUG_RECONSTRUCTION
543  if (debugPrintModified) {
544  std::cout << " newLinks:\n";
545  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); ++it) {
546  std::cout << " " << *it << "\n";
547  }
548  }
549 #endif
550 }
551 
552 
553 int
555  int maxIndex = -1;
556  for (const NBConnection& c : myControlledLinks) {
557  maxIndex = MAX2(maxIndex, c.getTLIndex());
558  }
559  for (NBNode* n : myControlledNodes) {
560  for (NBNode::Crossing* c : n->getCrossings()) {
561  maxIndex = MAX2(maxIndex, c->tlLinkIndex);
562  maxIndex = MAX2(maxIndex, c->tlLinkIndex2);
563  }
564  }
565  return maxIndex;
566 }
567 
568 
569 int
571  return myTLLogic->getNumLinks() - 1;
572 }
573 
574 
575 bool
577  for (const NBConnection& c : myControlledLinks) {
578  if (c.getTLIndex() == NBConnection::InvalidTlIndex) {
579  return false;
580  }
581  }
582  for (NBNode* n : myControlledNodes) {
583  for (NBNode::Crossing* c : n->getCrossings()) {
584  if (c->tlLinkIndex == NBConnection::InvalidTlIndex) {
585  return false;
586  }
587  }
588  }
589  // method getMaxIndex() is const but cannot be declare as such due to inheritance
590  return const_cast<NBLoadedSUMOTLDef*>(this)->getMaxIndex() < myTLLogic->getNumLinks();
591 }
592 
593 
594 bool
596  const int maxIndex = getMaxIndex();
597  if (maxIndex >= 0 && maxIndex + 1 < myTLLogic->getNumLinks()) {
598  myTLLogic->setStateLength(maxIndex + 1);
599  return true;
600  }
601  return false;
602 }
603 
604 void
608  const int maxIndex = MAX2(getMaxIndex(), def->getMaxIndex());
609  myTLLogic->setStateLength(maxIndex + 1);
610  myControlledLinks.insert(myControlledLinks.end(), def->getControlledLinks().begin(), def->getControlledLinks().end());
611  myOriginalNodes.insert(def->getNodes().begin(), def->getNodes().end());
612 }
613 
614 bool
616  // count how often each index is used
617  std::map<int, int> indexUsage;
618  for (const NBConnection& c : myControlledLinks) {
619  indexUsage[c.getTLIndex()]++;
620  }
621  for (NBNode* n : myControlledNodes) {
622  for (NBNode::Crossing* c : n->getCrossings()) {
623  indexUsage[c->tlLinkIndex]++;
624  indexUsage[c->tlLinkIndex2]++;
625  }
626  }
627  for (auto it : indexUsage) {
628  if (it.first >= 0 && it.second > 1) {
629  return true;
630  }
631  }
632  return false;
633 }
634 
635 /****************************************************************************/
636 
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
Definition: NBEdge.cpp:2737
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:2748
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBOwnTLDef.cpp:584
TrafficLightType myType
The algorithm type for the traffic light.
long long int SUMOTime
Definition: SUMOTime.h:36
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.
A loaded (complete) traffic light logic.
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:65
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:76
int computeBrakingTime(double minDecel) const
Computes the time vehicles may need to brake.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
bool hasValidIndices() const
return whether all tls link indices are valid
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:78
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
SUMOTime myOffset
The offset in the program.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:33
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
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:1554
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:724
virtual void collectEdges()
Build the list of participating edges.
static const int InvalidTlIndex
Definition: NBConnection.h:120
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
void updateParameter(const std::map< std::string, std::string > &mapArg)
Adds or updates all given parameters from the map.
virtual int getMaxIndex()=0
Returns the maximum index controlled by this traffic light and assigned to a connection.
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:420
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:1158
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light ...
int getMaxValidIndex()
Returns the maximum index controlled by this traffic 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.
void joinLogic(NBTrafficLightDefinition *def)
join nodes and states from the given logic (append red state)
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:86
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:499
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:34
static bool runningNetedit()
whether netbuilding takes place in the context of NETEDIT
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:2684
int getFromLane() const
returns the from-lane
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Represents a single node (junction) during network building.
Definition: NBNode.h:68
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
A definition of a pedestrian crossing.
Definition: NBNode.h:125
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
~NBLoadedSUMOTLDef()
Destructor.
bool usingSignalGroups() const
whether this definition uses signal group (multiple connections with the same link index) ...
data structure for caching needsCont information
void setType(TrafficLightType type)
Sets the algorithm type of this tls.
void shiftTLConnectionLaneIndex(NBEdge *edge, int offset, int threshold=-1)
patches signal plans by modifying lane indices with the given offset, only indices with a value above...
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled ...
Definition: NBConnection.h:94
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:434
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:47
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:441
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
NBTrafficLightLogic * myTLLogic
phases are added directly to myTLLogic which is then returned in myCompute()
int getMaxIndex()
return the highest known tls link index used by any controlled connection or crossing ...
TrafficLightType
void collectEdgeVectors(EdgeVector &fromEdges, EdgeVector &toEdges, std::vector< int > &fromLanes) const
Collects the edges for each tlIndex.