Eclipse SUMO - Simulation of Urban MObility
NBPTLineCont.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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/****************************************************************************/
19// Container for NBPTLine during netbuild
20/****************************************************************************/
21#include <config.h>
22
23#include <iostream>
28#include "NBPTLineCont.h"
29#include "NBPTStop.h"
30#include "NBEdge.h"
31#include "NBNode.h"
32#include "NBVehicle.h"
33#include "NBPTStopCont.h"
34
35//#define DEBUG_FIND_WAY
36//#define DEBUG_CONSTRUCT_ROUTE
37
38#define DEBUGLINEID ""
39#define DEBUGSTOPID ""
40
41// ===========================================================================
42// static value definitions
43// ===========================================================================
44const int NBPTLineCont::FWD(1);
45const int NBPTLineCont::BWD(-1);
46
47
48// ===========================================================================
49// method definitions
50// ===========================================================================
52 for (auto& myPTLine : myPTLines) {
53 delete myPTLine.second;
54 }
55 myPTLines.clear();
56}
57
58
59bool
61 if (myPTLines.count(ptLine->getLineID()) == 0) {
62 myPTLines[ptLine->getLineID()] = ptLine;
63 return true;
64 }
65 return false;
66}
67
68
69void
71 for (auto& item : myPTLines) {
72 NBPTLine* line = item.second;
73 if (item.second->getWays().size() > 0) {
74 // loaded from OSM rather than ptline input. We can use extra
75 // information to reconstruct route and stops
76 constructRoute(line, ec);
77 if (!routeOnly) {
78 // map stops to ways, using the constructed route for loose stops
79 reviseStops(line, ec, sc);
80 }
81 }
82 // fix circular line if necessary
83 if (line->getStops().size() > 1
84 && line->getStops().front() == line->getStops().back()
85 && line->getRoute().size() > 1
86 && line->getRoute().front() != line->getRoute().back()) {
87 // we need to duplicate either the first or the last edge depending on the stop locations
88 const std::string firstStopEdge = line->getStops().front()->getEdgeId();
89 const std::string lastStopEdge = line->getStops().back()->getEdgeId();
90 std::vector<NBEdge*> edges = line->getRoute();
91 if (firstStopEdge == edges.back()->getID()) {
92 edges.insert(edges.begin(), edges.back());
93 } else if (lastStopEdge == edges.front()->getID()) {
94 edges.push_back(edges.front());
95 }
96 line->setEdges(edges);
97 }
98 line->deleteInvalidStops(ec, sc);
99 //line->deleteDuplicateStops();
100 for (std::shared_ptr<NBPTStop> stop : line->getStops()) {
101 myServedPTStops.insert(stop->getID());
102 }
103 }
104}
105
106
107void
109 const std::vector<std::string>& waysIds = line->getWays();
110 if (waysIds.size() == 1 && line->getStops().size() > 1) {
111 reviseSingleWayStops(line, ec, sc);
112 return;
113 }
114 if (waysIds.size() <= 1) {
115 WRITE_WARNINGF(TL("Cannot revise pt stop localization for pt line '%', which consist of one way only. Ignoring!"), line->getLineID());
116 return;
117 }
118 if (line->getRoute().size() == 0) {
119 WRITE_WARNINGF(TL("Cannot revise pt stop localization for pt line '%', which has no route edges. Ignoring!"), line->getLineID());
120 return;
121 }
122 std::vector<std::shared_ptr<NBPTStop> > stops = line->getStops();
123 for (std::shared_ptr<NBPTStop> stop : stops) {
124 //get the corresponding and one of the two adjacent ways
125 stop = findWay(line, stop, ec, sc);
126 if (stop == nullptr) {
127 // warning already given
128 continue;
129 }
130 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
131 if (waysIdsIt == waysIds.end()) {
132 // warning already given
133 continue;
134 }
135 // find directional edge (OSM ways are bidirectional)
136 const std::vector<long long int>* const way = line->getWayNodes(stop->getOrigEdgeId());
137 if (way == nullptr) {
138 WRITE_WARNINGF(TL("Cannot assign stop '%' on edge '%' to pt line '%' (wayNodes not found). Ignoring!"),
139 stop->getID(), stop->getOrigEdgeId(), line->getLineID());
140 continue;
141 }
142
143 int dir;
144 const std::vector<long long int>* wayPrev = nullptr;
145 if (waysIdsIt != waysIds.begin()) {
146 wayPrev = line->getWayNodes(*(waysIdsIt - 1));
147 }
148 const std::vector<long long int>* wayNext = nullptr;
149 if (waysIdsIt != (waysIds.end() - 1)) {
150 wayNext = line->getWayNodes(*(waysIdsIt + 1));
151 }
152 if (wayPrev == nullptr && wayNext == nullptr) {
153 WRITE_WARNINGF(TL("Cannot revise pt stop localization for incomplete pt line '%'. Ignoring!"), line->getLineID());
154 continue;
155 }
156 const long long int wayEnds = way->back();
157 const long long int wayBegins = way->front();
158 const long long int wayPrevEnds = wayPrev != nullptr ? wayPrev->back() : 0;
159 const long long int wayPrevBegins = wayPrev != nullptr ? wayPrev->front() : 0;
160 const long long int wayNextEnds = wayNext != nullptr ? wayNext->back() : 0;
161 const long long int wayNextBegins = wayNext != nullptr ? wayNext->front() : 0;
162 if (wayBegins == wayPrevEnds || wayBegins == wayPrevBegins || wayEnds == wayNextBegins || wayEnds == wayNextEnds) {
163 dir = FWD;
164 } else if (wayEnds == wayPrevBegins || wayEnds == wayPrevEnds || wayBegins == wayNextEnds || wayBegins == wayNextBegins) {
165 dir = BWD;
166 } else {
167 WRITE_WARNINGF(TL("Cannot revise pt stop localization for incomplete pt line '%'. Ignoring!"), line->getLineID());
168 continue;
169 }
170
171 std::string edgeId = stop->getEdgeId();
172 NBEdge* current = ec.getByID(edgeId);
173 int assignedTo = edgeId.at(0) == '-' ? BWD : FWD;
174
175 if (dir != assignedTo) {
176 NBEdge* reverse = NBPTStopCont::getReverseEdge(current);
177 if (reverse == nullptr) {
178 WRITE_WARNINGF(TL("Could not re-assign PT stop '%', probably broken osm file."), stop->getID());
179 continue;
180 }
181 if (stop->getLines().size() > 0) {
182 std::shared_ptr<NBPTStop> reverseStop = sc.getReverseStop(stop, ec);
183 sc.insert(reverseStop);
184 line->replaceStop(stop, reverseStop);
185 stop = reverseStop;
186 } else {
187 WRITE_WARNINGF(TL("PT stop '%' has been moved to edge '%'."), stop->getID(), reverse->getID());
188 }
189 stop->setEdgeId(reverse->getID(), ec);
190 }
191 stop->addLine(line->getRef());
192 }
193}
194
195
197 const std::vector<std::string>& waysIds = line->getWays();
198 for (std::shared_ptr<NBPTStop> stop : line->getStops()) {
199 //get the corresponding and one of the two adjacent ways
200 stop = findWay(line, stop, ec, sc);
201 if (stop == nullptr) {
202 // warning already given
203 continue;
204 }
205 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
206 if (waysIdsIt == waysIds.end()) {
207 // warning already given
208 continue;
209 }
210 stop->addLine(line->getRef());
211 }
212}
213
214
215std::shared_ptr<NBPTStop>
216NBPTLineCont::findWay(NBPTLine* line, std::shared_ptr<NBPTStop> stop, const NBEdgeCont& ec, NBPTStopCont& sc) const {
217 const std::vector<std::string>& waysIds = line->getWays();
218#ifdef DEBUG_FIND_WAY
219 if (stop->getID() == DEBUGSTOPID) {
220 std::cout << " stop=" << stop->getID() << " line=" << line->getLineID() << " edgeID=" << stop->getEdgeId() << " origID=" << stop->getOrigEdgeId() << "\n";
221 }
222#endif
223 if (stop->isLoose()) {
224 // find closest edge in route
225 double minDist = std::numeric_limits<double>::max();
226 NBEdge* best = nullptr;
227 for (NBEdge* edge : line->getRoute()) {
228 const double dist = edge->getLaneShape(0).distance2D(stop->getPosition());
229 if (dist < minDist) {
230 best = edge;
231 minDist = dist;
232 }
233 }
234#ifdef DEBUG_FIND_WAY
235 if (stop->getID() == DEBUGSTOPID) {
236 std::cout << " best=" << Named::getIDSecure(best) << " minDist=" << minDist << " wayID=" << getWayID(best->getID())
237 << " found=" << (std::find(waysIds.begin(), waysIds.end(), getWayID(best->getID())) != waysIds.end())
238 << " wayIDs=" << toString(waysIds) << "\n";
239 }
240#endif
241 if (minDist < OptionsCont::getOptions().getFloat("ptline.match-dist")) {
242 const std::string wayID = getWayID(best->getID());
243 if (stop->getEdgeId() == "") {
244 stop->setEdgeId(best->getID(), ec);
245 stop->setOrigEdgeId(wayID);
246 } else if (stop->getEdgeId() != best->getID()) {
247 // stop is used by multiple lines and mapped to different edges.
248 // check if an alternative stop already exists
249 std::shared_ptr<NBPTStop> newStop = sc.findStop(wayID, stop->getPosition());
250 if (newStop == nullptr) {
251 newStop = std::make_shared<NBPTStop>(stop->getID() + "@" + line->getLineID(), stop->getPosition(), best->getID(), wayID, stop->getLength(), stop->getName(), stop->getPermissions());
252 newStop->setEdgeId(best->getID(), ec); // trigger lane assignment
253 sc.insert(newStop);
254 }
255 line->replaceStop(stop, newStop);
256 stop = newStop;
257 }
258 } else {
259 WRITE_WARNINGF(TL("Could not assign stop '%' to pt line '%' (closest edge '%', distance %). Ignoring!"),
260 stop->getID(), line->getLineID(), Named::getIDSecure(best), minDist);
261 return nullptr;
262 }
263 } else {
264 // if the stop is part of an edge, find that edge among the line edges
265 auto waysIdsIt = waysIds.begin();
266 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
267 if ((*waysIdsIt) == stop->getOrigEdgeId()) {
268 break;
269 }
270 }
271
272 if (waysIdsIt == waysIds.end()) {
273 // stop edge not found, try additional edges
274 for (auto& edgeCand : stop->getAdditionalEdgeCandidates()) {
275 bool found = false;
276 waysIdsIt = waysIds.begin();
277 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
278 if ((*waysIdsIt) == edgeCand.first) {
279 if (stop->setEdgeId(edgeCand.second, ec)) {
280 stop->setOrigEdgeId(edgeCand.first);
281 found = true;
282 break;
283 }
284 }
285 }
286 if (found) {
287 break;
288 }
289 }
290 if (waysIdsIt == waysIds.end()) {
291 WRITE_WARNINGF(TL("Cannot assign stop % on edge '%' to pt line '%'. Ignoring!"), stop->getID(), stop->getOrigEdgeId(), line->getLineID());
292 }
293 }
294 }
295 return stop;
296}
297
298
300 std::vector<NBEdge*> edges;
301
302 NBNode* first = nullptr;
303 NBNode* last = nullptr;
304 std::vector<NBEdge*> prevWayEdges;
305 std::vector<NBEdge*> prevWayMinusEdges;
306 prevWayEdges.clear();
307 prevWayMinusEdges.clear();
308 std::vector<NBEdge*> currentWayEdges;
309 std::vector<NBEdge*> currentWayMinusEdges;
310 for (auto it3 = pTLine->getWays().begin(); it3 != pTLine->getWays().end(); it3++) {
311
312 int foundForward = 0;
313 if (cont.retrieve(*it3, false) != nullptr) {
314 currentWayEdges.push_back(cont.retrieve(*it3, false));
315 foundForward++;
316 } else {
317 int i = 0;
318 while (cont.retrieve(*it3 + "#" + std::to_string(i), true) != nullptr) {
319 if (cont.retrieve(*it3 + "#" + std::to_string(i), false)) {
320 currentWayEdges.push_back(cont.retrieve(*it3 + "#" + std::to_string(i), false));
321 foundForward++;
322 }
323 i++;
324 }
325 }
326
327 int foundReverse = 0;
328 if (cont.retrieve("-" + *it3, false) != nullptr) {
329 currentWayMinusEdges.push_back(cont.retrieve("-" + *it3, false));
330 foundReverse++;
331 } else {
332 int i = 0;
333 while (cont.retrieve("-" + *it3 + "#" + std::to_string(i), true) != nullptr) {
334 if (cont.retrieve("-" + *it3 + "#" + std::to_string(i), false)) {
335 currentWayMinusEdges.insert(currentWayMinusEdges.begin(),
336 cont.retrieve("-" + *it3 + "#" + std::to_string(i), false));
337 foundReverse++;
338 }
339 i++;
340 }
341 }
342 bool fakeMinus = false;
343 if (foundReverse == 0 && foundForward > 0 && isRailway(pTLine->getVClass())) {
344 // rail tracks may be used in both directions and are often not tagged as such.
345 // This can be repaired later with option --railway.topology.repair
346 currentWayMinusEdges.insert(currentWayMinusEdges.begin(), currentWayEdges.rbegin(), currentWayEdges.rbegin() + foundForward);
347 fakeMinus = true;
348 }
349#ifdef DEBUG_CONSTRUCT_ROUTE
350 if (pTLine->getLineID() == DEBUGLINEID) {
351 std::cout << " way=" << (*it3)
352 << " done=" << toString(edges)
353 << " first=" << Named::getIDSecure(first)
354 << " last=" << Named::getIDSecure(last)
355 << " +=" << toString(currentWayEdges)
356 << " -=" << toString(currentWayMinusEdges)
357 << "\n";
358 }
359#endif
360 if (currentWayEdges.empty()) {
361 continue;
362 }
363 if (last == currentWayEdges.front()->getFromNode() && last != nullptr) {
364 if (!prevWayEdges.empty()) {
365 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
366 prevWayEdges.clear();
367 prevWayMinusEdges.clear();
368 }
369 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
370 last = currentWayEdges.back()->getToNode();
371 } else if (last == currentWayEdges.back()->getToNode() && last != nullptr) {
372 if (!prevWayEdges.empty()) {
373 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
374 prevWayEdges.clear();
375 prevWayMinusEdges.clear();
376 }
377 if (currentWayMinusEdges.empty()) {
378 currentWayEdges.clear();
379 last = nullptr;
380 continue;
381 } else {
382 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
383 if (fakeMinus) {
384 last = currentWayMinusEdges.back()->getFromNode();
385 } else {
386 last = currentWayMinusEdges.back()->getToNode();
387 }
388 }
389 } else if (first == currentWayEdges.front()->getFromNode() && first != nullptr) {
390 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
391 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
392 last = currentWayEdges.back()->getToNode();
393 prevWayEdges.clear();
394 prevWayMinusEdges.clear();
395 } else if (first == currentWayEdges.back()->getToNode() && first != nullptr) {
396 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
397 if (currentWayMinusEdges.empty()) {
398 currentWayEdges.clear();
399 last = nullptr;
400 prevWayEdges.clear();
401 prevWayMinusEdges.clear();
402 continue;
403 } else {
404 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
405 last = currentWayMinusEdges.back()->getToNode();
406 prevWayEdges.clear();
407 prevWayMinusEdges.clear();
408 }
409 } else {
410 if (it3 != pTLine->getWays().begin()) {
411#ifdef DEBUG_CONSTRUCT_ROUTE
412 if (pTLine->getLineID() == DEBUGLINEID) {
413 std::cout << " way " << (*it3)
414 << " is not the start of ptline " << pTLine->getLineID()
415 << " (" + pTLine->getName() + ")\n";
416 }
417#endif
418 } else if (pTLine->getWays().size() == 1) {
419 if (currentWayEdges.size() > 0) {
420 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
421 } else {
422 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
423 }
424 }
425 prevWayEdges = currentWayEdges;
426 prevWayMinusEdges = currentWayMinusEdges;
427 if (!prevWayEdges.empty()) {
428 first = prevWayEdges.front()->getFromNode();
429 last = prevWayEdges.back()->getToNode();
430 } else {
431 first = nullptr;
432 last = nullptr;
433 }
434 }
435 currentWayEdges.clear();
436 currentWayMinusEdges.clear();
437 }
438 pTLine->setEdges(edges);
439}
440
441
442void
443NBPTLineCont::replaceEdge(const std::string& edgeID, const EdgeVector& replacement) {
444 //std::cout << " replaceEdge " << edgeID << " replacement=" << toString(replacement) << "\n";
445 if (myPTLines.size() > 0 && myPTLineLookup.size() == 0) {
446 // init lookup once
447 for (auto& item : myPTLines) {
448 for (const NBEdge* e : item.second->getRoute()) {
449 myPTLineLookup[e->getID()].insert(item.second);
450 }
451 }
452 }
453 for (NBPTLine* line : myPTLineLookup[edgeID]) {
454 line->replaceEdge(edgeID, replacement);
455 for (const NBEdge* e : replacement) {
456 myPTLineLookup[e->getID()].insert(line);
457 }
458 }
459 myPTLineLookup.erase(edgeID);
460}
461
462
463std::set<std::string>&
465 return myServedPTStops;
466}
467
468
469void
471 std::map<std::string, SUMOVehicleClass> types;
472 types["bus"] = SVC_BUS;
473 types["tram"] = SVC_TRAM;
474 types["train"] = SVC_RAIL;
475 types["subway"] = SVC_RAIL_URBAN;
476 types["light_rail"] = SVC_RAIL_URBAN;
477 types["monorail"] = SVC_RAIL_URBAN;
478 types["aerialway"] = SVC_RAIL_URBAN;
479 types["ferry"] = SVC_SHIP;
480
482 ec.getAllRouterEdges(), true, &NBRouterEdge::getTravelTimeStatic, nullptr, true);
483
484 for (auto& item : myPTLines) {
485 NBPTLine* line = item.second;
486 std::vector<std::shared_ptr<NBPTStop> > stops = line->getStops();
487 if (stops.size() < 2) {
488 continue;
489 }
490 if (types.count(line->getType()) == 0) {
491 WRITE_WARNINGF(TL("Could not determine vehicle class for public transport line of type '%'."), line->getType());
492 continue;
493 }
494 NBVehicle veh(line->getRef(), types[line->getType()]);
495 std::vector<std::shared_ptr<NBPTStop> > newStops;
496 std::shared_ptr<NBPTStop> from = nullptr;
497 for (auto it = stops.begin(); it != stops.end(); ++it) {
498 std::shared_ptr<NBPTStop> to = *it;
499 std::shared_ptr<NBPTStop> used = *it;
500 if (to->getBidiStop() != nullptr) {
501 double best = std::numeric_limits<double>::max();
502 std::shared_ptr<NBPTStop> to2 = to->getBidiStop();
503 if (from == nullptr) {
504 if ((it + 1) != stops.end()) {
505 from = to;
506 std::shared_ptr<NBPTStop> from2 = to2;
507 to = *(it + 1);
508 const double c1 = getCost(ec, *router, from, to, &veh);
509 const double c2 = getCost(ec, *router, from2, to, &veh);
510 //std::cout << " from=" << from->getID() << " to=" << to->getID() << " c1=" << MIN2(10000.0, c1) << "\n";
511 //std::cout << " from2=" << from2->getID() << " to=" << to->getID() << " c2=" << MIN2(10000.0, c2) << "\n";
512 best = c1;
513 if (to->getBidiStop() != nullptr) {
514 to2 = to->getBidiStop();
515 const double c3 = getCost(ec, *router, from, to2, &veh);
516 const double c4 = getCost(ec, *router, from2, to2, &veh);
517 //std::cout << " from=" << from->getID() << " to2=" << to2->getID() << " c3=" << MIN2(10000.0, c3) << "\n";
518 //std::cout << " from2=" << from2->getID() << " to2=" << to2->getID() << " c4=" << MIN2(10000.0, c4) << "\n";
519 if (c2 < best) {
520 used = from2;
521 best = c2;
522 }
523 if (c3 < best) {
524 used = from;
525 best = c3;
526 }
527 if (c4 < best) {
528 used = from2;
529 best = c4;
530 }
531 } else {
532 if (c2 < c1) {
533 used = from2;
534 best = c2;
535 } else {
536 best = c1;
537 }
538 }
539 }
540 } else {
541 const double c1 = getCost(ec, *router, from, to, &veh);
542 const double c2 = getCost(ec, *router, from, to2, &veh);
543 //std::cout << " from=" << from->getID() << " to=" << to->getID() << " c1=" << MIN2(10000.0, c1) << "\n";
544 //std::cout << " from=" << from->getID() << " t2o=" << to2->getID() << " c2=" << MIN2(10000.0, c2) << "\n";
545 if (c2 < c1) {
546 used = to2;
547 best = c2;
548 } else {
549 best = c1;
550 }
551
552 }
553 if (best < std::numeric_limits<double>::max()) {
554 from = used;
555 } else {
556 WRITE_WARNINGF(TL("Could not determine direction for line '%' at stop '%'."), line->getLineID(), used->getID());
557 }
558 }
559 from = used;
560 newStops.push_back(used);
561 }
562 assert(stops.size() == newStops.size());
563 line->replaceStops(newStops);
564 }
565 delete router;
566}
567
568
569void
571 for (auto& item : myPTLines) {
572 item.second->removeInvalidEdges(ec);
573 }
574}
575
576
577void
579 for (auto& item : myPTLines) {
580 NBPTLine* line = item.second;
581 const std::vector<NBEdge*>& route = line->getRoute();
582 const SUMOVehicleClass svc = line->getVClass();
583 for (int i = 1; i < (int)route.size(); i++) {
584 NBEdge* e1 = route[i - 1];
585 NBEdge* e2 = route[i];
586 std::vector<NBEdge::Connection> cons = e1->getConnectionsFromLane(-1, e2, -1);
587 if (cons.size() == 0) {
588 //WRITE_WARNINGF(TL("Disconnected ptline '%' between edge '%' and edge '%'"), line->getLineID(), e1->getID(), e2->getID());
589 } else {
590 bool ok = false;
591 for (const auto& c : cons) {
592 if ((e1->getPermissions(c.fromLane) & svc) == svc) {
593 ok = true;
594 break;
595 }
596 }
597 if (!ok) {
598 int lane = cons[0].fromLane;
599 e1->setPermissions(e1->getPermissions(lane) | svc, lane);
600 }
601 }
602 }
603 }
604}
605
606
607double
609 const std::shared_ptr<NBPTStop> from, const std::shared_ptr<NBPTStop> to, const NBVehicle* veh) {
610 NBEdge* fromEdge = ec.getByID(from->getEdgeId());
611 NBEdge* toEdge = ec.getByID(to->getEdgeId());
612 if (fromEdge == nullptr || toEdge == nullptr) {
613 return std::numeric_limits<double>::max();
614 } else if (fromEdge == toEdge) {
615 if (from->getEndPos() <= to->getEndPos()) {
616 return to->getEndPos() - from->getEndPos();
617 } else {
618 return std::numeric_limits<double>::max();
619 }
620 } else if (fromEdge->getBidiEdge() == toEdge) {
621 return std::numeric_limits<double>::max();
622 }
623 std::vector<const NBRouterEdge*> route;
624 router.compute(fromEdge, toEdge, veh, 0, route);
625 if (route.size() == 0) {
626 return std::numeric_limits<double>::max();
627 } else {
628 return router.recomputeCosts(route, veh, 0);
629 }
630}
631
632
633std::string
634NBPTLineCont::getWayID(const std::string& edgeID) {
635 std::size_t found = edgeID.rfind("#");
636 std::string result = edgeID;
637 if (found != std::string::npos) {
638 result = edgeID.substr(0, found);
639 }
640 if (result[0] == '-') {
641 result = result.substr(1);
642 }
643 return result;
644}
645
646
647/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:271
#define TL(string)
Definition: MsgHandler.h:287
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:42
#define DEBUGLINEID
#define DEBUGSTOPID
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_SHIP
is an arbitrary ship
@ SVC_RAIL
vehicle is a not electrified rail
@ SVC_RAIL_URBAN
vehicle is a city rail
@ SVC_TRAM
vehicle is a light rail
@ SVC_BUS
vehicle is a bus
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
Computes the shortest path through a network using the Dijkstra algorithm.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
NBEdge * getByID(const std::string &edgeID) const
Returns the edge with id if it exists.
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:279
RouterEdgeVector getAllRouterEdges() const
return all router edges
The representation of a single edge during network building.
Definition: NBEdge.h:92
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:4232
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given
Definition: NBEdge.cpp:4195
const std::string & getID() const
Definition: NBEdge.h:1515
std::vector< Connection > getConnectionsFromLane(int lane, const NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
Definition: NBEdge.cpp:1221
const NBEdge * getBidiEdge() const
Definition: NBEdge.h:1501
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Definition: NBEdge.cpp:936
Represents a single node (junction) during network building.
Definition: NBNode.h:66
static double getCost(const NBEdgeCont &ec, SUMOAbstractRouter< NBRouterEdge, NBVehicle > &router, const std::shared_ptr< NBPTStop > from, const std::shared_ptr< NBPTStop > to, const NBVehicle *veh)
void reviseStops(NBPTLine *line, const NBEdgeCont &ec, NBPTStopCont &sc)
find directional edge for all stops of the line
void fixPermissions()
ensure that all turn lanes have sufficient permissions
void process(NBEdgeCont &ec, NBPTStopCont &sc, bool routeOnly=false)
std::set< std::string > myServedPTStops
Definition: NBPTLineCont.h:79
~NBPTLineCont()
destructor
std::map< std::string, NBPTLine * > myPTLines
The map of names to pt lines.
Definition: NBPTLineCont.h:66
std::shared_ptr< NBPTStop > findWay(NBPTLine *line, std::shared_ptr< NBPTStop > stop, const NBEdgeCont &ec, NBPTStopCont &sc) const
void replaceEdge(const std::string &edgeID, const EdgeVector &replacement)
replace the edge with the given edge list in all lines
std::set< std::string > & getServedPTStops()
void constructRoute(NBPTLine *myPTLine, const NBEdgeCont &cont)
bool insert(NBPTLine *ptLine)
insert new line
void removeInvalidEdges(const NBEdgeCont &ec)
filter out edges that were removed due to –geometry.remove
void fixBidiStops(const NBEdgeCont &ec)
select the correct stop on superposed rail edges
static const int BWD
Definition: NBPTLineCont.h:63
static const int FWD
Definition: NBPTLineCont.h:62
static std::string getWayID(const std::string &edgeID)
void reviseSingleWayStops(NBPTLine *line, const NBEdgeCont &ec, NBPTStopCont &sc)
std::map< std::string, std::set< NBPTLine * > > myPTLineLookup
The map of edge ids to lines that use this edge in their route.
Definition: NBPTLineCont.h:87
const std::string & getType() const
Definition: NBPTLine.h:59
void replaceStop(std::shared_ptr< NBPTStop > oldStop, std::shared_ptr< NBPTStop > newStop)
replace the given stop
Definition: NBPTLine.cpp:268
void replaceStops(std::vector< std::shared_ptr< NBPTStop > > stops)
Definition: NBPTLine.h:74
const std::vector< long long int > * getWayNodes(std::string wayId)
Definition: NBPTLine.cpp:123
void deleteInvalidStops(const NBEdgeCont &ec, const NBPTStopCont &sc)
remove invalid stops from the line
Definition: NBPTLine.cpp:296
const std::string & getName() const
Definition: NBPTLine.h:55
const std::string & getLineID() const
Definition: NBPTLine.h:51
SUMOVehicleClass getVClass() const
Definition: NBPTLine.h:89
const std::string & getRef() const
get line reference (not unique)
Definition: NBPTLine.h:70
const std::vector< NBEdge * > & getRoute() const
Definition: NBPTLine.cpp:163
const std::vector< std::string > & getWays() const
Definition: NBPTLine.h:110
const std::vector< std::shared_ptr< NBPTStop > > & getStops()
Definition: NBPTLine.cpp:65
void setEdges(const std::vector< NBEdge * > &edges)
Definition: NBPTLine.cpp:132
Container for public transport stops during the net building process.
Definition: NBPTStopCont.h:44
static NBEdge * getReverseEdge(NBEdge *edge)
std::shared_ptr< NBPTStop > getReverseStop(std::shared_ptr< NBPTStop > pStop, const NBEdgeCont &ec)
std::shared_ptr< NBPTStop > findStop(const std::string &origEdgeID, Position pos, double threshold=1) const
bool insert(std::shared_ptr< NBPTStop > ptStop, bool floating=false)
Inserts a node into the map.
static double getTravelTimeStatic(const NBRouterEdge *const edge, const NBVehicle *const, double)
Definition: NBEdge.h:82
A vehicle as used by router.
Definition: NBVehicle.h:42
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Definition: Named.h:67
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector)
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.hpp:21838