SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NBOwnTLDef.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A traffic light logics which must be computed (only nodes/edges are given)
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2015 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 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <cassert>
36 #include <iterator>
38 #include "NBNode.h"
39 #include "NBOwnTLDef.h"
40 #include "NBTrafficLightLogic.h"
43 #include <utils/common/ToString.h>
45 #include <utils/options/Option.h>
46 
47 #ifdef CHECK_MEMORY_LEAKS
48 #include <foreign/nvwa/debug_new.h>
49 #endif // CHECK_MEMORY_LEAKS
50 
51 
52 // ===========================================================================
53 // member method definitions
54 // ===========================================================================
55 NBOwnTLDef::NBOwnTLDef(const std::string& id,
56  const std::vector<NBNode*>& junctions, SUMOTime offset,
57  TrafficLightType type) :
58  NBTrafficLightDefinition(id, junctions, DefaultProgramID, offset, type),
59  myHaveSinglePhase(false)
60 {}
61 
62 
63 NBOwnTLDef::NBOwnTLDef(const std::string& id, NBNode* junction, SUMOTime offset,
64  TrafficLightType type) :
65  NBTrafficLightDefinition(id, junction, DefaultProgramID, offset, type),
66  myHaveSinglePhase(false)
67 {}
68 
69 
70 NBOwnTLDef::NBOwnTLDef(const std::string& id, SUMOTime offset,
71  TrafficLightType type) :
72  NBTrafficLightDefinition(id, DefaultProgramID, offset, type),
73  myHaveSinglePhase(false)
74 {}
75 
76 
78 
79 
80 int
81 NBOwnTLDef::getToPrio(const NBEdge* const e) {
82  return e->getJunctionPriority(e->getToNode());
83 }
84 
85 
88  switch (dir) {
89  case LINKDIR_STRAIGHT:
90  case LINKDIR_PARTLEFT:
91  case LINKDIR_PARTRIGHT:
92  return 2.;
93  case LINKDIR_LEFT:
94  case LINKDIR_RIGHT:
95  return .5;
96  case LINKDIR_NODIR:
97  case LINKDIR_TURN:
98  return 0;
99  }
100  return 0;
101 }
102 
103 SUMOReal
105  SUMOReal val = 0;
106  for (unsigned int e1l = 0; e1l < e1->getNumLanes(); e1l++) {
107  std::vector<NBEdge::Connection> approached1 = e1->getConnectionsFromLane(e1l);
108  for (unsigned int e2l = 0; e2l < e2->getNumLanes(); e2l++) {
109  std::vector<NBEdge::Connection> approached2 = e2->getConnectionsFromLane(e2l);
110  for (std::vector<NBEdge::Connection>::iterator e1c = approached1.begin(); e1c != approached1.end(); ++e1c) {
111  if (e1->getTurnDestination() == (*e1c).toEdge) {
112  continue;
113  }
114  for (std::vector<NBEdge::Connection>::iterator e2c = approached2.begin(); e2c != approached2.end(); ++e2c) {
115  if (e2->getTurnDestination() == (*e2c).toEdge) {
116  continue;
117  }
118  if (!foes(e1, (*e1c).toEdge, e2, (*e2c).toEdge)) {
119  val += getDirectionalWeight(e1->getToNode()->getDirection(e1, (*e1c).toEdge));
120  val += getDirectionalWeight(e2->getToNode()->getDirection(e2, (*e2c).toEdge));
121  }
122  }
123  }
124  }
125  }
126  return val;
127 }
128 
129 
130 std::pair<NBEdge*, NBEdge*>
132  std::pair<NBEdge*, NBEdge*> bestPair(static_cast<NBEdge*>(0), static_cast<NBEdge*>(0));
133  SUMOReal bestValue = -1;
134  for (EdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
135  for (EdgeVector::const_iterator j = i + 1; j != edges.end(); ++j) {
136  const SUMOReal value = computeUnblockedWeightedStreamNumber(*i, *j);
137  if (value > bestValue) {
138  bestValue = value;
139  bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
140  } else if (value == bestValue) {
141  const SUMOReal ca = GeomHelper::getMinAngleDiff((*i)->getAngleAtNode((*i)->getToNode()), (*j)->getAngleAtNode((*j)->getToNode()));
142  const SUMOReal oa = GeomHelper::getMinAngleDiff(bestPair.first->getAngleAtNode(bestPair.first->getToNode()), bestPair.second->getAngleAtNode(bestPair.second->getToNode()));
143  if (fabs(oa - ca) < NUMERICAL_EPS) { // break ties by id
144  if (bestPair.first->getID() < (*i)->getID()) {
145  bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
146  }
147  } else if (oa < ca) {
148  bestPair = std::pair<NBEdge*, NBEdge*>(*i, *j);
149  }
150  }
151  }
152  }
153  return bestPair;
154 }
155 
156 
157 std::pair<NBEdge*, NBEdge*>
159  if (incoming.size() == 1) {
160  // only one there - return the one
161  std::pair<NBEdge*, NBEdge*> ret(*incoming.begin(), static_cast<NBEdge*>(0));
162  incoming.clear();
163  return ret;
164  }
165  // determine the best combination
166  // by priority, first
167  EdgeVector used;
168  std::sort(incoming.begin(), incoming.end(), edge_by_incoming_priority_sorter());
169  used.push_back(*incoming.begin()); // the first will definitely be used
170  // get the ones with the same priority
171  int prio = getToPrio(*used.begin());
172  for (EdgeVector::iterator i = incoming.begin() + 1; i != incoming.end() && prio == getToPrio(*i); ++i) {
173  used.push_back(*i);
174  }
175  // if there only lower priorised, use these, too
176  if (used.size() < 2) {
177  used = incoming;
178  }
179  std::pair<NBEdge*, NBEdge*> ret = getBestCombination(used);
180  incoming.erase(find(incoming.begin(), incoming.end(), ret.first));
181  incoming.erase(find(incoming.begin(), incoming.end(), ret.second));
182  return ret;
183 }
184 
186 NBOwnTLDef::myCompute(const NBEdgeCont&, unsigned int brakingTimeSeconds) {
187  return computeLogicAndConts(brakingTimeSeconds);
188 }
189 
191 NBOwnTLDef::computeLogicAndConts(unsigned int brakingTimeSeconds, bool onlyConts) {
192  myNeedsContRelation.clear();
193  const SUMOTime brakingTime = TIME2STEPS(brakingTimeSeconds);
194  const SUMOTime leftTurnTime = TIME2STEPS(6); // make configurable
195  // build complete lists first
196  const EdgeVector& incoming = getIncomingEdges();
197  EdgeVector fromEdges, toEdges;
198  std::vector<bool> isTurnaround;
199  std::vector<int> fromLanes;
200  unsigned int noLanesAll = 0;
201  unsigned int noLinksAll = 0;
202  for (unsigned int i1 = 0; i1 < incoming.size(); i1++) {
203  unsigned int noLanes = incoming[i1]->getNumLanes();
204  noLanesAll += noLanes;
205  for (unsigned int i2 = 0; i2 < noLanes; i2++) {
206  NBEdge* fromEdge = incoming[i1];
207  std::vector<NBEdge::Connection> approached = fromEdge->getConnectionsFromLane(i2);
208  noLinksAll += (unsigned int) approached.size();
209  for (unsigned int i3 = 0; i3 < approached.size(); i3++) {
210  if (!fromEdge->mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
211  --noLinksAll;
212  continue;
213  }
214  assert(i3 < approached.size());
215  NBEdge* toEdge = approached[i3].toEdge;
216  fromEdges.push_back(fromEdge);
217  fromLanes.push_back((int)i2);
218  toEdges.push_back(toEdge);
219  if (toEdge != 0) {
220  isTurnaround.push_back(fromEdge->isTurningDirectionAt(toEdge));
221  } else {
222  isTurnaround.push_back(true);
223  }
224  }
225  }
226  }
227  // collect crossings
228  std::vector<NBNode::Crossing> crossings;
229  for (std::vector<NBNode*>::iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
230  const std::vector<NBNode::Crossing>& c = (*i)->getCrossings();
231  if (!onlyConts) {
232  // set tl indices for crossings
233  (*i)->setCrossingTLIndices(noLinksAll);
234  }
235  copy(c.begin(), c.end(), std::back_inserter(crossings));
236  noLinksAll += (unsigned int)c.size();
237  }
238 
239  NBTrafficLightLogic* logic = new NBTrafficLightLogic(getID(), getProgramID(), noLinksAll, myOffset, myType);
240  EdgeVector toProc = incoming;
241  const SUMOTime greenTime = TIME2STEPS(OptionsCont::getOptions().getInt("tls.green.time"));
242  // build all phases
243  while (toProc.size() > 0) {
244  std::pair<NBEdge*, NBEdge*> chosen;
245  if (incoming.size() == 2) {
246  // if there are only 2 incoming edges we need to decide whether they are a crossing or a "continuation"
247  // @node: this heuristic could be extended to also check the number of outgoing edges
248  SUMOReal angle = fabs(NBHelpers::relAngle(toProc[0]->getAngleAtNode(toProc[0]->getToNode()), toProc[1]->getAngleAtNode(toProc[1]->getToNode())));
249  // angle would be 180 for straight opposing incoming edges
250  if (angle < 135) {
251  chosen = std::pair<NBEdge*, NBEdge*>(toProc[0], static_cast<NBEdge*>(0));
252  toProc.erase(toProc.begin());
253  } else {
254  chosen = getBestPair(toProc);
255  }
256  } else {
257  chosen = getBestPair(toProc);
258  }
259  unsigned int pos = 0;
260  std::string state((size_t) noLinksAll, 'r');
261  // plain straight movers
262  for (unsigned int i1 = 0; i1 < (unsigned int) incoming.size(); ++i1) {
263  NBEdge* fromEdge = incoming[i1];
264  const bool inChosen = fromEdge == chosen.first || fromEdge == chosen.second; //chosen.find(fromEdge)!=chosen.end();
265  const unsigned int numLanes = fromEdge->getNumLanes();
266  for (unsigned int i2 = 0; i2 < numLanes; i2++) {
267  std::vector<NBEdge::Connection> approached = fromEdge->getConnectionsFromLane(i2);
268  for (unsigned int i3 = 0; i3 < approached.size(); ++i3) {
269  if (!fromEdge->mayBeTLSControlled(i2, approached[i3].toEdge, approached[i3].toLane)) {
270  continue;
271  }
272  if (inChosen) {
273  state[pos] = 'G';
274  } else {
275  state[pos] = 'r';
276  }
277  ++pos;
278  }
279  }
280  }
281  // correct behaviour for those that are not in chosen, but may drive, though
282  for (unsigned int i1 = 0; i1 < pos; ++i1) {
283  if (state[i1] == 'G') {
284  continue;
285  }
286  bool isForbidden = false;
287  for (unsigned int i2 = 0; i2 < pos && !isForbidden; ++i2) {
288  if (state[i2] == 'G' && !isTurnaround[i2] &&
289  (forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1], true) || forbids(fromEdges[i1], toEdges[i1], fromEdges[i2], toEdges[i2], true))) {
290  isForbidden = true;
291  }
292  }
293  if (!isForbidden && !hasCrossing(fromEdges[i1], toEdges[i1], crossings)) {
294  state[i1] = 'G';
295  }
296  }
297  // correct behaviour for those that have to wait (mainly left-mover)
298  bool haveForbiddenLeftMover = false;
299  std::vector<bool> rightTurnConflicts(pos, false);
300  for (unsigned int i1 = 0; i1 < pos; ++i1) {
301  if (state[i1] != 'G') {
302  continue;
303  }
304  for (unsigned int i2 = 0; i2 < pos; ++i2) {
305  if ((state[i2] == 'G' || state[i2] == 'g')) {
306  if (fromEdges[i2]->getToNode()->rightTurnConflict(
307  fromEdges[i1], toEdges[i1], fromLanes[i1], fromEdges[i2], toEdges[i2], fromLanes[i2])) {
308  rightTurnConflicts[i1] = true;
309  }
310  if (forbids(fromEdges[i2], toEdges[i2], fromEdges[i1], toEdges[i1], true) || rightTurnConflicts[i1]) {
311  state[i1] = 'g';
312  myNeedsContRelation.insert(StreamPair(fromEdges[i1], toEdges[i1], fromEdges[i2], toEdges[i2]));
313  if (!isTurnaround[i1]) {
314  haveForbiddenLeftMover = true;
315  }
316  }
317  }
318  }
319  }
320  const std::string vehicleState = state; // backup state before pedestrian modifications
321  state = addPedestrianPhases(logic, greenTime, state, crossings, fromEdges, toEdges);
322  // pedestrians have 'r' from here on
323  for (unsigned int i1 = pos; i1 < pos + crossings.size(); ++i1) {
324  state[i1] = 'r';
325  }
326 
327  if (brakingTime > 0) {
328  // build yellow (straight)
329  for (unsigned int i1 = 0; i1 < pos; ++i1) {
330  if (state[i1] != 'G' && state[i1] != 'g') {
331  continue;
332  }
333  if ((vehicleState[i1] >= 'a' && vehicleState[i1] <= 'z') && haveForbiddenLeftMover && !rightTurnConflicts[i1]) {
334  continue;
335  }
336  state[i1] = 'y';
337  }
338  // add step
339  logic->addStep(brakingTime, state);
340  }
341 
342  if (haveForbiddenLeftMover && !myHaveSinglePhase) {
343  // build left green
344  for (unsigned int i1 = 0; i1 < pos; ++i1) {
345  if (state[i1] == 'Y' || state[i1] == 'y') {
346  state[i1] = 'r';
347  continue;
348  }
349  if (state[i1] == 'g') {
350  state[i1] = 'G';
351  }
352  }
353  // add step
354  logic->addStep(leftTurnTime, state);
355 
356  // build left yellow
357  if (brakingTime > 0) {
358  for (unsigned int i1 = 0; i1 < pos; ++i1) {
359  if (state[i1] != 'G' && state[i1] != 'g') {
360  continue;
361  }
362  state[i1] = 'y';
363  }
364  // add step
365  logic->addStep(brakingTime, state);
366  }
367  }
368  }
369  const SUMOTime totalDuration = logic->getDuration();
370  // this computation only makes sense for single nodes
372  if (totalDuration > 0) {
373  if (totalDuration > 3 * (greenTime + 2 * brakingTime + leftTurnTime)) {
374  WRITE_WARNING("The traffic light '" + getID() + "' has a high cycle time of " + time2string(totalDuration) + ".");
375  }
376  logic->closeBuilding();
377  return logic;
378  } else {
379  delete logic;
380  return 0;
381  }
382 }
383 
384 
385 bool
386 NBOwnTLDef::hasCrossing(const NBEdge* from, const NBEdge* to, const std::vector<NBNode::Crossing>& crossings) {
387  assert(from != 0);
388  assert(to != 0);
389  for (std::vector<NBNode::Crossing>::const_iterator it = crossings.begin(); it != crossings.end(); it++) {
390  const NBNode::Crossing& cross = *it;
391  // only check connections at this crossings node
392  if (from->getToNode() == cross.node) {
393  for (EdgeVector::const_iterator it_e = cross.edges.begin(); it_e != cross.edges.end(); ++it_e) {
394  const NBEdge* edge = *it_e;
395  if (edge == from || edge == to) {
396  return true;
397  }
398  }
399  }
400  }
401  return false;
402 }
403 
404 
405 std::string
407  std::string state, const std::vector<NBNode::Crossing>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges) {
408  const SUMOTime pedClearingTime = TIME2STEPS(5); // compute based on length of the crossing
409  const SUMOTime minPedTime = TIME2STEPS(4); // compute: must be able to reach the middle of the second "Richtungsfahrbahn"
410  const std::string orig = state;
411  state = patchStateForCrossings(state, crossings, fromEdges, toEdges);
412  if (orig == state) {
413  // add step
414  logic->addStep(greenTime, state);
415  } else {
416  const SUMOTime pedTime = greenTime - pedClearingTime;
417  if (pedTime >= minPedTime) {
418  // ensure clearing time for pedestrians
419  const size_t pedStates = crossings.size();
420  logic->addStep(pedTime, state);
421  state = state.substr(0, state.size() - pedStates) + std::string(pedStates, 'r');
422  logic->addStep(pedClearingTime, state);
423  } else {
424  state = orig;
425  // not safe for pedestrians.
426  logic->addStep(greenTime, state);
427  }
428  }
429  return state;
430 }
431 
432 
433 std::string
434 NBOwnTLDef::patchStateForCrossings(const std::string& state, const std::vector<NBNode::Crossing>& crossings, const EdgeVector& fromEdges, const EdgeVector& toEdges) {
435  std::string result = state;
436  const unsigned int pos = (unsigned int)(state.size() - crossings.size()); // number of controlled vehicle links
437  for (int ic = 0; ic < (int)crossings.size(); ++ic) {
438  const int i1 = pos + ic;
439  const NBNode::Crossing& cross = crossings[ic];
440  bool isForbidden = false;
441  for (unsigned int i2 = 0; i2 < pos && !isForbidden; ++i2) {
442  // only check connections at this crossings node
443  if (fromEdges[i2] != 0 && toEdges[i2] != 0 && fromEdges[i2]->getToNode() == cross.node) {
444  for (EdgeVector::const_iterator it = cross.edges.begin(); it != cross.edges.end(); ++it) {
445  const NBEdge* edge = *it;
446  const LinkDirection i2dir = cross.node->getDirection(fromEdges[i2], toEdges[i2]);
447  if (state[i2] != 'r' && (edge == fromEdges[i2] ||
448  (edge == toEdges[i2] && (i2dir == LINKDIR_STRAIGHT || i2dir == LINKDIR_PARTLEFT || i2dir == LINKDIR_PARTRIGHT)))) {
449  isForbidden = true;
450  break;
451  }
452  }
453  }
454  }
455  if (!isForbidden) {
456  result[i1] = 'G';
457  } else {
458  result[i1] = 'r';
459  }
460  }
461 
462  // correct behaviour for roads that are in conflict with a pedestrian crossing
463  for (unsigned int i1 = 0; i1 < pos; ++i1) {
464  if (result[i1] == 'G') {
465  for (int ic = 0; ic < (int)crossings.size(); ++ic) {
466  const NBNode::Crossing& crossing = crossings[ic];
467  if (fromEdges[i1] != 0 && toEdges[i1] != 0 && fromEdges[i1]->getToNode() == crossing.node) {
468  const int i2 = pos + ic;
469  if (result[i2] == 'G' && crossing.node->mustBrakeForCrossing(fromEdges[i1], toEdges[i1], crossing)) {
470  result[i1] = 'g';
471  break;
472  }
473  }
474  }
475  }
476  }
477  return result;
478 }
479 
480 
481 void
483 
484 
485 void
487  collectAllLinks();
488 }
489 
490 
491 void
493  // assign participating nodes to the request
494  collectNodes();
495  // collect the information about participating edges and links
496  collectEdges();
497  collectLinks();
498 }
499 
500 
501 void
503  // set the information about the link's positions within the tl into the
504  // edges the links are starting at, respectively
505  for (NBConnectionVector::const_iterator j = myControlledLinks.begin(); j != myControlledLinks.end(); ++j) {
506  const NBConnection& conn = *j;
507  NBEdge* edge = conn.getFrom();
508  edge->setControllingTLInformation(conn, getID());
509  }
510 }
511 
512 
513 void
514 NBOwnTLDef::remapRemoved(NBEdge* /*removed*/, const EdgeVector& /*incoming*/,
515  const EdgeVector& /*outgoing*/) {}
516 
517 
518 void
519 NBOwnTLDef::replaceRemoved(NBEdge* /*removed*/, int /*removedLane*/,
520  NBEdge* /*by*/, int /*byLane*/) {}
521 
522 
523 void
526  assert(myControlledNodes.size() > 0);
527  // there are basically 2 cases for controlling multiple nodes
528  // a) a complex (unjoined) intersection. Here, internal junctions should
529  // not be needed since real nodes are used instead
530  // b) two far-away junctions which shall be coordinated
531  // This is likely to mess up the bestPair computation for each
532  // individual node and thus generate incorrect needsCont data
533  //
534  // Therefore we compute needsCont for individual nodes which doesn't
535  // matter for a) and is better for b)
536  myNeedsContRelation.clear();
537  for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
538  NBNode* n = *i;
539  NBOwnTLDef dummy("dummy", n, 0, TLTYPE_STATIC);
541  dummy.computeLogicAndConts(0, true);
542  myNeedsContRelation.insert(dummy.myNeedsContRelation.begin(), dummy.myNeedsContRelation.end());
543  n->removeTrafficLight(&dummy);
544  }
546  }
547 
548 }
549 
550 /****************************************************************************/
static std::string patchStateForCrossings(const std::string &state, const std::vector< NBNode::Crossing > &crossings, const EdgeVector &fromEdges, const EdgeVector &toEdges)
compute phase state in regard to pedestrian crossings
Definition: NBOwnTLDef.cpp:434
The link is a partial left direction.
bool setControllingTLInformation(const NBConnection &c, const std::string &tlID)
Returns if the link could be set as to be controlled.
Definition: NBEdge.cpp:1822
TrafficLightType myType
The algorithm type for the traffic light.
void collectAllLinks()
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
void closeBuilding()
closes the building process
A SUMO-compliant built logic for a traffic light.
const std::string & getProgramID() const
Returns the ProgramID.
The representation of a single edge during network building.
Definition: NBEdge.h:71
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
Definition: NBEdge.cpp:1811
The link is a 180 degree turn.
void collectNodes()
Collects the nodes participating in this traffic light.
Definition: NBOwnTLDef.cpp:482
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
The base class for traffic light logic definitions.
static bool hasCrossing(const NBEdge *from, const NBEdge *to, const std::vector< NBNode::Crossing > &crossings)
compute whether the given connection is crossed by pedestrians
Definition: NBOwnTLDef.cpp:386
bool isForbidden(SVCPermissions permissions)
Returns whether an edge with the given permission is a forbidden edge.
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
NBTrafficLightLogic * computeLogicAndConts(unsigned int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
Definition: NBOwnTLDef.cpp:191
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
Removes the given traffic light from this node.
Definition: NBNode.cpp:304
std::vector< Connection > getConnectionsFromLane(unsigned int lane) const
Returns connections from a given lane.
Definition: NBEdge.cpp:747
SUMOTime myOffset
The offset in the program.
NBEdge * getFrom() const
returns the from-edge (start of the connection)
The link is a (hard) left direction.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
std::pair< NBEdge *, NBEdge * > getBestPair(EdgeVector &incoming)
Returns the combination of two edges from the given which has most unblocked streams.
Definition: NBOwnTLDef.cpp:158
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
The link is a straight direction.
const std::string & getID() const
Returns the id.
Definition: Named.h:60
virtual void collectEdges()
Build the list of participating edges.
bool mustBrakeForCrossing(const NBEdge *const from, const NBEdge *const to, const Crossing &crossing) const
Returns the information whether the described flow must brake for the given crossing.
Definition: NBNode.cpp:1181
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBOwnTLDef.cpp:519
std::pair< NBEdge *, NBEdge * > getBestCombination(const EdgeVector &edges)
Returns the combination of two edges from the given which has most unblocked streams.
Definition: NBOwnTLDef.cpp:131
bool myHaveSinglePhase
Whether left-mover should not have an additional phase.
Definition: NBOwnTLDef.h:245
unsigned int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:347
~NBOwnTLDef()
Destructor.
Definition: NBOwnTLDef.cpp:77
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition: NBEdge.cpp:1756
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
The link is a (hard) right direction.
static std::string addPedestrianPhases(NBTrafficLightLogic *logic, SUMOTime greenTime, 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:406
The link is a partial right direction.
SUMOTime getDuration() const
Returns the duration of the complete cycle.
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition: NBEdge.cpp:1225
SUMOReal computeUnblockedWeightedStreamNumber(const NBEdge *const e1, const NBEdge *const e2)
Returns how many streams outgoing from the edges can pass the junction without being blocked...
Definition: NBOwnTLDef.cpp:104
NBOwnTLDef(const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBOwnTLDef.cpp:55
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:371
void setTLControllingInformation(const NBEdgeCont &ec) const
Informs edges about being controlled by a tls.
Definition: NBOwnTLDef.cpp:502
void collectLinks()
Collects the links participating in this traffic light If a link could not be found.
Definition: NBOwnTLDef.cpp:486
SUMOReal getDirectionalWeight(LinkDirection dir)
Returns the weight of a stream given its direction.
Definition: NBOwnTLDef.cpp:87
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
NBTrafficLightLogic * myCompute(const NBEdgeCont &ec, unsigned int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBOwnTLDef.cpp:186
static SUMOReal getMinAngleDiff(SUMOReal angle1, SUMOReal angle2)
Returns the minimum distance (clockwise/counter-clockwise) between both angles.
Definition: GeomHelper.cpp:405
const NBNode * node
The parent node of this crossing.
Definition: NBNode.h:139
int SUMOTime
Definition: SUMOTime.h:43
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:141
Represents a single node (junction) during network building.
Definition: NBNode.h:75
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.
A definition of a pedestrian crossing.
Definition: NBNode.h:134
#define SUMOReal
Definition: config.h:218
void initNeedsContRelation() const
Definition: NBOwnTLDef.cpp:524
static SUMOReal relAngle(SUMOReal angle1, SUMOReal angle2)
Definition: NBHelpers.cpp:63
#define NUMERICAL_EPS
Definition: config.h:162
data structure for caching needsCont information
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.
Sorts edges by their priority within the node they end at.
Definition: NBOwnTLDef.h:228
void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
Definition: NBOwnTLDef.cpp:492
NBConnectionVector myControlledLinks
The list of controlled links.
NBEdge * getTurnDestination(bool possibleDestination=false) const
Definition: NBEdge.cpp:2039
int getToPrio(const NBEdge *const e)
Returns this edge's priority at the node it ends at.
Definition: NBOwnTLDef.cpp:81
TrafficLightType
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
Definition: NBOwnTLDef.cpp:514
The link has no direction (is a dead end link)
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.
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing) const
Returns the representation of the described stream's direction.
Definition: NBNode.cpp:1311