53 delete myPTLine.second;
73 if (item.second->getWays().size() > 0) {
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());
100 for (std::shared_ptr<NBPTStop> stop : line->
getStops()) {
109 const std::vector<std::string>& waysIds = line->
getWays();
110 if (waysIds.size() == 1 && line->
getStops().size() > 1) {
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());
119 WRITE_WARNINGF(
TL(
"Cannot revise pt stop localization for pt line '%', which has no route edges. Ignoring!"), line->
getLineID());
122 std::vector<std::shared_ptr<NBPTStop> > stops = line->
getStops();
123 for (std::shared_ptr<NBPTStop> stop : stops) {
125 stop =
findWay(line, stop, ec, sc);
126 if (stop ==
nullptr) {
130 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
131 if (waysIdsIt == waysIds.end()) {
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());
144 const std::vector<long long int>* wayPrev =
nullptr;
145 if (waysIdsIt != waysIds.begin()) {
148 const std::vector<long long int>* wayNext =
nullptr;
149 if (waysIdsIt != (waysIds.end() - 1)) {
152 if (wayPrev ==
nullptr && wayNext ==
nullptr) {
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) {
164 }
else if (wayEnds == wayPrevBegins || wayEnds == wayPrevEnds || wayBegins == wayNextEnds || wayBegins == wayNextBegins) {
171 std::string edgeId = stop->getEdgeId();
173 int assignedTo = edgeId.at(0) ==
'-' ?
BWD :
FWD;
175 if (dir != assignedTo) {
177 if (reverse ==
nullptr) {
178 WRITE_WARNINGF(
TL(
"Could not re-assign PT stop '%', probably broken osm file."), stop->getID());
181 if (stop->getLines().size() > 0) {
182 std::shared_ptr<NBPTStop> reverseStop = sc.
getReverseStop(stop, ec);
189 stop->setEdgeId(reverse->
getID(), ec);
191 stop->addLine(line->
getRef());
197 const std::vector<std::string>& waysIds = line->
getWays();
198 for (std::shared_ptr<NBPTStop> stop : line->
getStops()) {
200 stop =
findWay(line, stop, ec, sc);
201 if (stop ==
nullptr) {
205 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
206 if (waysIdsIt == waysIds.end()) {
210 stop->addLine(line->
getRef());
215std::shared_ptr<NBPTStop>
217 const std::vector<std::string>& waysIds = line->
getWays();
220 std::cout <<
" stop=" << stop->getID() <<
" line=" << line->
getLineID() <<
" edgeID=" << stop->getEdgeId() <<
" origID=" << stop->getOrigEdgeId() <<
"\n";
223 if (stop->isLoose()) {
225 double minDist = std::numeric_limits<double>::max();
229 if (dist < minDist) {
237 <<
" found=" << (std::find(waysIds.begin(), waysIds.end(),
getWayID(best->
getID())) != waysIds.end())
238 <<
" wayIDs=" <<
toString(waysIds) <<
"\n";
243 if (stop->getEdgeId() ==
"") {
244 stop->setEdgeId(best->
getID(), ec);
245 stop->setOrigEdgeId(wayID);
246 }
else if (stop->getEdgeId() != best->
getID()) {
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);
259 WRITE_WARNINGF(
TL(
"Could not assign stop '%' to pt line '%' (closest edge '%', distance %). Ignoring!"),
265 auto waysIdsIt = waysIds.begin();
266 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
267 if ((*waysIdsIt) == stop->getOrigEdgeId()) {
272 if (waysIdsIt == waysIds.end()) {
274 for (
auto& edgeCand : stop->getAdditionalEdgeCandidates()) {
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);
290 if (waysIdsIt == waysIds.end()) {
291 WRITE_WARNINGF(
TL(
"Cannot assign stop % on edge '%' to pt line '%'. Ignoring!"), stop->getID(), stop->getOrigEdgeId(), line->
getLineID());
300 std::vector<NBEdge*> edges;
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++) {
312 int foundForward = 0;
313 if (cont.
retrieve(*it3,
false) !=
nullptr) {
314 currentWayEdges.push_back(cont.
retrieve(*it3,
false));
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));
327 int foundReverse = 0;
328 if (cont.
retrieve(
"-" + *it3,
false) !=
nullptr) {
329 currentWayMinusEdges.push_back(cont.
retrieve(
"-" + *it3,
false));
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));
342 bool fakeMinus =
false;
346 currentWayMinusEdges.insert(currentWayMinusEdges.begin(), currentWayEdges.rbegin(), currentWayEdges.rbegin() + foundForward);
349#ifdef DEBUG_CONSTRUCT_ROUTE
351 std::cout <<
" way=" << (*it3)
355 <<
" +=" <<
toString(currentWayEdges)
356 <<
" -=" <<
toString(currentWayMinusEdges)
360 if (currentWayEdges.empty()) {
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();
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();
377 if (currentWayMinusEdges.empty()) {
378 currentWayEdges.clear();
382 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
384 last = currentWayMinusEdges.back()->getFromNode();
386 last = currentWayMinusEdges.back()->getToNode();
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();
400 prevWayEdges.clear();
401 prevWayMinusEdges.clear();
404 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
405 last = currentWayMinusEdges.back()->getToNode();
406 prevWayEdges.clear();
407 prevWayMinusEdges.clear();
410 if (it3 != pTLine->
getWays().begin()) {
411#ifdef DEBUG_CONSTRUCT_ROUTE
413 std::cout <<
" way " << (*it3)
414 <<
" is not the start of ptline " << pTLine->
getLineID()
415 <<
" (" + pTLine->
getName() +
")\n";
418 }
else if (pTLine->
getWays().size() == 1) {
419 if (currentWayEdges.size() > 0) {
420 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
422 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
425 prevWayEdges = currentWayEdges;
426 prevWayMinusEdges = currentWayMinusEdges;
427 if (!prevWayEdges.empty()) {
428 first = prevWayEdges.front()->getFromNode();
429 last = prevWayEdges.back()->getToNode();
435 currentWayEdges.clear();
436 currentWayMinusEdges.clear();
448 for (
const NBEdge* e : item.second->getRoute()) {
454 line->replaceEdge(edgeID, replacement);
455 for (
const NBEdge* e : replacement) {
463std::set<std::string>&
471 std::map<std::string, SUMOVehicleClass> types;
486 std::vector<std::shared_ptr<NBPTStop> > stops = line->
getStops();
487 if (stops.size() < 2) {
490 if (types.count(line->
getType()) == 0) {
491 WRITE_WARNINGF(
TL(
"Could not determine vehicle class for public transport line of type '%'."), 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()) {
506 std::shared_ptr<NBPTStop> from2 = to2;
508 const double c1 =
getCost(ec, *router, from, to, &veh);
509 const double c2 =
getCost(ec, *router, from2, to, &veh);
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);
541 const double c1 =
getCost(ec, *router, from, to, &veh);
542 const double c2 =
getCost(ec, *router, from, to2, &veh);
553 if (best < std::numeric_limits<double>::max()) {
560 newStops.push_back(used);
562 assert(stops.size() == newStops.size());
572 item.second->removeInvalidEdges(ec);
581 const std::vector<NBEdge*>& route = line->
getRoute();
583 for (
int i = 1; i < (int)route.size(); i++) {
584 NBEdge* e1 = route[i - 1];
587 if (cons.size() == 0) {
591 for (
const auto& c : cons) {
598 int lane = cons[0].fromLane;
609 const std::shared_ptr<NBPTStop> from,
const std::shared_ptr<NBPTStop> to,
const NBVehicle* veh) {
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();
618 return std::numeric_limits<double>::max();
621 return std::numeric_limits<double>::max();
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();
635 std::size_t found = edgeID.rfind(
"#");
636 std::string result = edgeID;
637 if (found != std::string::npos) {
638 result = edgeID.substr(0, found);
640 if (result[0] ==
'-') {
641 result = result.substr(1);
#define WRITE_WARNINGF(...)
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
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)
Computes the shortest path through a network using the Dijkstra algorithm.
Storage for edges, including some functionality operating on multiple edges.
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.
RouterEdgeVector getAllRouterEdges() const
return all router edges
The representation of a single edge during network building.
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given
const std::string & getID() const
std::vector< Connection > getConnectionsFromLane(int lane, const NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
const NBEdge * getBidiEdge() const
const PositionVector & getLaneShape(int i) const
Returns the shape of the nth lane.
Represents a single node (junction) during network building.
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
~NBPTLineCont()
destructor
std::map< std::string, NBPTLine * > myPTLines
The map of names to pt lines.
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 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.
const std::string & getType() const
void replaceStop(std::shared_ptr< NBPTStop > oldStop, std::shared_ptr< NBPTStop > newStop)
replace the given stop
void replaceStops(std::vector< std::shared_ptr< NBPTStop > > stops)
const std::vector< long long int > * getWayNodes(std::string wayId)
void deleteInvalidStops(const NBEdgeCont &ec, const NBPTStopCont &sc)
remove invalid stops from the line
const std::string & getName() const
const std::string & getLineID() const
SUMOVehicleClass getVClass() const
const std::string & getRef() const
get line reference (not unique)
const std::vector< NBEdge * > & getRoute() const
const std::vector< std::string > & getWays() const
const std::vector< std::shared_ptr< NBPTStop > > & getStops()
void setEdges(const std::vector< NBEdge * > &edges)
Container for public transport stops during the net building process.
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)
A vehicle as used by router.
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
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.
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