38#define DEBUGLINEID "1986097"
55 delete myPTLine.second;
71 if (item.second->getWays().size() > 0) {
91 const std::vector<std::string>& waysIds = line->
getWays();
92 if (waysIds.size() == 1 && line->
getStops().size() > 1) {
96 if (waysIds.size() <= 1) {
97 WRITE_WARNINGF(
TL(
"Cannot revise pt stop localization for pt line '%', which consist of one way only. Ignoring!"), line->
getLineID());
101 WRITE_WARNINGF(
TL(
"Cannot revise pt stop localization for pt line '%', which has no route edges. Ignoring!"), line->
getLineID());
104 std::vector<NBPTStop*> stops = line->
getStops();
107 stop =
findWay(line, stop, ec, sc);
108 if (stop ==
nullptr) {
112 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
113 if (waysIdsIt == waysIds.end()) {
118 std::vector<long long int>* way = line->
getWaysNodes(stop->getOrigEdgeId());
119 if (way ==
nullptr) {
120 WRITE_WARNINGF(
TL(
"Cannot assign stop '%' on edge '%' to pt line '%' (wayNodes not found). Ignoring!"),
121 stop->getID(), stop->getOrigEdgeId(), line->
getLineID());
127 std::string adjIdPrev;
128 std::string adjIdNext;
129 if (waysIdsIt != waysIds.begin()) {
130 adjIdPrev = *(waysIdsIt - 1);
132 if (waysIdsIt != (waysIds.end() - 1)) {
133 adjIdNext = *(waysIdsIt + 1);
135 std::vector<long long int>* wayPrev = line->
getWaysNodes(adjIdPrev);
136 std::vector<long long int>* wayNext = line->
getWaysNodes(adjIdNext);
137 if (wayPrev ==
nullptr && wayNext ==
nullptr) {
141 long long int wayEnds = *(way->end() - 1);
142 long long int wayBegins = *(way->begin());
143 long long int wayPrevEnds = wayPrev !=
nullptr ? *(wayPrev->end() - 1) : 0;
144 long long int wayPrevBegins = wayPrev !=
nullptr ? *(wayPrev->begin()) : 0;
145 long long int wayNextEnds = wayNext !=
nullptr ? *(wayNext->end() - 1) : 0;
146 long long int wayNextBegins = wayNext !=
nullptr ? *(wayNext->begin()) : 0;
147 if (wayBegins == wayPrevEnds || wayBegins == wayPrevBegins || wayEnds == wayNextBegins
148 || wayEnds == wayNextEnds) {
150 }
else if (wayEnds == wayPrevBegins || wayEnds == wayPrevEnds || wayBegins == wayNextEnds
151 || wayBegins == wayNextBegins) {
158 std::string edgeId = stop->getEdgeId();
160 int assignedTo = edgeId.at(0) ==
'-' ?
BWD :
FWD;
162 if (dir != assignedTo) {
164 if (reverse ==
nullptr) {
165 WRITE_WARNINGF(
TL(
"Could not re-assign PT stop '%', probably broken osm file."), stop->getID());
168 if (stop->getLines().size() > 0) {
176 stop->setEdgeId(reverse->
getID(), ec);
178 stop->addLine(line->
getRef());
184 const std::vector<std::string>& waysIds = line->
getWays();
187 stop =
findWay(line, stop, ec, sc);
188 if (stop ==
nullptr) {
192 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
193 if (waysIdsIt == waysIds.end()) {
197 stop->addLine(line->
getRef());
204 const std::vector<std::string>& waysIds = line->
getWays();
212 double minDist = std::numeric_limits<double>::max();
216 if (dist < minDist) {
224 <<
" found=" << (std::find(waysIds.begin(), waysIds.end(),
getWayID(best->
getID())) != waysIds.end())
225 <<
" wayIDs=" <<
toString(waysIds) <<
"\n";
237 if (newStop ==
nullptr) {
246 WRITE_WARNINGF(
TL(
"Could not assign stop '%' to pt line '%' (closest edge '%', distance %). Ignoring!"),
252 auto waysIdsIt = waysIds.begin();
253 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
259 if (waysIdsIt == waysIds.end()) {
263 waysIdsIt = waysIds.begin();
264 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
265 if ((*waysIdsIt) == edgeCand.first) {
266 if (stop->
setEdgeId(edgeCand.second, ec)) {
277 if (waysIdsIt == waysIds.end()) {
287 std::vector<NBEdge*> edges;
291 std::vector<NBEdge*> prevWayEdges;
292 std::vector<NBEdge*> prevWayMinusEdges;
293 prevWayEdges.clear();
294 prevWayMinusEdges.clear();
295 std::vector<NBEdge*> currentWayEdges;
296 std::vector<NBEdge*> currentWayMinusEdges;
297 for (
auto it3 = pTLine->
getWays().begin(); it3 != pTLine->
getWays().end(); it3++) {
299 if (cont.
retrieve(*it3,
false) !=
nullptr) {
300 currentWayEdges.push_back(cont.
retrieve(*it3,
false));
311 if (cont.
retrieve(
"-" + *it3,
false) !=
nullptr) {
312 currentWayMinusEdges.push_back(cont.
retrieve(
"-" + *it3,
false));
317 currentWayMinusEdges.insert(currentWayMinusEdges.begin(),
323#ifdef DEBUG_CONSTRUCT_ROUTE
325 std::cout <<
" way=" << (*it3)
329 <<
" +=" <<
toString(currentWayEdges)
330 <<
" -=" <<
toString(currentWayMinusEdges)
334 if (currentWayEdges.empty()) {
337 if (last == currentWayEdges.front()->getFromNode() && last !=
nullptr) {
338 if (!prevWayEdges.empty()) {
339 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
340 prevWayEdges.clear();
341 prevWayMinusEdges.clear();
343 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
344 last = currentWayEdges.back()->getToNode();
345 }
else if (last == currentWayEdges.back()->getToNode() && last !=
nullptr) {
346 if (!prevWayEdges.empty()) {
347 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
348 prevWayEdges.clear();
349 prevWayMinusEdges.clear();
351 if (currentWayMinusEdges.empty()) {
352 currentWayEdges.clear();
356 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
357 last = currentWayMinusEdges.back()->getToNode();
359 }
else if (first == currentWayEdges.front()->getFromNode() && first !=
nullptr) {
360 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
361 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
362 last = currentWayEdges.back()->getToNode();
363 prevWayEdges.clear();
364 prevWayMinusEdges.clear();
365 }
else if (first == currentWayEdges.back()->getToNode() && first !=
nullptr) {
366 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
367 if (currentWayMinusEdges.empty()) {
368 currentWayEdges.clear();
370 prevWayEdges.clear();
371 prevWayMinusEdges.clear();
374 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
375 last = currentWayMinusEdges.back()->getToNode();
376 prevWayEdges.clear();
377 prevWayMinusEdges.clear();
380 if (it3 != pTLine->
getWays().begin()) {
381#ifdef DEBUG_CONSTRUCT_ROUTE
383 std::cout <<
" way " << (*it3)
384 <<
" is not the start of ptline " << pTLine->
getLineID()
385 <<
" (" + pTLine->
getName() +
")\n";
388 }
else if (pTLine->
getWays().size() == 1) {
389 if (currentWayEdges.size() > 0) {
390 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
392 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
395 prevWayEdges = currentWayEdges;
396 prevWayMinusEdges = currentWayMinusEdges;
397 if (!prevWayEdges.empty()) {
398 first = prevWayEdges.front()->getFromNode();
399 last = prevWayEdges.back()->getToNode();
405 currentWayEdges.clear();
406 currentWayMinusEdges.clear();
418 for (
const NBEdge* e : item.second->getRoute()) {
424 line->replaceEdge(edgeID, replacement);
425 for (
const NBEdge* e : replacement) {
433std::set<std::string>&
441 std::map<std::string, SUMOVehicleClass> types;
456 std::vector<NBPTStop*> stops = line->
getStops();
457 if (stops.size() < 2) {
460 if (types.count(line->
getType()) == 0) {
461 WRITE_WARNINGF(
TL(
"Could not determine vehicle class for public transport line of type '%'."), line->
getType());
465 std::vector<NBPTStop*> newStops;
467 for (
auto it = stops.begin(); it != stops.end(); ++it) {
471 double best = std::numeric_limits<double>::max();
473 if (from ==
nullptr) {
474 if ((it + 1) != stops.end()) {
478 const double c1 =
getCost(ec, *router, from, to, &veh);
479 const double c2 =
getCost(ec, *router, from2, to, &veh);
485 const double c3 =
getCost(ec, *router, from, to2, &veh);
486 const double c4 =
getCost(ec, *router, from2, to2, &veh);
511 const double c1 =
getCost(ec, *router, from, to, &veh);
512 const double c2 =
getCost(ec, *router, from, to2, &veh);
523 if (best < std::numeric_limits<double>::max()) {
530 newStops.push_back(used);
532 assert(stops.size() == newStops.size());
542 item.second->removeInvalidEdges(ec);
551 const std::vector<NBEdge*>& route = line->
getRoute();
553 for (
int i = 1; i < (int)route.size(); i++) {
554 NBEdge* e1 = route[i - 1];
557 if (cons.size() == 0) {
561 for (
const auto& c : cons) {
568 int lane = cons[0].fromLane;
581 if (fromEdge ==
nullptr || toEdge ==
nullptr) {
582 return std::numeric_limits<double>::max();
583 }
else if (fromEdge == toEdge) {
587 return std::numeric_limits<double>::max();
590 return std::numeric_limits<double>::max();
592 std::vector<const NBRouterEdge*> route;
593 router.
compute(fromEdge, toEdge, veh, 0, route);
594 if (route.size() == 0) {
595 return std::numeric_limits<double>::max();
604 std::size_t found = edgeID.rfind(
"#");
605 std::string result = edgeID;
606 if (found != std::string::npos) {
607 result = edgeID.substr(0, found);
609 if (result[0] ==
'-') {
610 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
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.
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
~NBPTLineCont()
destructor
std::map< std::string, NBPTLine * > myPTLines
The map of names to pt lines.
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 constructRoute(NBPTLine *myPTLine, const NBEdgeCont &cont)
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
void insert(NBPTLine *ptLine)
insert new line
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 deleteInvalidStops(const NBEdgeCont &ec, const NBPTStopCont &sc)
remove invalid stops from the line
void replaceStops(std::vector< NBPTStop * > stops)
const std::vector< NBPTStop * > & getStops()
const std::string & getName() const
const std::string & getLineID() const
std::vector< long long int > * getWaysNodes(std::string wayId)
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
void replaceStop(NBPTStop *oldStop, NBPTStop *newStop)
replace the given stop
void setEdges(const std::vector< NBEdge * > &edges)
bool insert(NBPTStop *ptStop, bool floating=false)
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.
const std::map< std::string, std::string > & getAdditionalEdgeCandidates() const
bool setEdgeId(std::string edgeId, const NBEdgeCont &ec)
void setOrigEdgeId(const std::string &origEdgeId)
std::string getID() const
SVCPermissions getPermissions() const
const std::string & getEdgeId() const
const Position & getPosition() const
NBPTStop * getBidiStop() const
const std::string getOrigEdgeId() const
const std::string getName() const
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