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