38#define DEBUGLINEID "1986097"
53 delete myPTLine.second;
73 if (item.second->getWays().size() > 0) {
84 for (std::shared_ptr<NBPTStop> stop : line->
getStops()) {
93 const std::vector<std::string>& waysIds = line->
getWays();
94 if (waysIds.size() == 1 && line->
getStops().size() > 1) {
98 if (waysIds.size() <= 1) {
99 WRITE_WARNINGF(
TL(
"Cannot revise pt stop localization for pt line '%', which consist of one way only. Ignoring!"), line->
getLineID());
103 WRITE_WARNINGF(
TL(
"Cannot revise pt stop localization for pt line '%', which has no route edges. Ignoring!"), line->
getLineID());
106 std::vector<std::shared_ptr<NBPTStop> > stops = line->
getStops();
107 for (std::shared_ptr<NBPTStop> stop : stops) {
109 stop =
findWay(line, stop, ec, sc);
110 if (stop ==
nullptr) {
114 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
115 if (waysIdsIt == waysIds.end()) {
120 const std::vector<long long int>*
const way = line->
getWayNodes(stop->getOrigEdgeId());
121 if (way ==
nullptr) {
122 WRITE_WARNINGF(
TL(
"Cannot assign stop '%' on edge '%' to pt line '%' (wayNodes not found). Ignoring!"),
123 stop->getID(), stop->getOrigEdgeId(), line->
getLineID());
128 const std::vector<long long int>* wayPrev =
nullptr;
129 if (waysIdsIt != waysIds.begin()) {
132 const std::vector<long long int>* wayNext =
nullptr;
133 if (waysIdsIt != (waysIds.end() - 1)) {
136 if (wayPrev ==
nullptr && wayNext ==
nullptr) {
140 const long long int wayEnds = way->back();
141 const long long int wayBegins = way->front();
142 const long long int wayPrevEnds = wayPrev !=
nullptr ? wayPrev->back() : 0;
143 const long long int wayPrevBegins = wayPrev !=
nullptr ? wayPrev->front() : 0;
144 const long long int wayNextEnds = wayNext !=
nullptr ? wayNext->back() : 0;
145 const long long int wayNextBegins = wayNext !=
nullptr ? wayNext->front() : 0;
146 if (wayBegins == wayPrevEnds || wayBegins == wayPrevBegins || wayEnds == wayNextBegins || wayEnds == wayNextEnds) {
148 }
else if (wayEnds == wayPrevBegins || wayEnds == wayPrevEnds || wayBegins == wayNextEnds || wayBegins == wayNextBegins) {
155 std::string edgeId = stop->getEdgeId();
157 int assignedTo = edgeId.at(0) ==
'-' ?
BWD :
FWD;
159 if (dir != assignedTo) {
161 if (reverse ==
nullptr) {
162 WRITE_WARNINGF(
TL(
"Could not re-assign PT stop '%', probably broken osm file."), stop->getID());
165 if (stop->getLines().size() > 0) {
166 std::shared_ptr<NBPTStop> reverseStop = sc.
getReverseStop(stop, ec);
173 stop->setEdgeId(reverse->
getID(), ec);
175 stop->addLine(line->
getRef());
181 const std::vector<std::string>& waysIds = line->
getWays();
182 for (std::shared_ptr<NBPTStop> stop : line->
getStops()) {
184 stop =
findWay(line, stop, ec, sc);
185 if (stop ==
nullptr) {
189 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
190 if (waysIdsIt == waysIds.end()) {
194 stop->addLine(line->
getRef());
199std::shared_ptr<NBPTStop>
201 const std::vector<std::string>& waysIds = line->
getWays();
204 std::cout <<
" stop=" << stop->getID() <<
" line=" << line->
getLineID() <<
" edgeID=" << stop->getEdgeId() <<
" origID=" << stop->getOrigEdgeId() <<
"\n";
207 if (stop->isLoose()) {
209 double minDist = std::numeric_limits<double>::max();
213 if (dist < minDist) {
221 <<
" found=" << (std::find(waysIds.begin(), waysIds.end(),
getWayID(best->
getID())) != waysIds.end())
222 <<
" wayIDs=" <<
toString(waysIds) <<
"\n";
227 if (stop->getEdgeId() ==
"") {
228 stop->setEdgeId(best->
getID(), ec);
229 stop->setOrigEdgeId(wayID);
230 }
else if (stop->getEdgeId() != best->
getID()) {
233 std::shared_ptr<NBPTStop> newStop = sc.
findStop(wayID, stop->getPosition());
234 if (newStop ==
nullptr) {
235 newStop = std::make_shared<NBPTStop>(stop->getID() +
"@" + line->
getLineID(), stop->getPosition(), best->
getID(), wayID, stop->getLength(), stop->getName(), stop->getPermissions());
236 newStop->setEdgeId(best->
getID(), ec);
243 WRITE_WARNINGF(
TL(
"Could not assign stop '%' to pt line '%' (closest edge '%', distance %). Ignoring!"),
249 auto waysIdsIt = waysIds.begin();
250 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
251 if ((*waysIdsIt) == stop->getOrigEdgeId()) {
256 if (waysIdsIt == waysIds.end()) {
258 for (
auto& edgeCand : stop->getAdditionalEdgeCandidates()) {
260 waysIdsIt = waysIds.begin();
261 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
262 if ((*waysIdsIt) == edgeCand.first) {
263 if (stop->setEdgeId(edgeCand.second, ec)) {
264 stop->setOrigEdgeId(edgeCand.first);
274 if (waysIdsIt == waysIds.end()) {
275 WRITE_WARNINGF(
TL(
"Cannot assign stop % on edge '%' to pt line '%'. Ignoring!"), stop->getID(), stop->getOrigEdgeId(), line->
getLineID());
284 std::vector<NBEdge*> edges;
288 std::vector<NBEdge*> prevWayEdges;
289 std::vector<NBEdge*> prevWayMinusEdges;
290 prevWayEdges.clear();
291 prevWayMinusEdges.clear();
292 std::vector<NBEdge*> currentWayEdges;
293 std::vector<NBEdge*> currentWayMinusEdges;
294 for (
auto it3 = pTLine->
getWays().begin(); it3 != pTLine->
getWays().end(); it3++) {
296 if (cont.
retrieve(*it3,
false) !=
nullptr) {
297 currentWayEdges.push_back(cont.
retrieve(*it3,
false));
308 if (cont.
retrieve(
"-" + *it3,
false) !=
nullptr) {
309 currentWayMinusEdges.push_back(cont.
retrieve(
"-" + *it3,
false));
314 currentWayMinusEdges.insert(currentWayMinusEdges.begin(),
320#ifdef DEBUG_CONSTRUCT_ROUTE
322 std::cout <<
" way=" << (*it3)
326 <<
" +=" <<
toString(currentWayEdges)
327 <<
" -=" <<
toString(currentWayMinusEdges)
331 if (currentWayEdges.empty()) {
334 if (last == currentWayEdges.front()->getFromNode() && last !=
nullptr) {
335 if (!prevWayEdges.empty()) {
336 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
337 prevWayEdges.clear();
338 prevWayMinusEdges.clear();
340 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
341 last = currentWayEdges.back()->getToNode();
342 }
else if (last == currentWayEdges.back()->getToNode() && last !=
nullptr) {
343 if (!prevWayEdges.empty()) {
344 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
345 prevWayEdges.clear();
346 prevWayMinusEdges.clear();
348 if (currentWayMinusEdges.empty()) {
349 currentWayEdges.clear();
353 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
354 last = currentWayMinusEdges.back()->getToNode();
356 }
else if (first == currentWayEdges.front()->getFromNode() && first !=
nullptr) {
357 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
358 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
359 last = currentWayEdges.back()->getToNode();
360 prevWayEdges.clear();
361 prevWayMinusEdges.clear();
362 }
else if (first == currentWayEdges.back()->getToNode() && first !=
nullptr) {
363 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
364 if (currentWayMinusEdges.empty()) {
365 currentWayEdges.clear();
367 prevWayEdges.clear();
368 prevWayMinusEdges.clear();
371 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
372 last = currentWayMinusEdges.back()->getToNode();
373 prevWayEdges.clear();
374 prevWayMinusEdges.clear();
377 if (it3 != pTLine->
getWays().begin()) {
378#ifdef DEBUG_CONSTRUCT_ROUTE
380 std::cout <<
" way " << (*it3)
381 <<
" is not the start of ptline " << pTLine->
getLineID()
382 <<
" (" + pTLine->
getName() +
")\n";
385 }
else if (pTLine->
getWays().size() == 1) {
386 if (currentWayEdges.size() > 0) {
387 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
389 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
392 prevWayEdges = currentWayEdges;
393 prevWayMinusEdges = currentWayMinusEdges;
394 if (!prevWayEdges.empty()) {
395 first = prevWayEdges.front()->getFromNode();
396 last = prevWayEdges.back()->getToNode();
402 currentWayEdges.clear();
403 currentWayMinusEdges.clear();
415 for (
const NBEdge* e : item.second->getRoute()) {
421 line->replaceEdge(edgeID, replacement);
422 for (
const NBEdge* e : replacement) {
430std::set<std::string>&
438 std::map<std::string, SUMOVehicleClass> types;
453 std::vector<std::shared_ptr<NBPTStop> > stops = line->
getStops();
454 if (stops.size() < 2) {
457 if (types.count(line->
getType()) == 0) {
458 WRITE_WARNINGF(
TL(
"Could not determine vehicle class for public transport line of type '%'."), line->
getType());
462 std::vector<std::shared_ptr<NBPTStop> > newStops;
463 std::shared_ptr<NBPTStop> from =
nullptr;
464 for (
auto it = stops.begin(); it != stops.end(); ++it) {
465 std::shared_ptr<NBPTStop> to = *it;
466 std::shared_ptr<NBPTStop> used = *it;
467 if (to->getBidiStop() !=
nullptr) {
468 double best = std::numeric_limits<double>::max();
469 std::shared_ptr<NBPTStop> to2 = to->getBidiStop();
470 if (from ==
nullptr) {
471 if ((it + 1) != stops.end()) {
473 std::shared_ptr<NBPTStop> from2 = to2;
475 const double c1 =
getCost(ec, *router, from, to, &veh);
476 const double c2 =
getCost(ec, *router, from2, to, &veh);
480 if (to->getBidiStop() !=
nullptr) {
481 to2 = to->getBidiStop();
482 const double c3 =
getCost(ec, *router, from, to2, &veh);
483 const double c4 =
getCost(ec, *router, from2, to2, &veh);
508 const double c1 =
getCost(ec, *router, from, to, &veh);
509 const double c2 =
getCost(ec, *router, from, to2, &veh);
520 if (best < std::numeric_limits<double>::max()) {
527 newStops.push_back(used);
529 assert(stops.size() == newStops.size());
539 item.second->removeInvalidEdges(ec);
548 const std::vector<NBEdge*>& route = line->
getRoute();
550 for (
int i = 1; i < (int)route.size(); i++) {
551 NBEdge* e1 = route[i - 1];
554 if (cons.size() == 0) {
558 for (
const auto& c : cons) {
565 int lane = cons[0].fromLane;
576 const std::shared_ptr<NBPTStop> from,
const std::shared_ptr<NBPTStop> to,
const NBVehicle* veh) {
579 if (fromEdge ==
nullptr || toEdge ==
nullptr) {
580 return std::numeric_limits<double>::max();
581 }
else if (fromEdge == toEdge) {
582 if (from->getEndPos() <= to->getEndPos()) {
583 return to->getEndPos() - from->getEndPos();
585 return std::numeric_limits<double>::max();
588 return std::numeric_limits<double>::max();
590 std::vector<const NBRouterEdge*> route;
591 router.
compute(fromEdge, toEdge, veh, 0, route);
592 if (route.size() == 0) {
593 return std::numeric_limits<double>::max();
602 std::size_t found = edgeID.rfind(
"#");
603 std::string result = edgeID;
604 if (found != std::string::npos) {
605 result = edgeID.substr(0, found);
607 if (result[0] ==
'-') {
608 result = result.substr(1);
#define WRITE_WARNINGF(...)
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
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, 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)
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...
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values