53 delete myPTLine.second;
82 if (item.second->getWays().size() > 0) {
97 const std::string firstStopEdge = line->
getStops().front()->getEdgeId();
98 const std::string lastStopEdge = line->
getStops().back()->getEdgeId();
99 std::vector<NBEdge*> edges = line->
getRoute();
100 if (firstStopEdge == edges.back()->getID()) {
101 edges.insert(edges.begin(), edges.back());
102 }
else if (lastStopEdge == edges.front()->getID()) {
103 edges.push_back(edges.front());
109 for (std::shared_ptr<NBPTStop> stop : line->
getStops()) {
118 const std::vector<std::string>& waysIds = line->
getWays();
119 if (waysIds.size() == 1 && line->
getStops().size() > 1) {
123 if (waysIds.size() <= 1) {
124 WRITE_WARNINGF(
TL(
"Cannot revise pt stop localization for pt line '%', which consist of one way only. Ignoring!"), line->
getLineID());
128 WRITE_WARNINGF(
TL(
"Cannot revise pt stop localization for pt line '%', which has no route edges. Ignoring!"), line->
getLineID());
131 std::vector<std::shared_ptr<NBPTStop> > stops = line->
getStops();
132 for (std::shared_ptr<NBPTStop> stop : stops) {
134 stop =
findWay(line, stop, ec, sc);
135 if (stop ==
nullptr) {
139 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
140 if (waysIdsIt == waysIds.end()) {
145 const std::vector<long long int>*
const way = line->
getWayNodes(stop->getOrigEdgeId());
146 if (way ==
nullptr) {
147 WRITE_WARNINGF(
TL(
"Cannot assign stop '%' on edge '%' to pt line '%' (wayNodes not found). Ignoring!"),
148 stop->getID(), stop->getOrigEdgeId(), line->
getLineID());
153 const std::vector<long long int>* wayPrev =
nullptr;
154 if (waysIdsIt != waysIds.begin()) {
157 const std::vector<long long int>* wayNext =
nullptr;
158 if (waysIdsIt != (waysIds.end() - 1)) {
161 if (wayPrev ==
nullptr && wayNext ==
nullptr) {
165 const long long int wayEnds = way->back();
166 const long long int wayBegins = way->front();
167 const long long int wayPrevEnds = wayPrev !=
nullptr ? wayPrev->back() : 0;
168 const long long int wayPrevBegins = wayPrev !=
nullptr ? wayPrev->front() : 0;
169 const long long int wayNextEnds = wayNext !=
nullptr ? wayNext->back() : 0;
170 const long long int wayNextBegins = wayNext !=
nullptr ? wayNext->front() : 0;
171 if (wayBegins == wayPrevEnds || wayBegins == wayPrevBegins || wayEnds == wayNextBegins || wayEnds == wayNextEnds) {
173 }
else if (wayEnds == wayPrevBegins || wayEnds == wayPrevEnds || wayBegins == wayNextEnds || wayBegins == wayNextBegins) {
180 std::string edgeId = stop->getEdgeId();
182 int assignedTo = edgeId.at(0) ==
'-' ?
BWD :
FWD;
184 if (dir != assignedTo) {
186 if (reverse ==
nullptr) {
187 WRITE_WARNINGF(
TL(
"Could not re-assign PT stop '%', probably broken osm file."), stop->getID());
190 if (stop->getLines().size() > 0) {
191 std::shared_ptr<NBPTStop> reverseStop = sc.
getReverseStop(stop, ec);
198 stop->setEdgeId(reverse->
getID(), ec);
200 stop->addLine(line->
getRef());
206 const std::vector<std::string>& waysIds = line->
getWays();
207 for (std::shared_ptr<NBPTStop> stop : line->
getStops()) {
209 stop =
findWay(line, stop, ec, sc);
210 if (stop ==
nullptr) {
214 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
215 if (waysIdsIt == waysIds.end()) {
219 stop->addLine(line->
getRef());
224std::shared_ptr<NBPTStop>
226 const std::vector<std::string>& waysIds = line->
getWays();
229 std::cout <<
" stop=" << stop->getID() <<
" line=" << line->
getLineID() <<
" edgeID=" << stop->getEdgeId() <<
" origID=" << stop->getOrigEdgeId() <<
"\n";
232 if (stop->isLoose()) {
234 double minDist = std::numeric_limits<double>::max();
238 if (dist < minDist) {
246 <<
" found=" << (std::find(waysIds.begin(), waysIds.end(),
getWayID(best->
getID())) != waysIds.end())
247 <<
" wayIDs=" <<
toString(waysIds) <<
"\n";
252 if (stop->getEdgeId() ==
"") {
253 stop->setEdgeId(best->
getID(), ec);
254 stop->setOrigEdgeId(wayID);
255 }
else if (stop->getEdgeId() != best->
getID()) {
258 std::shared_ptr<NBPTStop> newStop = sc.
findStop(wayID, stop->getPosition());
259 if (newStop ==
nullptr) {
260 newStop = std::make_shared<NBPTStop>(stop->getID() +
"@" + line->
getLineID(), stop->getPosition(), best->
getID(), wayID, stop->getLength(), stop->getName(), stop->getPermissions());
261 newStop->setEdgeId(best->
getID(), ec);
268 WRITE_WARNINGF(
TL(
"Could not assign stop '%' to pt line '%' (closest edge '%', distance %). Ignoring!"),
274 auto waysIdsIt = waysIds.begin();
275 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
276 if ((*waysIdsIt) == stop->getOrigEdgeId()) {
281 if (waysIdsIt == waysIds.end()) {
283 for (
auto& edgeCand : stop->getAdditionalEdgeCandidates()) {
285 waysIdsIt = waysIds.begin();
286 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
287 if ((*waysIdsIt) == edgeCand.first) {
288 if (stop->setEdgeId(edgeCand.second, ec)) {
289 stop->setOrigEdgeId(edgeCand.first);
299 if (waysIdsIt == waysIds.end()) {
300 WRITE_WARNINGF(
TL(
"Cannot assign stop % on edge '%' to pt line '%'. Ignoring!"), stop->getID(), stop->getOrigEdgeId(), line->
getLineID());
309 std::vector<NBEdge*> edges;
313 std::vector<NBEdge*> prevWayEdges;
314 std::vector<NBEdge*> prevWayMinusEdges;
315 std::vector<NBEdge*> currentWayEdges;
316 std::vector<NBEdge*> currentWayMinusEdges;
317 for (
auto it3 = pTLine->
getWays().begin(); it3 != pTLine->
getWays().end(); it3++) {
319 int foundForward = 0;
320 if (cont.
retrieve(*it3,
false) !=
nullptr) {
321 currentWayEdges.push_back(cont.
retrieve(*it3,
false));
325 while (cont.
retrieve(*it3 +
"#" + std::to_string(i),
true) !=
nullptr) {
326 if (cont.
retrieve(*it3 +
"#" + std::to_string(i),
false)) {
327 currentWayEdges.push_back(cont.
retrieve(*it3 +
"#" + std::to_string(i),
false));
334 int foundReverse = 0;
335 if (cont.
retrieve(
"-" + *it3,
false) !=
nullptr) {
336 currentWayMinusEdges.push_back(cont.
retrieve(
"-" + *it3,
false));
340 while (cont.
retrieve(
"-" + *it3 +
"#" + std::to_string(i),
true) !=
nullptr) {
341 if (cont.
retrieve(
"-" + *it3 +
"#" + std::to_string(i),
false)) {
342 currentWayMinusEdges.insert(currentWayMinusEdges.end() - foundReverse,
343 cont.
retrieve(
"-" + *it3 +
"#" + std::to_string(i),
false));
349 bool fakeMinus =
false;
353 currentWayMinusEdges.insert(currentWayMinusEdges.begin(), currentWayEdges.rbegin(), currentWayEdges.rbegin() + foundForward);
356#ifdef DEBUG_CONSTRUCT_ROUTE
358 std::cout <<
" way=" << (*it3)
362 <<
"\n +=" <<
toString(currentWayEdges)
363 <<
"\n -=" <<
toString(currentWayMinusEdges)
364 <<
"\n p+=" <<
toString(prevWayEdges)
365 <<
"\n p-=" <<
toString(prevWayMinusEdges)
369 if (currentWayEdges.empty()) {
372 if (last == currentWayEdges.front()->getFromNode() && last !=
nullptr) {
373 if (!prevWayEdges.empty()) {
374 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
375 prevWayEdges.clear();
376 prevWayMinusEdges.clear();
378 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
379 last = currentWayEdges.back()->getToNode();
380 }
else if (last == currentWayEdges.back()->getToNode() && last !=
nullptr) {
381 if (!prevWayEdges.empty()) {
382 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
383 prevWayEdges.clear();
384 prevWayMinusEdges.clear();
386 if (currentWayMinusEdges.empty()) {
387 currentWayEdges.clear();
391 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
393 last = currentWayMinusEdges.back()->getFromNode();
395 last = currentWayMinusEdges.back()->getToNode();
398 }
else if (first == currentWayEdges.front()->getFromNode() && first !=
nullptr) {
399 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
400 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
401 last = currentWayEdges.back()->getToNode();
402 prevWayEdges.clear();
403 prevWayMinusEdges.clear();
404 }
else if (first == currentWayEdges.back()->getToNode() && first !=
nullptr) {
405 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
406 if (currentWayMinusEdges.empty()) {
407 currentWayEdges.clear();
409 prevWayEdges.clear();
410 prevWayMinusEdges.clear();
413 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
414 last = currentWayMinusEdges.back()->getToNode();
415 prevWayEdges.clear();
416 prevWayMinusEdges.clear();
419 if (it3 != pTLine->
getWays().begin()) {
420#ifdef DEBUG_CONSTRUCT_ROUTE
422 std::cout <<
" way " << (*it3)
423 <<
" is not the start of ptline " << pTLine->
getLineID()
424 <<
" (" + pTLine->
getName() +
")\n";
427 }
else if (pTLine->
getWays().size() == 1) {
428 if (currentWayEdges.size() > 0) {
429 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
431 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
434 prevWayEdges = currentWayEdges;
435 prevWayMinusEdges = currentWayMinusEdges;
436 if (!prevWayEdges.empty()) {
437 first = prevWayEdges.front()->getFromNode();
438 last = prevWayEdges.back()->getToNode();
444 currentWayEdges.clear();
445 currentWayMinusEdges.clear();
457 for (
const NBEdge* e : item.second->getRoute()) {
463 line->replaceEdge(edgeID, replacement);
464 for (
const NBEdge* e : replacement) {
472std::set<std::string>&
480 std::map<std::string, SUMOVehicleClass> types;
497 std::vector<std::shared_ptr<NBPTStop> > stops = line->
getStops();
498 if (stops.size() < 2) {
501 if (types.count(line->
getType()) == 0) {
502 WRITE_WARNINGF(
TL(
"Could not determine vehicle class for public transport line of type '%'."), line->
getType());
506 std::vector<std::shared_ptr<NBPTStop> > newStops;
507 std::shared_ptr<NBPTStop> from =
nullptr;
508 for (
auto it = stops.begin(); it != stops.end(); ++it) {
509 std::shared_ptr<NBPTStop> to = *it;
510 std::shared_ptr<NBPTStop> used = *it;
511 if (to->getBidiStop() !=
nullptr) {
512 double best = std::numeric_limits<double>::max();
513 std::shared_ptr<NBPTStop> to2 = to->getBidiStop();
514 if (from ==
nullptr) {
515 if ((it + 1) != stops.end()) {
517 std::shared_ptr<NBPTStop> from2 = to2;
519 const double c1 =
getCost(ec, *router, from, to, &veh);
520 const double c2 =
getCost(ec, *router, from2, to, &veh);
524 if (to->getBidiStop() !=
nullptr) {
525 to2 = to->getBidiStop();
526 const double c3 =
getCost(ec, *router, from, to2, &veh);
527 const double c4 =
getCost(ec, *router, from2, to2, &veh);
552 const double c1 =
getCost(ec, *router, from, to, &veh);
553 const double c2 =
getCost(ec, *router, from, to2, &veh);
564 if (best < std::numeric_limits<double>::max()) {
571 newStops.push_back(used);
573 assert(stops.size() == newStops.size());
583 item.second->removeInvalidEdges(ec);
592 const std::vector<NBEdge*>& route = line->
getRoute();
594 for (
int i = 1; i < (int)route.size(); i++) {
595 NBEdge* e1 = route[i - 1];
598 if (cons.size() == 0) {
602 for (
const auto& c : cons) {
609 int lane = cons[0].fromLane;
620 const std::shared_ptr<NBPTStop> from,
const std::shared_ptr<NBPTStop> to,
const NBVehicle* veh) {
623 if (fromEdge ==
nullptr || toEdge ==
nullptr) {
624 return std::numeric_limits<double>::max();
625 }
else if (fromEdge == toEdge) {
626 if (from->getEndPos() <= to->getEndPos()) {
627 return to->getEndPos() - from->getEndPos();
629 return std::numeric_limits<double>::max();
632 return std::numeric_limits<double>::max();
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();
646 std::size_t found = edgeID.rfind(
"#");
647 std::string result = edgeID;
648 if (found != std::string::npos) {
649 result = edgeID.substr(0, found);
651 if (result[0] ==
'-') {
652 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 permissions 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
NBPTLine * retrieve(const std::string &lineID)
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