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>
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// ===========================================================================
43const std::string NBRampsComputer::ADDED_ON_RAMP_EDGE("-AddedOnRampEdge");
44
45// ===========================================================================
46// method definitions
47// ===========================================================================
48// ---------------------------------------------------------------------------
49// NBRampsComputer
50// ---------------------------------------------------------------------------
51void
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 for (const EdgeSet& round : ec.getRoundabouts()) {
71 for (NBEdge* const edge : round) {
72 noramps.insert(edge->getID());
73 }
74 }
75 // exclude public transport edges
76 nb.getPTStopCont().addEdges2Keep(oc, noramps);
77 nb.getParkingCont().addEdges2Keep(oc, noramps);
78
79 // check whether on-off ramps shall be guessed
80 if (guessAndAdd || oc.getBool("ramps.guess-acceleration-lanes")) {
81 for (const auto& it : ec) {
82 it.second->markOffRamp(false);
83 }
84
85 // if an edge is part of two ramps, ordering is important
86 std::set<NBNode*, ComparatorIdLess> potOnRamps;
87 std::set<NBNode*, ComparatorIdLess> potOffRamps;
88 for (const auto& i : nc) {
89 NBNode* cur = i.second;
90 if (mayNeedOnRamp(cur, minHighwaySpeed, maxRampSpeed, noramps, minWeaveLength)) {
91 potOnRamps.insert(cur);
92 }
93 if (mayNeedOffRamp(cur, minHighwaySpeed, maxRampSpeed, noramps)) {
94 potOffRamps.insert(cur);
95 }
96 }
97 for (std::set<NBNode*, ComparatorIdLess>::const_iterator i = potOnRamps.begin(); i != potOnRamps.end(); ++i) {
98 buildOnRamp(*i, nc, ec, dc, rampLength, dontSplit || !guessAndAdd, guessAndAdd);
99 }
100 for (std::set<NBNode*, ComparatorIdLess>::const_iterator i = potOffRamps.begin(); i != potOffRamps.end(); ++i) {
101 buildOffRamp(*i, nc, ec, dc, rampLength, dontSplit || !guessAndAdd, guessAndAdd, potOnRamps);
102 }
103 }
104 // check whether on-off ramps are specified
105 if (oc.isSet("ramps.set") && mayAddOrRemove) {
106 std::vector<std::string> edges = oc.getStringVector("ramps.set");
107 std::set<NBNode*, ComparatorIdLess> potOnRamps;
108 for (const std::string& i : edges) {
109 NBEdge* e = ec.retrieve(i);
110 if (noramps.count(i) != 0) {
111 WRITE_WARNINGF(TL("Can not build ramp on edge '%' - the edge is unsuitable."), i);
112 continue;
113 }
114 if (e == nullptr) {
115 WRITE_WARNINGF(TL("Can not build on ramp on edge '%' - the edge is not known."), i);
116 continue;
117 }
118 NBNode* from = e->getFromNode();
119 if (from->getIncomingEdges().size() == 2 && from->getOutgoingEdges().size() == 1) {
120 buildOnRamp(from, nc, ec, dc, rampLength, dontSplit, true);
121 potOnRamps.insert(from);
122 }
123 // load edge again to check offramps
124 e = ec.retrieve(i);
125 if (e == nullptr) {
126 WRITE_WARNINGF(TL("Can not build off ramp on edge '%' - the edge is not known."), i);
127 continue;
128 }
129 NBNode* to = e->getToNode();
130 if (to->getIncomingEdges().size() == 1 && to->getOutgoingEdges().size() == 2) {
131 buildOffRamp(to, nc, ec, dc, rampLength, dontSplit, true, potOnRamps);
132 }
133 }
134 }
135}
136
137
138bool
139NBRampsComputer::mayNeedOnRamp(NBNode* cur, double minHighwaySpeed, double maxRampSpeed, const std::set<std::string>& noramps, double minWeaveLength) {
140 if (cur->getOutgoingEdges().size() != 1 || cur->getIncomingEdges().size() != 2) {
141 return false;
142 }
143 NBEdge* potHighway, *potRamp, *cont;
144 getOnRampEdges(cur, &potHighway, &potRamp, &cont);
145 // may be an on-ramp
146 if (fulfillsRampConstraints(potHighway, potRamp, cont, minHighwaySpeed, maxRampSpeed, noramps)) {
147 // prevent short weaving section
148 double seen = cont->getLength();
149 while (seen < minWeaveLength) {
150 if (cont->getToNode()->getOutgoingEdges().size() > 1) {
151 return false;
152 } else if (cont->getToNode()->getOutgoingEdges().size() == 0) {
153 return true;
154 }
155 cont = cont->getToNode()->getOutgoingEdges().front();
156 seen += cont->getLength();
157 }
158 return true;
159 } else {
160 return false;
161 }
162}
163
164
165bool
166NBRampsComputer::mayNeedOffRamp(NBNode* cur, double minHighwaySpeed, double maxRampSpeed, const std::set<std::string>& noramps) {
167 if (cur->getIncomingEdges().size() != 1 || cur->getOutgoingEdges().size() != 2) {
168 return false;
169 }
170 // may be an off-ramp
171 NBEdge* potHighway, *potRamp, *prev;
172 getOffRampEdges(cur, &potHighway, &potRamp, &prev);
173#ifdef DEBUG_RAMPS
174 if (DEBUGCOND(cur)) {
175 std::cout << "off ramp hw=" << potHighway->getID() << " ramp=" << potRamp->getID() << " prev=" << prev->getID() << std::endl;
176 }
177#endif
178 return fulfillsRampConstraints(potHighway, potRamp, prev, minHighwaySpeed, maxRampSpeed, noramps);
179}
180
181
182void
183NBRampsComputer::buildOnRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes) {
184 NBEdge* potHighway, *potRamp, *cont;
185 getOnRampEdges(cur, &potHighway, &potRamp, &cont);
186#ifdef DEBUG_RAMPS
187 if (DEBUGCOND(cur)) {
188 std::cout << "buildOnRamp cur=" << cur->getID() << " hw=" << potHighway->getID() << " ramp=" << potRamp->getID() << " cont=" << cont->getID() << "\n";
189 }
190#endif
191 // compute the number of lanes to append
192 const int firstLaneNumber = cont->getNumLanes();
193 int toAdd = (potRamp->getNumLanes() + potHighway->getNumLanes()) - firstLaneNumber;
194 NBEdge* first = cont;
195 NBEdge* last = cont;
196 NBEdge* curr = cont;
197 std::set<NBEdge*> incremented;
198 if (addLanes && toAdd > 0 && std::find(incremented.begin(), incremented.end(), cont) == incremented.end()) {
199 double currLength = 0;
200 while (curr != nullptr && currLength + curr->getGeometry().length() - POSITION_EPS < rampLength) {
201 if (find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
202 curr->incLaneNo(toAdd);
204 curr->invalidateConnections(true);
205 }
206 incremented.insert(curr);
207 moveRampRight(curr, toAdd);
208 currLength += curr->getGeometry().length(); // !!! loaded length?
209 last = curr;
210 // mark acceleration lanes
211 for (int i = 0; i < curr->getNumLanes() - potHighway->getNumLanes(); ++i) {
212 curr->setAcceleration(i, true);
213 }
214 }
215 NBNode* nextN = curr->getToNode();
216 if (nextN->getOutgoingEdges().size() == 1 && nextN->getIncomingEdges().size() == 1) {
217 curr = nextN->getOutgoingEdges()[0];
218 if (curr->getNumLanes() != firstLaneNumber) {
219 // the number of lanes changes along the computation; we'll stop...
220 curr = nullptr;
221 } else if (curr->isTurningDirectionAt(last)) {
222 // turnarounds certainly should not be included in a ramp
223 curr = nullptr;
224 } else if (curr == potHighway || curr == potRamp) {
225 // circular connectivity. do not split!
226 curr = nullptr;
227 }
228 } else {
229 // ambiguous; and, in fact, what should it be? ...stop
230 curr = nullptr;
231 }
232 }
233 // check whether a further split is necessary
234 if (curr != nullptr && !dontSplit && currLength - POSITION_EPS < rampLength && curr->getNumLanes() == firstLaneNumber && std::find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
235 // there is enough place to build a ramp; do it
236 bool wasFirst = first == curr;
237 NBNode* rn = new NBNode(curr->getID() + "-AddedOnRampNode", curr->getGeometry().positionAtOffset(rampLength - currLength));
238 if (!nc.insert(rn)) {
239 throw ProcessError("Ups - could not build on-ramp for edge '" + curr->getID() + "' (node could not be build)!");
240 }
241 std::string name = curr->getID();
242 bool ok = ec.splitAt(dc, curr, rn, curr->getID() + ADDED_ON_RAMP_EDGE, curr->getID(), curr->getNumLanes() + toAdd, curr->getNumLanes());
243 if (!ok) {
244 WRITE_ERROR("Ups - could not build on-ramp for edge '" + curr->getID() + "'!");
245 return;
246 }
247 //ec.retrieve(name)->invalidateConnections();
248 curr = ec.retrieve(name + ADDED_ON_RAMP_EDGE);
249 incremented.insert(curr);
250 last = curr;
251 moveRampRight(curr, toAdd);
252 if (wasFirst) {
253 first = curr;
254 }
255 // mark acceleration lanes
256 for (int i = 0; i < curr->getNumLanes() - potHighway->getNumLanes(); ++i) {
257 curr->setAcceleration(i, true);
258 }
259 }
260 if (curr == cont && dontSplit && addLanes) {
261 WRITE_WARNING("Could not build on-ramp for edge '" + curr->getID() + "' due to option '--ramps.no-split'");
262 return;
263 }
264 } else {
265 // mark acceleration lanes
266 for (int i = 0; i < firstLaneNumber - potHighway->getNumLanes(); ++i) {
267 cont->setAcceleration(i, true);
268 }
269 }
270 // set connections from ramp/highway to added ramp
271 if (addLanes) {
273 if (!potHighway->addLane2LaneConnections(0, first, potRamp->getNumLanes(), MIN2(first->getNumLanes() - potRamp->getNumLanes(), potHighway->getNumLanes()), NBEdge::Lane2LaneInfoType::VALIDATED, true)) {
274 throw ProcessError("Could not set connection!");
275 }
276 }
278 if (!potRamp->addLane2LaneConnections(0, first, 0, potRamp->getNumLanes(), NBEdge::Lane2LaneInfoType::VALIDATED, true)) {
279 throw ProcessError("Could not set connection!");
280 }
281 }
282 patchRampGeometry(potRamp, first, potHighway, false);
283 }
284}
285
286
287void
288NBRampsComputer::buildOffRamp(NBNode* cur, NBNodeCont& nc, NBEdgeCont& ec, NBDistrictCont& dc, double rampLength, bool dontSplit, bool addLanes,
289 const std::set<NBNode*, ComparatorIdLess>& potOnRamps) {
290 NBEdge* potHighway, *potRamp, *prev;
291 getOffRampEdges(cur, &potHighway, &potRamp, &prev);
292#ifdef DEBUG_RAMPS
293 if (DEBUGCOND(cur)) {
294 std::cout << "buildOffRamp cur=" << cur->getID() << " hw=" << potHighway->getID() << " ramp=" << potRamp->getID() << " prev=" << prev->getID() << "\n";
295 }
296#endif
297 // compute the number of lanes to append
298 const int firstLaneNumber = prev->getNumLanes();
299 int toAdd = (potRamp->getNumLanes() + potHighway->getNumLanes()) - firstLaneNumber;
300 NBEdge* first = prev;
301 NBEdge* last = prev;
302 NBEdge* curr = prev;
303 std::set<NBEdge*> incremented;
304 if (addLanes && toAdd > 0 && std::find(incremented.begin(), incremented.end(), prev) == incremented.end()) {
305 double currLength = 0;
306 while (curr != nullptr && currLength + curr->getGeometry().length() - POSITION_EPS < rampLength) {
307 if (find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
308 curr->incLaneNo(toAdd);
310 curr->invalidateConnections(true);
311 }
312 incremented.insert(curr);
313 moveRampRight(curr, toAdd);
314 currLength += curr->getGeometry().length(); // !!! loaded length?
315 last = curr;
316 }
317 NBNode* prevN = curr->getFromNode();
318 if (prevN->getIncomingEdges().size() == 1 && prevN->getOutgoingEdges().size() == 1) {
319 curr = prevN->getIncomingEdges()[0];
320 if (curr->getStep() < NBEdge::EdgeBuildingStep::LANES2LANES_USER && toAdd != 0) {
321 // curr might be an onRamp. In this case connections need to be rebuilt
322 curr->invalidateConnections();
323 }
324 if (curr->getNumLanes() != firstLaneNumber) {
325 // the number of lanes changes along the computation; we'll stop...
326 curr = nullptr;
327 } else if (last->isTurningDirectionAt(curr)) {
328 // turnarounds certainly should not be included in a ramp
329 curr = nullptr;
330 } else if (curr == potHighway || curr == potRamp) {
331 // circular connectivity. do not split!
332 curr = nullptr;
333 }
334 } else {
335 // ambiguous; and, in fact, what should it be? ...stop
336 curr = nullptr;
337 }
338 }
339 // check whether a further split is necessary
340 if (curr != nullptr && !dontSplit && currLength - POSITION_EPS < rampLength && curr->getNumLanes() == firstLaneNumber && std::find(incremented.begin(), incremented.end(), curr) == incremented.end()) {
341 // there is enough place to build a ramp; do it
342 bool wasFirst = first == curr;
343 Position pos = curr->getGeometry().positionAtOffset(curr->getGeometry().length() - (rampLength - currLength));
344 NBNode* rn = new NBNode(curr->getID() + "-AddedOffRampNode", pos);
345 if (!nc.insert(rn)) {
346 throw ProcessError("Ups - could not build off-ramp for edge '" + curr->getID() + "' (node could not be build)!");
347 }
348 std::string name = curr->getID();
349 bool ok = ec.splitAt(dc, curr, rn, curr->getID(), curr->getID() + "-AddedOffRampEdge", curr->getNumLanes(), curr->getNumLanes() + toAdd);
350 if (!ok) {
351 WRITE_ERROR("Ups - could not build off-ramp for edge '" + curr->getID() + "'!");
352 return;
353 }
354 curr = ec.retrieve(name + "-AddedOffRampEdge");
355 incremented.insert(curr);
356 last = curr;
357 moveRampRight(curr, toAdd);
358 if (wasFirst) {
359 first = curr;
360 }
361 }
362 if (curr == prev && dontSplit && addLanes) {
363 WRITE_WARNING("Could not build off-ramp for edge '" + curr->getID() + "' due to option '--ramps.no-split'");
364 return;
365 }
366 }
367 NBEdge* toMark = first;
368 toMark->markOffRamp(true);
369 double markedLength = toMark->getLoadedLength();
370 while (markedLength < OFFRAMP_LOOKBACK) {
371 if (toMark != first && toMark->getToNode()->getOutgoingEdges().size() != 1) {
372 break;
373 }
374 NBNode* from = toMark->getFromNode();
375 if (from->getIncomingEdges().size() == 1) {
376 toMark = from->getIncomingEdges()[0];
377 } else if (potOnRamps.count(from) == 1) {
378 NBEdge* potOnRamp, *cont;
379 getOnRampEdges(from, &toMark, &potOnRamp, &cont);
380 } else {
381 break;
382 }
383 toMark->markOffRamp(true);
384 markedLength += toMark->getLoadedLength();
385 }
386 // set connections from added ramp to ramp/highway
387 if (addLanes) {
389 if (!first->addLane2LaneConnections(potRamp->getNumLanes(), potHighway, 0, MIN2(first->getNumLanes() - 1, potHighway->getNumLanes()), NBEdge::Lane2LaneInfoType::VALIDATED, true)) {
390 throw ProcessError("Could not set connection!");
391 }
392 if (!first->addLane2LaneConnections(0, potRamp, 0, potRamp->getNumLanes(), NBEdge::Lane2LaneInfoType::VALIDATED, false)) {
393 throw ProcessError("Could not set connection!");
394 }
395 }
396 patchRampGeometry(potRamp, first, potHighway, true);
397 }
398}
399
400
401void
404 return;
405 }
406 try {
407 PositionVector g = ramp->getGeometry();
408 const double offset = (0.5 * addedLanes *
410 g.move2side(offset);
411 ramp->setGeometry(g);
412 } catch (InvalidArgument&) {
413 WRITE_WARNING("For edge '" + ramp->getID() + "': could not compute shape.");
414 }
415}
416
417
418bool
420 if (fabs((*potHighway)->getSpeed() - (*potRamp)->getSpeed()) < .1) {
421 return false;
422 }
423 if ((*potHighway)->getSpeed() < (*potRamp)->getSpeed()) {
424 std::swap(*potHighway, *potRamp);
425 }
426 return true;
427}
428
429
430bool
432 if ((*potHighway)->getNumLanes() == (*potRamp)->getNumLanes()) {
433 return false;
434 }
435 if ((*potHighway)->getNumLanes() < (*potRamp)->getNumLanes()) {
436 std::swap(*potHighway, *potRamp);
437 }
438 return true;
439}
440
441
442void
443NBRampsComputer::getOnRampEdges(NBNode* n, NBEdge** potHighway, NBEdge** potRamp, NBEdge** other) {
444 *other = n->getOutgoingEdges()[0];
445 const std::vector<NBEdge*>& edges = n->getIncomingEdges();
446 assert(edges.size() == 2);
447 *potHighway = edges[0];
448 *potRamp = edges[1];
449 /*
450 // heuristic: highway is faster than ramp
451 if(determinedBySpeed(potHighway, potRamp)) {
452 return;
453 }
454 // heuristic: highway has more lanes than ramp
455 if(determinedByLaneNumber(potHighway, potRamp)) {
456 return;
457 }
458 */
459 // heuristic: ramp comes from right
460 if (NBContHelper::relative_incoming_edge_sorter(*other)(*potRamp, *potHighway)) {
461 std::swap(*potHighway, *potRamp);
462 }
463}
464
465
466void
467NBRampsComputer::getOffRampEdges(NBNode* n, NBEdge** potHighway, NBEdge** potRamp, NBEdge** other) {
468 *other = n->getIncomingEdges()[0];
469 const std::vector<NBEdge*>& edges = n->getOutgoingEdges();
470 *potHighway = edges[0];
471 *potRamp = edges[1];
472 assert(edges.size() == 2);
473 /*
474 // heuristic: highway is faster than ramp
475 if(determinedBySpeed(potHighway, potRamp)) {
476 return;
477 }
478 // heuristic: highway has more lanes than ramp
479 if(determinedByLaneNumber(potHighway, potRamp)) {
480 return;
481 }
482 */
483 // heuristic: ramp goes to right
484 const std::vector<NBEdge*>& edges2 = n->getEdges();
485#ifdef DEBUG_RAMPS
486 if (DEBUGCOND(n)) {
487 std::cout << " edges=" << toString(edges) << " edges2=" << toString(edges2) << "\n";
488 }
489#endif
490 std::vector<NBEdge*>::const_iterator i = std::find(edges2.begin(), edges2.end(), *other);
491 NBContHelper::nextCW(edges2, i);
492 if ((*i) == *potRamp) {
493 std::swap(*potHighway, *potRamp);
494 }
495 // the following would be better but runs afoul of misleading angles when both edges
496 // have the same geometry start point but different references lanes are
497 // chosen for NBEdge::computeAngle()
498 //if (NBContHelper::relative_outgoing_edge_sorter(*other)(*potHighway, *potRamp)) {
499 // std::swap(*potHighway, *potRamp);
500 //}
501}
502
503
504bool
506 NBEdge* potHighway, NBEdge* potRamp, NBEdge* other, double minHighwaySpeed, double maxRampSpeed,
507 const std::set<std::string>& noramps) {
508 // check modes that are not appropriate for rampsdo not build ramps on rail edges
509 if (hasWrongMode(potHighway) || hasWrongMode(potRamp) || hasWrongMode(other)) {
510 return false;
511 }
512 // do not build ramps at traffic lights
513 if (NBNode::isTrafficLight(potRamp->getToNode()->getType())) {
514 return false;
515 }
516 // do not build ramps on connectors
517 if (potHighway->isMacroscopicConnector() || potRamp->isMacroscopicConnector() || other->isMacroscopicConnector()) {
518 return false;
519 }
520 // check whether a lane is missing
521 if (potHighway->getNumLanes() + potRamp->getNumLanes() < other->getNumLanes()) {
522 return false;
523 }
524 // is it really a highway?
525 double maxSpeed = MAX3(potHighway->getSpeed(), other->getSpeed(), potRamp->getSpeed());
526 if (maxSpeed < minHighwaySpeed) {
527 return false;
528 }
529 // is any of the connections a turnaround?
530 if (other->getToNode() == potHighway->getFromNode()) {
531 // off ramp
532 if (other->isTurningDirectionAt(potHighway) ||
533 other->isTurningDirectionAt(potRamp)) {
534 return false;
535 }
536 } else {
537 // on ramp
538 if (other->isTurningDirectionAt(potHighway) ||
539 other->isTurningDirectionAt(potRamp)) {
540 return false;
541 }
542 }
543 // are the angles between highway and other / ramp and other more or less straight?
544 const NBNode* node = ((potHighway->getToNode() == potRamp->getToNode() && potHighway->getToNode() == other->getFromNode())
545 ? potHighway->getToNode() : potHighway->getFromNode());
546 double angle = fabs(NBHelpers::relAngle(potHighway->getAngleAtNode(node), other->getAngleAtNode(node)));
547 if (angle >= 60) {
548 return false;
549 }
550 angle = fabs(NBHelpers::relAngle(potRamp->getAngleAtNode(node), other->getAngleAtNode(node)));
551 if (angle >= 60) {
552 return false;
553 }
554 /*
555 if (potHighway->getSpeed() < minHighwaySpeed || other->getSpeed() < minHighwaySpeed) {
556 return false;
557 }
558 */
559 // is it really a ramp?
560 if (maxRampSpeed > 0 && maxRampSpeed < potRamp->getSpeed()) {
561 return false;
562 }
563 if (noramps.find(other->getID()) != noramps.end()) {
564 return false;
565 }
566 return true;
567}
568
569
570bool
572 // must allow passenger vehicles
573 if ((edge->getPermissions() & SVC_PASSENGER) == 0) {
574 return true;
575 }
576 // must not have a green verge or a lane that is only for soft modes
577 for (int i = 0; i < (int)edge->getNumLanes(); ++i) {
578 if ((edge->getPermissions(i) & ~(SVC_PEDESTRIAN | SVC_BICYCLE)) == 0) {
579 return true;
580 }
581 }
582 return false;
583}
584
585void
586NBRampsComputer::patchRampGeometry(NBEdge* potRamp, NBEdge* first, NBEdge* potHighway, bool onRamp) {
587 // geometry of first and highway should allign on the left side
589 const NBNode* n = onRamp ? potHighway->getToNode() : potHighway->getFromNode();
590 if (potHighway->hasDefaultGeometryEndpointAtNode(n)) {
591 PositionVector p2 = first->getGeometry();
592 try {
593 p2.move2side((first->getNumLanes() - potHighway->getNumLanes()) * first->getLaneWidth(0) * 0.5);
594 first->setGeometry(p2);
595 } catch (InvalidArgument&) {}
596 }
597 }
598
599 // ramp should merge smoothly with first
600 PositionVector p = potRamp->getGeometry();
601 double offset = 0;
602 int firstIndex = MAX2(0, MIN2(potRamp->getNumLanes(), first->getNumLanes()) - 1);
604 offset = -first->getLaneWidth(firstIndex) / 2;
605 } else {
606 if (firstIndex % 2 == 1) {
607 // even number of lanes
608 offset = -first->getLaneWidth(firstIndex / 2) / 2;
609 }
610 firstIndex /= 2; // integer division
611 }
612 // reset lane shape (might be affected by earlier junctions.join step. see #947)
613 first->resetLaneShapes();
614 PositionVector l = first->getLaneShape(firstIndex);
615 try {
616 l.move2side(offset);
617 } catch (InvalidArgument&) {}
618 //std::cout << " ramp=" << potRamp->getID() << " firstIndex=" << firstIndex << " offset=" << offset << " l=" << l << "\n";
619
620 if (onRamp) {
621 p[0] = l[-1];
622 } else {
623 p.pop_back();
624 p.push_back(l[0]);
625 }
626 potRamp->setGeometry(p);
627
628}
629
630
631/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:266
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:274
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:265
#define TL(string)
Definition: MsgHandler.h:282
#define DEBUGCOND(obj)
#define OFFRAMP_LOOKBACK
std::set< NBEdge * > EdgeSet
container for unique edges
Definition: NBCont.h:50
@ 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:71
T MAX2(T a, T b)
Definition: StdDefs.h:77
T MAX3(T a, T b, T c)
Definition: StdDefs.h:91
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:274
bool splitAt(NBDistrictCont &dc, NBEdge *edge, NBNode *node)
Splits the edge at the position nearest to the given node.
Definition: NBEdgeCont.cpp:588
The representation of a single edge during network building.
Definition: NBEdge.h:92
double getLength() const
Returns the computed length of the edge.
Definition: NBEdge.h:599
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:4137
double getLoadedLength() const
Returns the length was set explicitly or the computed length if it wasn't set.
Definition: NBEdge.h:608
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:648
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:552
void incLaneNo(int by)
increment lane
Definition: NBEdge.cpp:3834
void markOffRamp(bool isOffRamp)
marks this edge has being an offRamp or leading to one (used for connection computation)
Definition: NBEdge.h:1398
const PositionVector & getGeometry() const
Returns the geometry of the edge.
Definition: NBEdge.h:787
LaneSpreadFunction getLaneSpreadFunction() const
Returns how this edge's lanes' lateral offset is computed.
Definition: NBEdge.cpp:974
bool hasDefaultGeometryEndpoints() const
Returns whether the geometry is terminated by the node positions This default may be violated by init...
Definition: NBEdge.cpp:627
EdgeBuildingStep getStep() const
The building step of this edge.
Definition: NBEdge.h:641
@ 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:625
const std::string & getID() const
Definition: NBEdge.h:1526
void resetLaneShapes()
reset lane shapes to what they would be before cutting with the junction shapes
Definition: NBEdge.cpp:2147
void setAcceleration(int lane, bool accelRamp)
marks one lane as acceleration lane
Definition: NBEdge.cpp:4084
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition: NBEdge.cpp:3430
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:526
void invalidateConnections(bool reallowSetting=false)
invalidate current connections of edge
Definition: NBEdge.cpp:1483
@ VALIDATED
The connection was computed and validated.
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:545
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
Definition: NBEdge.cpp:2083
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:634
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:357
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:1128
bool isMacroscopicConnector() const
Returns whether this edge was marked as a macroscopic connector.
Definition: NBEdge.h:1138
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition: NBEdge.cpp:962
void setGeometry(const PositionVector &g, bool inner=false)
(Re)sets the edge's geometry
Definition: NBEdge.cpp:650
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
NBParkingCont & getParkingCont()
Definition: NBNetBuilder.h:173
NBPTStopCont & getPTStopCont()
Returns a reference to the pt stop container.
Definition: NBNetBuilder.h:164
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:144
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:139
NBDistrictCont & getDistrictCont()
Returns a reference the districts container.
Definition: NBNetBuilder.h:159
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:91
Represents a single node (junction) during network building.
Definition: NBNode.h:66
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:275
static bool isTrafficLight(SumoXMLNodeType type)
return whether the given type is a traffic light
Definition: NBNode.cpp:3689
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges (The edges which yield in this node)
Definition: NBNode.h:258
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges (The edges which start at this node)
Definition: NBNode.h:263
const EdgeVector & getEdges() const
Returns all edges which participate in this node (Edges that start or end at this node)
Definition: NBNode.h:268
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
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.hpp:21884