Eclipse SUMO - Simulation of Urban MObility
NBAlgorithms_Ramps.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // Algorithms for highway on-/off-ramps computation
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <cassert>
27 #include <utils/common/ToString.h>
28 #include "NBNetBuilder.h"
29 #include "NBNodeCont.h"
30 #include "NBNode.h"
31 #include "NBEdge.h"
32 #include "NBAlgorithms_Ramps.h"
33 
34 #define OFFRAMP_LOOKBACK 500
35 
36 //#define DEBUG_RAMPS
37 #define DEBUGNODEID "260479469"
38 #define DEBUGCOND(obj) ((obj != 0 && (obj)->getID() == DEBUGNODEID))
39 
40 // ===========================================================================
41 // static members
42 // ===========================================================================
43 const std::string NBRampsComputer::ADDED_ON_RAMP_EDGE("-AddedOnRampEdge");
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 // ---------------------------------------------------------------------------
49 // NBRampsComputer
50 // ---------------------------------------------------------------------------
51 void
52 NBRampsComputer::computeRamps(NBNetBuilder& nb, OptionsCont& oc, bool mayAddOrRemove) {
53  const bool guessAndAdd = oc.getBool("ramps.guess") && mayAddOrRemove;
54  const double minHighwaySpeed = oc.getFloat("ramps.min-highway-speed");
55  const double maxRampSpeed = oc.getFloat("ramps.max-ramp-speed");
56  const double rampLength = oc.getFloat("ramps.ramp-length");
57  const double minWeaveLength = oc.getFloat("ramps.min-weave-length");
58  const bool dontSplit = oc.getBool("ramps.no-split");
59  NBNodeCont& nc = nb.getNodeCont();
60  NBEdgeCont& ec = nb.getEdgeCont();
62  std::set<NBEdge*> incremented;
63  // collect join exclusions
64  std::set<std::string> noramps;
65  if (oc.isSet("ramps.unset")) {
66  std::vector<std::string> edges = oc.getStringVector("ramps.unset");
67  noramps.insert(edges.begin(), edges.end());
68  }
69  // exclude roundabouts
70  const std::set<EdgeSet>& roundabouts = ec.getRoundabouts();
71  for (std::set<EdgeSet>::const_iterator it_round = roundabouts.begin();
72  it_round != roundabouts.end(); ++it_round) {
73  for (EdgeSet::const_iterator it_edge = it_round->begin(); it_edge != it_round->end(); ++it_edge) {
74  noramps.insert((*it_edge)->getID());
75  }
76  }
77  // exclude public transport edges
78  nb.getPTStopCont().addEdges2Keep(oc, noramps);
79  nb.getPTLineCont().addEdges2Keep(oc, noramps);
80  nb.getParkingCont().addEdges2Keep(oc, noramps);
81 
82  // check whether on-off ramps shall be guessed
83  if (guessAndAdd || oc.getBool("ramps.guess-acceleration-lanes")) {
84  for (const auto& it : ec) {
85  it.second->markOffRamp(false);
86  }
87 
88  // if an edge is part of two ramps, ordering is important
89  std::set<NBNode*, ComparatorIdLess> potOnRamps;
90  std::set<NBNode*, ComparatorIdLess> potOffRamps;
91  for (const auto& i : nc) {
92  NBNode* cur = i.second;
93  if (mayNeedOnRamp(cur, minHighwaySpeed, maxRampSpeed, noramps, minWeaveLength)) {
94  potOnRamps.insert(cur);
95  }
96  if (mayNeedOffRamp(cur, minHighwaySpeed, maxRampSpeed, noramps)) {
97  potOffRamps.insert(cur);
98  }
99  }
100  for (std::set<NBNode*, ComparatorIdLess>::const_iterator i = potOnRamps.begin(); i != potOnRamps.end(); ++i) {
101  buildOnRamp(*i, nc, ec, dc, rampLength, dontSplit || !guessAndAdd, guessAndAdd);
102  }
103  for (std::set<NBNode*, ComparatorIdLess>::const_iterator i = potOffRamps.begin(); i != potOffRamps.end(); ++i) {
104  buildOffRamp(*i, nc, ec, dc, rampLength, dontSplit || !guessAndAdd, guessAndAdd, potOnRamps);
105  }
106  }
107  // check whether on-off ramps are specified
108  if (oc.isSet("ramps.set") && mayAddOrRemove) {
109  std::vector<std::string> edges = oc.getStringVector("ramps.set");
110  std::set<NBNode*, ComparatorIdLess> potOnRamps;
111  for (std::vector<std::string>::iterator i = edges.begin(); i != edges.end(); ++i) {
112  NBEdge* e = ec.retrieve(*i);
113  if (noramps.count(*i) != 0) {
114  WRITE_WARNING("Can not build ramp on edge '" + *i + "' - the edge is unsuitable.");
115  continue;
116  }
117  if (e == nullptr) {
118  WRITE_WARNING("Can not build on ramp on edge '" + *i + "' - the edge is not known.");
119  continue;
120  }
121  NBNode* from = e->getFromNode();
122  if (from->getIncomingEdges().size() == 2 && from->getOutgoingEdges().size() == 1) {
123  buildOnRamp(from, nc, ec, dc, rampLength, dontSplit, true);
124  potOnRamps.insert(from);
125  }
126  // load edge again to check offramps
127  e = ec.retrieve(*i);
128  if (e == nullptr) {
129  WRITE_WARNING("Can not build off ramp on edge '" + *i + "' - the edge is not known.");
130  continue;
131  }
132  NBNode* to = e->getToNode();
133  if (to->getIncomingEdges().size() == 1 && to->getOutgoingEdges().size() == 2) {
134  buildOffRamp(to, nc, ec, dc, rampLength, dontSplit, true, potOnRamps);
135  }
136  }
137  }
138 }
139 
140 
141 bool
142 NBRampsComputer::mayNeedOnRamp(NBNode* cur, double minHighwaySpeed, double maxRampSpeed, const std::set<std::string>& noramps, double minWeaveLength) {
143  if (cur->getOutgoingEdges().size() != 1 || cur->getIncomingEdges().size() != 2) {
144  return false;
145  }
146  NBEdge* potHighway, *potRamp, *cont;
147  getOnRampEdges(cur, &potHighway, &potRamp, &cont);
148  // may be an on-ramp
149  if (fulfillsRampConstraints(potHighway, potRamp, cont, minHighwaySpeed, maxRampSpeed, noramps)) {
150  // prevent short weaving section
151  double seen = cont->getLength();
152  while (seen < minWeaveLength) {
153  if (cont->getToNode()->getOutgoingEdges().size() > 1) {
154  return false;
155  } else if (cont->getToNode()->getOutgoingEdges().size() == 0) {
156  return true;
157  }
158  cont = cont->getToNode()->getOutgoingEdges().front();
159  seen += cont->getLength();
160  }
161  return true;
162  } else {
163  return false;
164  }
165 }
166 
167 
168 bool
169 NBRampsComputer::mayNeedOffRamp(NBNode* cur, double minHighwaySpeed, double maxRampSpeed, const std::set<std::string>& noramps) {
170  if (cur->getIncomingEdges().size() != 1 || cur->getOutgoingEdges().size() != 2) {
171  return false;
172  }
173  // may be an off-ramp
174  NBEdge* potHighway, *potRamp, *prev;
175  getOffRampEdges(cur, &potHighway, &potRamp, &prev);
176  return fulfillsRampConstraints(potHighway, potRamp, prev, minHighwaySpeed, maxRampSpeed, noramps);
177 }
178 
179 
180 void
181 NBRampsComputer::buildOnRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes) {
182  NBEdge* potHighway, *potRamp, *cont;
183  getOnRampEdges(cur, &potHighway, &potRamp, &cont);
184 #ifdef DEBUG_RAMPS
185  if (DEBUGCOND(cur)) {
186  std::cout << "buildOnRamp cur=" << cur->getID() << " hw=" << potHighway->getID() << " ramp=" << potRamp->getID() << " cont=" << cont->getID() << "\n";
187  }
188 #endif
189  // compute the number of lanes to append
190  const int firstLaneNumber = cont->getNumLanes();
191  int toAdd = (potRamp->getNumLanes() + potHighway->getNumLanes()) - firstLaneNumber;
192  NBEdge* first = cont;
193  NBEdge* last = cont;
194  NBEdge* curr = cont;
195  std::set<NBEdge*> incremented;
196  if (addLanes && toAdd > 0 && std::find(incremented.begin(), incremented.end(), cont) == incremented.end()) {
197  double currLength = 0;
198  while (curr != nullptr && currLength + curr->getGeometry().length() - POSITION_EPS < rampLength) {
199  if (find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
200  curr->incLaneNo(toAdd);
202  curr->invalidateConnections(true);
203  }
204  incremented.insert(curr);
205  moveRampRight(curr, toAdd);
206  currLength += curr->getGeometry().length(); // !!! loaded length?
207  last = curr;
208  // mark acceleration lanes
209  for (int i = 0; i < curr->getNumLanes() - potHighway->getNumLanes(); ++i) {
210  curr->setAcceleration(i, true);
211  }
212  }
213  NBNode* nextN = curr->getToNode();
214  if (nextN->getOutgoingEdges().size() == 1 && nextN->getIncomingEdges().size() == 1) {
215  curr = nextN->getOutgoingEdges()[0];
216  if (curr->getNumLanes() != firstLaneNumber) {
217  // the number of lanes changes along the computation; we'll stop...
218  curr = nullptr;
219  } else if (curr->isTurningDirectionAt(last)) {
220  // turnarounds certainly should not be included in a ramp
221  curr = nullptr;
222  } else if (curr == potHighway || curr == potRamp) {
223  // circular connectivity. do not split!
224  curr = nullptr;
225  }
226  } else {
227  // ambiguous; and, in fact, what should it be? ...stop
228  curr = nullptr;
229  }
230  }
231  // check whether a further split is necessary
232  if (curr != nullptr && !dontSplit && currLength - POSITION_EPS < rampLength && curr->getNumLanes() == firstLaneNumber && std::find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
233  // there is enough place to build a ramp; do it
234  bool wasFirst = first == curr;
235  NBNode* rn = new NBNode(curr->getID() + "-AddedOnRampNode", curr->getGeometry().positionAtOffset(rampLength - currLength));
236  if (!nc.insert(rn)) {
237  throw ProcessError("Ups - could not build on-ramp for edge '" + curr->getID() + "' (node could not be build)!");
238  }
239  std::string name = curr->getID();
240  bool ok = ec.splitAt(dc, curr, rn, curr->getID() + ADDED_ON_RAMP_EDGE, curr->getID(), curr->getNumLanes() + toAdd, curr->getNumLanes());
241  if (!ok) {
242  WRITE_ERROR("Ups - could not build on-ramp for edge '" + curr->getID() + "'!");
243  return;
244  }
245  //ec.retrieve(name)->invalidateConnections();
246  curr = ec.retrieve(name + ADDED_ON_RAMP_EDGE);
247  incremented.insert(curr);
248  last = curr;
249  moveRampRight(curr, toAdd);
250  if (wasFirst) {
251  first = curr;
252  }
253  // mark acceleration lanes
254  for (int i = 0; i < curr->getNumLanes() - potHighway->getNumLanes(); ++i) {
255  curr->setAcceleration(i, true);
256  }
257  }
258  if (curr == cont && dontSplit && addLanes) {
259  WRITE_WARNING("Could not build on-ramp for edge '" + curr->getID() + "' due to option '--ramps.no-split'");
260  return;
261  }
262  } else {
263  // mark acceleration lanes
264  for (int i = 0; i < firstLaneNumber - potHighway->getNumLanes(); ++i) {
265  cont->setAcceleration(i, true);
266  }
267  }
268  // set connections from ramp/highway to added ramp
269  if (addLanes) {
271  if (!potHighway->addLane2LaneConnections(0, first, potRamp->getNumLanes(), MIN2(first->getNumLanes() - potRamp->getNumLanes(), potHighway->getNumLanes()), NBEdge::Lane2LaneInfoType::VALIDATED, true)) {
272  throw ProcessError("Could not set connection!");
273  }
274  }
276  if (!potRamp->addLane2LaneConnections(0, first, 0, potRamp->getNumLanes(), NBEdge::Lane2LaneInfoType::VALIDATED, true)) {
277  throw ProcessError("Could not set connection!");
278  }
279  }
280  patchRampGeometry(potRamp, first, potHighway, false);
281  }
282 }
283 
284 
285 void
286 NBRampsComputer::buildOffRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes,
287  const std::set<NBNode*, ComparatorIdLess>& potOnRamps) {
288  NBEdge* potHighway, *potRamp, *prev;
289  getOffRampEdges(cur, &potHighway, &potRamp, &prev);
290 #ifdef DEBUG_RAMPS
291  if (DEBUGCOND(cur)) {
292  std::cout << "buildOffRamp cur=" << cur->getID() << " hw=" << potHighway->getID() << " ramp=" << potRamp->getID() << " prev=" << prev->getID() << "\n";
293  }
294 #endif
295  // compute the number of lanes to append
296  const int firstLaneNumber = prev->getNumLanes();
297  int toAdd = (potRamp->getNumLanes() + potHighway->getNumLanes()) - firstLaneNumber;
298  NBEdge* first = prev;
299  NBEdge* last = prev;
300  NBEdge* curr = prev;
301  std::set<NBEdge*> incremented;
302  if (addLanes && toAdd > 0 && std::find(incremented.begin(), incremented.end(), prev) == incremented.end()) {
303  double currLength = 0;
304  while (curr != nullptr && currLength + curr->getGeometry().length() - POSITION_EPS < rampLength) {
305  if (find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
306  curr->incLaneNo(toAdd);
308  curr->invalidateConnections(true);
309  }
310  incremented.insert(curr);
311  moveRampRight(curr, toAdd);
312  currLength += curr->getGeometry().length(); // !!! loaded length?
313  last = curr;
314  }
315  NBNode* prevN = curr->getFromNode();
316  if (prevN->getIncomingEdges().size() == 1 && prevN->getOutgoingEdges().size() == 1) {
317  curr = prevN->getIncomingEdges()[0];
318  if (curr->getStep() < NBEdge::EdgeBuildingStep::LANES2LANES_USER && toAdd != 0) {
319  // curr might be an onRamp. In this case connections need to be rebuilt
320  curr->invalidateConnections();
321  }
322  if (curr->getNumLanes() != firstLaneNumber) {
323  // the number of lanes changes along the computation; we'll stop...
324  curr = nullptr;
325  } else if (last->isTurningDirectionAt(curr)) {
326  // turnarounds certainly should not be included in a ramp
327  curr = nullptr;
328  } else if (curr == potHighway || curr == potRamp) {
329  // circular connectivity. do not split!
330  curr = nullptr;
331  }
332  } else {
333  // ambiguous; and, in fact, what should it be? ...stop
334  curr = nullptr;
335  }
336  }
337  // check whether a further split is necessary
338  if (curr != nullptr && !dontSplit && currLength - POSITION_EPS < rampLength && curr->getNumLanes() == firstLaneNumber && std::find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
339  // there is enough place to build a ramp; do it
340  bool wasFirst = first == curr;
341  Position pos = curr->getGeometry().positionAtOffset(curr->getGeometry().length() - (rampLength - currLength));
342  NBNode* rn = new NBNode(curr->getID() + "-AddedOffRampNode", pos);
343  if (!nc.insert(rn)) {
344  throw ProcessError("Ups - could not build off-ramp for edge '" + curr->getID() + "' (node could not be build)!");
345  }
346  std::string name = curr->getID();
347  bool ok = ec.splitAt(dc, curr, rn, curr->getID(), curr->getID() + "-AddedOffRampEdge", curr->getNumLanes(), curr->getNumLanes() + toAdd);
348  if (!ok) {
349  WRITE_ERROR("Ups - could not build off-ramp for edge '" + curr->getID() + "'!");
350  return;
351  }
352  curr = ec.retrieve(name + "-AddedOffRampEdge");
353  incremented.insert(curr);
354  last = curr;
355  moveRampRight(curr, toAdd);
356  if (wasFirst) {
357  first = curr;
358  }
359  }
360  if (curr == prev && dontSplit && addLanes) {
361  WRITE_WARNING("Could not build off-ramp for edge '" + curr->getID() + "' due to option '--ramps.no-split'");
362  return;
363  }
364  }
365  NBEdge* toMark = first;
366  toMark->markOffRamp(true);
367  double markedLength = toMark->getLoadedLength();
368  while (markedLength < OFFRAMP_LOOKBACK) {
369  if (toMark != first && toMark->getToNode()->getOutgoingEdges().size() != 1) {
370  break;
371  }
372  NBNode* from = toMark->getFromNode();
373  if (from->getIncomingEdges().size() == 1) {
374  toMark = from->getIncomingEdges()[0];
375  } else if (potOnRamps.count(from) == 1) {
376  NBEdge* potOnRamp, *cont;
377  getOnRampEdges(from, &toMark, &potOnRamp, &cont);
378  } else {
379  break;
380  }
381  toMark->markOffRamp(true);
382  markedLength += toMark->getLoadedLength();
383  }
384  // set connections from added ramp to ramp/highway
385  if (addLanes) {
387  if (!first->addLane2LaneConnections(potRamp->getNumLanes(), potHighway, 0, MIN2(first->getNumLanes() - 1, potHighway->getNumLanes()), NBEdge::Lane2LaneInfoType::VALIDATED, true)) {
388  throw ProcessError("Could not set connection!");
389  }
390  if (!first->addLane2LaneConnections(0, potRamp, 0, potRamp->getNumLanes(), NBEdge::Lane2LaneInfoType::VALIDATED, false)) {
391  throw ProcessError("Could not set connection!");
392  }
393  }
394  patchRampGeometry(potRamp, first, potHighway, true);
395  }
396 }
397 
398 
399 void
400 NBRampsComputer::moveRampRight(NBEdge* ramp, int addedLanes) {
402  return;
403  }
404  try {
405  PositionVector g = ramp->getGeometry();
406  const double offset = (0.5 * addedLanes *
408  g.move2side(offset);
409  ramp->setGeometry(g);
410  } catch (InvalidArgument&) {
411  WRITE_WARNING("For edge '" + ramp->getID() + "': could not compute shape.");
412  }
413 }
414 
415 
416 bool
418  if (fabs((*potHighway)->getSpeed() - (*potRamp)->getSpeed()) < .1) {
419  return false;
420  }
421  if ((*potHighway)->getSpeed() < (*potRamp)->getSpeed()) {
422  std::swap(*potHighway, *potRamp);
423  }
424  return true;
425 }
426 
427 
428 bool
430  if ((*potHighway)->getNumLanes() == (*potRamp)->getNumLanes()) {
431  return false;
432  }
433  if ((*potHighway)->getNumLanes() < (*potRamp)->getNumLanes()) {
434  std::swap(*potHighway, *potRamp);
435  }
436  return true;
437 }
438 
439 
440 void
441 NBRampsComputer::getOnRampEdges(NBNode* n, NBEdge** potHighway, NBEdge** potRamp, NBEdge** other) {
442  *other = n->getOutgoingEdges()[0];
443  const std::vector<NBEdge*>& edges = n->getIncomingEdges();
444  assert(edges.size() == 2);
445  *potHighway = edges[0];
446  *potRamp = edges[1];
447  /*
448  // heuristic: highway is faster than ramp
449  if(determinedBySpeed(potHighway, potRamp)) {
450  return;
451  }
452  // heuristic: highway has more lanes than ramp
453  if(determinedByLaneNumber(potHighway, potRamp)) {
454  return;
455  }
456  */
457  // heuristic: ramp comes from right
458  if (NBContHelper::relative_incoming_edge_sorter(*other)(*potRamp, *potHighway)) {
459  std::swap(*potHighway, *potRamp);
460  }
461 }
462 
463 
464 void
465 NBRampsComputer::getOffRampEdges(NBNode* n, NBEdge** potHighway, NBEdge** potRamp, NBEdge** other) {
466  *other = n->getIncomingEdges()[0];
467  const std::vector<NBEdge*>& edges = n->getOutgoingEdges();
468  *potHighway = edges[0];
469  *potRamp = edges[1];
470  assert(edges.size() == 2);
471  /*
472  // heuristic: highway is faster than ramp
473  if(determinedBySpeed(potHighway, potRamp)) {
474  return;
475  }
476  // heuristic: highway has more lanes than ramp
477  if(determinedByLaneNumber(potHighway, potRamp)) {
478  return;
479  }
480  */
481  // heuristic: ramp goes to right
482  const std::vector<NBEdge*>& edges2 = n->getEdges();
483 #ifdef DEBUG_RAMPS
484  if (DEBUGCOND(n)) {
485  std::cout << " edges=" << toString(edges) << " edges2=" << toString(edges2) << "\n";
486  }
487 #endif
488  std::vector<NBEdge*>::const_iterator i = std::find(edges2.begin(), edges2.end(), *other);
489  NBContHelper::nextCW(edges2, i);
490  if ((*i) == *potRamp) {
491  std::swap(*potHighway, *potRamp);
492  }
493  // the following would be better but runs afoul of misleading angles when both edges
494  // have the same geometry start point but different references lanes are
495  // chosen for NBEdge::computeAngle()
496  //if (NBContHelper::relative_outgoing_edge_sorter(*other)(*potHighway, *potRamp)) {
497  // std::swap(*potHighway, *potRamp);
498  //}
499 }
500 
501 
502 bool
504  NBEdge* potHighway, NBEdge* potRamp, NBEdge* other, double minHighwaySpeed, double maxRampSpeed,
505  const std::set<std::string>& noramps) {
506  // check modes that are not appropriate for rampsdo not build ramps on rail edges
507  if (hasWrongMode(potHighway) || hasWrongMode(potRamp) || hasWrongMode(other)) {
508  return false;
509  }
510  // do not build ramps at traffic lights
511  if (NBNode::isTrafficLight(potRamp->getToNode()->getType())) {
512  return false;
513  }
514  // do not build ramps on connectors
515  if (potHighway->isMacroscopicConnector() || potRamp->isMacroscopicConnector() || other->isMacroscopicConnector()) {
516  return false;
517  }
518  // check whether a lane is missing
519  if (potHighway->getNumLanes() + potRamp->getNumLanes() < other->getNumLanes()) {
520  return false;
521  }
522  // is it really a highway?
523  double maxSpeed = MAX3(potHighway->getSpeed(), other->getSpeed(), potRamp->getSpeed());
524  if (maxSpeed < minHighwaySpeed) {
525  return false;
526  }
527  // is any of the connections a turnaround?
528  if (other->getToNode() == potHighway->getFromNode()) {
529  // off ramp
530  if (other->isTurningDirectionAt(potHighway) ||
531  other->isTurningDirectionAt(potRamp)) {
532  return false;
533  }
534  } else {
535  // on ramp
536  if (other->isTurningDirectionAt(potHighway) ||
537  other->isTurningDirectionAt(potRamp)) {
538  return false;
539  }
540  }
541  // are the angles between highway and other / ramp and other more or less straight?
542  const NBNode* node = ((potHighway->getToNode() == potRamp->getToNode() && potHighway->getToNode() == other->getFromNode())
543  ? potHighway->getToNode() : potHighway->getFromNode());
544  double angle = fabs(NBHelpers::relAngle(potHighway->getAngleAtNode(node), other->getAngleAtNode(node)));
545  if (angle >= 60) {
546  return false;
547  }
548  angle = fabs(NBHelpers::relAngle(potRamp->getAngleAtNode(node), other->getAngleAtNode(node)));
549  if (angle >= 60) {
550  return false;
551  }
552  /*
553  if (potHighway->getSpeed() < minHighwaySpeed || other->getSpeed() < minHighwaySpeed) {
554  return false;
555  }
556  */
557  // is it really a ramp?
558  if (maxRampSpeed > 0 && maxRampSpeed < potRamp->getSpeed()) {
559  return false;
560  }
561  if (noramps.find(other->getID()) != noramps.end()) {
562  return false;
563  }
564  return true;
565 }
566 
567 
568 bool
570  // must allow passenger vehicles
571  if ((edge->getPermissions() & SVC_PASSENGER) == 0) {
572  return true;
573  }
574  // must not have a green verge or a lane that is only for soft modes
575  for (int i = 0; i < (int)edge->getNumLanes(); ++i) {
576  if ((edge->getPermissions(i) & ~(SVC_PEDESTRIAN | SVC_BICYCLE)) == 0) {
577  return true;
578  }
579  }
580  return false;
581 }
582 
583 void
584 NBRampsComputer::patchRampGeometry(NBEdge* potRamp, NBEdge* first, NBEdge* potHighway, bool onRamp) {
585  // geometry of first and highway should allign on the left side
587  const NBNode* n = onRamp ? potHighway->getToNode() : potHighway->getFromNode();
588  if (potHighway->hasDefaultGeometryEndpointAtNode(n)) {
589  PositionVector p2 = first->getGeometry();
590  try {
591  p2.move2side((first->getNumLanes() - potHighway->getNumLanes()) * first->getLaneWidth(0) * 0.5);
592  first->setGeometry(p2);
593  } catch (InvalidArgument&) {}
594  }
595  }
596 
597  // ramp should merge smoothly with first
598  PositionVector p = potRamp->getGeometry();
599  double offset = 0;
600  int firstIndex = MAX2(0, MIN2(potRamp->getNumLanes(), first->getNumLanes()) - 1);
602  offset = -first->getLaneWidth(firstIndex) / 2;
603  } else {
604  if (firstIndex % 2 == 1) {
605  // even number of lanes
606  offset = -first->getLaneWidth(firstIndex / 2) / 2;
607  }
608  firstIndex /= 2; // integer division
609  }
610  // reset lane shape (might be affected by earlier junctions.join step. see #947)
611  first->resetLaneShapes();
612  PositionVector l = first->getLaneShape(firstIndex);
613  try {
614  l.move2side(offset);
615  } catch (InvalidArgument&) {}
616  //std::cout << " ramp=" << potRamp->getID() << " firstIndex=" << firstIndex << " offset=" << offset << " l=" << l << "\n";
617 
618  if (onRamp) {
619  p[0] = l[-1];
620  } else {
621  p.pop_back();
622  p.push_back(l[0]);
623  }
624  potRamp->setGeometry(p);
625 
626 }
627 
628 
629 /****************************************************************************/
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:288
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
#define DEBUGCOND(obj)
#define OFFRAMP_LOOKBACK
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_PEDESTRIAN
pedestrian
const double SUMO_const_laneWidth
Definition: StdDefs.h:48
T MIN2(T a, T b)
Definition: StdDefs.h:74
T MAX2(T a, T b)
Definition: StdDefs.h:80
T MAX3(T a, T b, T c)
Definition: StdDefs.h:94
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
static void nextCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
A container for districts.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
const std::set< EdgeSet > getRoundabouts() const
Returns the determined roundabouts.
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:275
bool splitAt(NBDistrictCont &dc, NBEdge *edge, NBNode *node)
Splits the edge at the position nearest to the given node.
Definition: NBEdgeCont.cpp:589
The representation of a single edge during network building.
Definition: NBEdge.h:91
double getLength() const
Returns the computed length of the edge.
Definition: NBEdge.h:588
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:4022
double getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn't set.
Definition: NBEdge.h:597
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:630
void incLaneNo(int by)
increment lane
Definition: NBEdge.cpp:3750
void markOffRamp(bool isOffRamp)
marks this edge has being an offRamp or leading to one (used for connection computation)
Definition: NBEdge.h:1345
LaneSpreadFunction getLaneSpreadFunction() const
Returns how this edge's lanes' lateral offset is computed.
Definition: NBEdge.cpp:942
bool hasDefaultGeometryEndpoints() const
Returns whether the geometry is terminated by the node positions This default may be violated by init...
Definition: NBEdge.cpp:610
EdgeBuildingStep getStep() const
The building step of this edge.
Definition: NBEdge.h:623
const std::string & getID() const
Definition: NBEdge.h:1465
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:541
@ LANES2LANES_USER
Lanes to lanes - relationships are loaded; no recheck is necessary/wished.
double getSpeed() const
Returns the speed allowed on this edge.
Definition: NBEdge.h:614
void resetLaneShapes()
reset lane shapes to what they would be before cutting with the junction shapes
Definition: NBEdge.cpp:2094
void setAcceleration(int lane, bool accelRamp)
marks one lane as acceleration lane
Definition: NBEdge.cpp:3969
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition: NBEdge.cpp:3356
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:515
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:752
void invalidateConnections(bool reallowSetting=false)
invalidate current connections of edge
Definition: NBEdge.cpp:1453
@ VALIDATED
The connection was computed and validated.
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
Definition: NBEdge.cpp:2053
bool hasDefaultGeometryEndpointAtNode(const NBNode *node) const
Returns whether the geometry is terminated by the node positions This default may be violated by init...
Definition: NBEdge.cpp:617
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:349
bool addLane2LaneConnections(int fromLane, NBEdge *dest, int toLane, int no, Lane2LaneInfoType type, bool invalidatePrevious=false, bool mayDefinitelyPass=false)
Builds no connections starting at the given lanes.
Definition: NBEdge.cpp:1095
bool isMacroscopicConnector() const
Returns whether this edge was marked as a macroscopic connector.
Definition: NBEdge.h:1101
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition: NBEdge.cpp:930
void setGeometry(const PositionVector &g, bool inner=false)
(Re)sets the edge's geometry
Definition: NBEdge.cpp:633
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:534
static double relAngle(double angle1, double angle2)
computes the relative angle between the two angles
Definition: NBHelpers.cpp:45
Instance responsible for building networks.
Definition: NBNetBuilder.h:107
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:168
NBParkingCont & getParkingCont()
Definition: NBNetBuilder.h:184
NBPTLineCont & getPTLineCont()
Returns a reference to the pt line container.
Definition: NBNetBuilder.h:179
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:148
NBPTStopCont & getPTStopCont()
Returns a reference to the pt stop container.
Definition: NBNetBuilder.h:174
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:153
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:58
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:90
Represents a single node (junction) during network building.
Definition: NBNode.h:66
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:273
static bool isTrafficLight(SumoXMLNodeType type)
return whether the given type is a traffic light
Definition: NBNode.cpp:3555
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges (The edges which start at this node)
Definition: NBNode.h:261
const EdgeVector & getEdges() const
Returns all edges which participate in this node (Edges that start or end at this node)
Definition: NBNode.h:266
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges (The edges which yield in this node)
Definition: NBNode.h:256
void addEdges2Keep(const OptionsCont &oc, std::set< std::string > &into)
add edges that must be kept
void addEdges2Keep(const OptionsCont &oc, std::set< std::string > &into)
add edges that must be kept
void addEdges2Keep(const OptionsCont &oc, std::set< std::string > &into)
add edges that must be kept
Definition: NBParking.cpp:78
static void computeRamps(NBNetBuilder &nb, OptionsCont &oc, bool mayAddOrRemove)
Computes highway on-/off-ramps (if wished)
static void getOffRampEdges(NBNode *n, NBEdge **potHighway, NBEdge **potRamp, NBEdge **other)
static bool mayNeedOffRamp(NBNode *cur, double minHighwaySpeed, double maxRampSpeed, const std::set< std::string > &noramps)
Determines whether the given node may be an off-ramp end.
static bool mayNeedOnRamp(NBNode *cur, double minHighwaySpeed, double maxRampSpeed, const std::set< std::string > &noramps, double minWeaveLength)
Determines whether the given node may be an on-ramp begin.
static bool determinedBySpeed(NBEdge **potHighway, NBEdge **potRamp)
static void moveRampRight(NBEdge *ramp, int addedLanes)
Moves the ramp to the right, as new lanes were added.
static void getOnRampEdges(NBNode *n, NBEdge **potHighway, NBEdge **potRamp, NBEdge **other)
static const std::string ADDED_ON_RAMP_EDGE
suffix for newly generated on-ramp edges
static void patchRampGeometry(NBEdge *potRamp, NBEdge *first, NBEdge *potHighway, bool onRamp)
shift ramp geometry to merge smoothly with the motorway
static void buildOffRamp(NBNode *cur, NBNodeCont &nc, NBEdgeCont &ec, NBDistrictCont &dc, double rampLength, bool dontSplit, bool addLanes, const std::set< NBNode *, ComparatorIdLess > &potOnRamps)
Builds an off-ramp ending at the given node.
static bool determinedByLaneNumber(NBEdge **potHighway, NBEdge **potRamp)
static bool hasWrongMode(NBEdge *edge)
whether the edge has a mode that does not indicate a ramp edge
static void buildOnRamp(NBNode *cur, NBNodeCont &nc, NBEdgeCont &ec, NBDistrictCont &dc, double rampLength, bool dontSplit, bool addLanes)
Builds an on-ramp starting at the given node.
static bool fulfillsRampConstraints(NBEdge *potHighway, NBEdge *potRamp, NBEdge *other, double minHighwaySpeed, double maxRampSpeed, const std::set< std::string > &noramps)
Checks whether an on-/off-ramp can be bult here.
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.
double length() const
Returns the length.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
void move2side(double amount, double maxExtension=100)
move position vector to side using certain ammount