35 #define DEBUGSTOPID ""
51 delete myPTLine.second;
63 if (item.second->getMyWays().size() > 0) {
75 const std::vector<std::string>& waysIds = line->
getMyWays();
76 if (waysIds.size() == 1 && line->
getStops().size() > 1) {
80 if (waysIds.size() <= 1) {
81 WRITE_WARNING(
"Cannot revise pt stop localization for pt line: " + line->
getLineID() +
", which consist of one way only. Ignoring!");
85 WRITE_WARNING(
"Cannot revise pt stop localization for pt line: " + line->
getLineID() +
", which has no route edges. Ignoring!");
88 std::vector<NBPTStop*> stops = line->
getStops();
91 stop =
findWay(line, stop, ec, sc);
92 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
93 if (waysIdsIt == waysIds.end()) {
98 std::vector<long long int>* way = line->
getWaysNodes(stop->getOrigEdgeId());
100 WRITE_WARNING(
"Cannot assign stop '" + stop->getID() +
"' on edge '" + stop->getOrigEdgeId() +
"' to pt line '" + line->
getLineID() +
"' (wayNodes not found). Ignoring!");
106 std::string adjIdPrev;
107 std::string adjIdNext;
108 if (waysIdsIt != waysIds.begin()) {
109 adjIdPrev = *(waysIdsIt - 1);
111 if (waysIdsIt != (waysIds.end() - 1)) {
112 adjIdNext = *(waysIdsIt + 1);
114 std::vector<long long int>* wayPrev = line->
getWaysNodes(adjIdPrev);
115 std::vector<long long int>* wayNext = line->
getWaysNodes(adjIdNext);
116 if (wayPrev ==
nullptr && wayNext ==
nullptr) {
121 long long int wayEnds = *(way->end() - 1);
122 long long int wayBegins = *(way->begin());
123 long long int wayPrevEnds = wayPrev !=
nullptr ? *(wayPrev->end() - 1) : 0;
124 long long int wayPrevBegins = wayPrev !=
nullptr ? *(wayPrev->begin()) : 0;
125 long long int wayNextEnds = wayNext !=
nullptr ? *(wayNext->end() - 1) : 0;
126 long long int wayNextBegins = wayNext !=
nullptr ? *(wayNext->begin()) : 0;
127 if (wayBegins == wayPrevEnds || wayBegins == wayPrevBegins || wayEnds == wayNextBegins
128 || wayEnds == wayNextEnds) {
130 }
else if (wayEnds == wayPrevBegins || wayEnds == wayPrevEnds || wayBegins == wayNextEnds
131 || wayBegins == wayNextBegins) {
139 std::string edgeId = stop->getEdgeId();
141 int assignedTo = edgeId.at(0) ==
'-' ?
BWD :
FWD;
143 if (dir != assignedTo) {
145 if (reverse ==
nullptr) {
146 WRITE_WARNING(
"Could not re-assign PT stop: " + stop->getID() +
" probably broken osm file");
149 stop->setEdgeId(reverse->
getID(), ec);
150 WRITE_WARNING(
"PT stop: " + stop->getID() +
" has been moved to edge: " + reverse->
getID());
153 stop->addLine(line->
getRef());
159 const std::vector<std::string>& waysIds = line->
getMyWays();
162 stop =
findWay(line, stop, ec, sc);
163 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
164 if (waysIdsIt == waysIds.end()) {
169 stop->addLine(line->
getRef());
176 const std::vector<std::string>& waysIds = line->
getMyWays();
177 #ifdef DEBUG_FIND_WAY
184 double minDist = std::numeric_limits<double>::max();
188 if (dist < minDist) {
193 #ifdef DEBUG_FIND_WAY
196 <<
" found=" << (std::find(waysIds.begin(), waysIds.end(),
getWayID(best->
getID())) != waysIds.end())
197 <<
" wayIDs=" <<
toString(waysIds) <<
"\n";
209 if (newStop ==
nullptr) {
223 auto waysIdsIt = waysIds.begin();
224 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
230 if (waysIdsIt == waysIds.end()) {
234 waysIdsIt = waysIds.begin();
235 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
236 if ((*waysIdsIt) == edgeCand.first) {
237 if (stop->
setEdgeId(edgeCand.second, ec)) {
248 if (waysIdsIt == waysIds.end()) {
258 std::vector<NBEdge*> edges;
262 std::vector<NBEdge*> prevWayEdges;
263 std::vector<NBEdge*> prevWayMinusEdges;
264 prevWayEdges.clear();
265 prevWayMinusEdges.clear();
266 std::vector<NBEdge*> currentWayEdges;
267 std::vector<NBEdge*> currentWayMinusEdges;
268 for (
auto it3 = pTLine->
getMyWays().begin();
269 it3 != pTLine->
getMyWays().end(); it3++) {
271 if (cont.
retrieve(*it3,
false) !=
nullptr) {
272 currentWayEdges.push_back(cont.
retrieve(*it3,
false));
275 while (cont.
retrieve(*it3 +
"#" + std::to_string(i),
false) !=
nullptr) {
276 currentWayEdges.push_back(cont.
retrieve(*it3 +
"#" + std::to_string(i),
false));
281 if (cont.
retrieve(
"-" + *it3,
false) !=
nullptr) {
282 currentWayMinusEdges.push_back(cont.
retrieve(
"-" + *it3,
false));
285 while (cont.
retrieve(
"-" + *it3 +
"#" + std::to_string(i),
false) !=
nullptr) {
286 currentWayMinusEdges.insert(currentWayMinusEdges.begin(),
287 cont.
retrieve(
"-" + *it3 +
"#" + std::to_string(i),
false));
291 if (currentWayEdges.empty()) {
294 if (last == currentWayEdges.front()->getFromNode() && last !=
nullptr) {
295 if (!prevWayEdges.empty()) {
296 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
297 prevWayEdges.clear();
298 prevWayMinusEdges.clear();
300 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
301 last = currentWayEdges.back()->getToNode();
302 }
else if (last == currentWayEdges.back()->getToNode() && last !=
nullptr) {
303 if (!prevWayEdges.empty()) {
304 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
305 prevWayEdges.clear();
306 prevWayMinusEdges.clear();
308 if (currentWayMinusEdges.empty()) {
309 currentWayEdges.clear();
313 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
314 last = currentWayMinusEdges.back()->getToNode();
316 }
else if (first == currentWayEdges.front()->getFromNode() && first !=
nullptr) {
317 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
318 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
319 last = currentWayEdges.back()->getToNode();
320 prevWayEdges.clear();
321 prevWayMinusEdges.clear();
322 }
else if (first == currentWayEdges.back()->getToNode() && first !=
nullptr) {
323 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
324 if (currentWayMinusEdges.empty()) {
325 currentWayEdges.clear();
327 prevWayEdges.clear();
328 prevWayMinusEdges.clear();
331 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
332 last = currentWayMinusEdges.back()->getToNode();
333 prevWayEdges.clear();
334 prevWayMinusEdges.clear();
337 if (it3 != pTLine->
getMyWays().begin()) {
339 (pTLine->
getName() !=
"" ?
"' (" + pTLine->
getName() +
")" :
""));
340 }
else if (pTLine->
getMyWays().size() == 1) {
341 if (currentWayEdges.size() > 0) {
342 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
344 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
347 prevWayEdges = currentWayEdges;
348 prevWayMinusEdges = currentWayMinusEdges;
349 if (!prevWayEdges.empty()) {
350 first = prevWayEdges.front()->getFromNode();
351 last = prevWayEdges.back()->getToNode();
357 currentWayEdges.clear();
358 currentWayMinusEdges.clear();
366 if (oc.
isSet(
"ptline-output")) {
368 for (
auto edge : item.second->getRoute()) {
369 into.insert(edge->getID());
380 item.second->replaceEdge(edgeID, replacement);
385 std::set<std::string>&
393 std::map<std::string, SUMOVehicleClass> types;
406 std::vector<NBPTStop*> stops = line->
getStops();
407 if (stops.size() < 2) {
410 if (types.count(line->
getType()) == 0) {
411 WRITE_WARNING(
"Could not determine vehicle class for public transport line of type '"
416 std::vector<NBPTStop*> newStops;
418 for (
auto it = stops.begin(); it != stops.end(); ++it) {
422 double best = std::numeric_limits<double>::max();
424 if (from ==
nullptr) {
425 if ((it + 1) != stops.end()) {
429 const double c1 =
getCost(ec, *router, from, to, &veh);
430 const double c2 =
getCost(ec, *router, from2, to, &veh);
436 const double c3 =
getCost(ec, *router, from, to2, &veh);
437 const double c4 =
getCost(ec, *router, from2, to2, &veh);
462 const double c1 =
getCost(ec, *router, from, to, &veh);
463 const double c2 =
getCost(ec, *router, from, to2, &veh);
474 if (best < std::numeric_limits<double>::max()) {
481 newStops.push_back(used);
483 assert(stops.size() == newStops.size());
495 if (fromEdge ==
nullptr || toEdge ==
nullptr) {
496 return std::numeric_limits<double>::max();
497 }
else if (fromEdge == toEdge) {
501 return std::numeric_limits<double>::max();
504 std::vector<const NBRouterEdge*> route;
505 router.
compute(fromEdge, toEdge, veh, 0, route);
506 if (route.size() == 0) {
507 return std::numeric_limits<double>::max();
516 std::size_t found = edgeID.rfind(
"#");
517 std::string result = edgeID;
518 if (found != std::string::npos) {
519 result = edgeID.substr(0, found);
521 if (result[0] ==
'-') {
522 result = result.substr(1);
#define WRITE_WARNING(msg)
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
@ 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.
const std::string & getID() 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
static double getCost(const NBEdgeCont &ec, SUMOAbstractRouter< NBRouterEdge, NBVehicle > &router, const NBPTStop *from, const NBPTStop *to, const NBVehicle *veh)
std::set< std::string > myServedPTStops
~NBPTLineCont()
destructor
std::map< std::string, NBPTLine * > myPTLines
The map of names to pt lines.
void constructRoute(NBPTLine *myPTLine, NBEdgeCont &cont)
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 process(NBEdgeCont &ec, NBPTStopCont &sc)
void addEdges2Keep(const OptionsCont &oc, std::set< std::string > &into)
add edges that must be kept
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)
void replaceStops(std::vector< NBPTStop * > stops)
const std::vector< std::string > & getMyWays() const
const std::string & getLineID() const
const std::string & getType() const
std::vector< long long int > * getWaysNodes(std::string wayId)
const std::vector< NBEdge * > & getRoute() const
const std::string & getName() const
const std::string & getRef() const
get line reference (not unique)
void replaceStop(NBPTStop *oldStop, NBPTStop *newStop)
replace the given stop
std::vector< NBPTStop * > getStops()
void setEdges(const std::vector< NBEdge * > &edges)
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
The representation of a single pt stop.
bool setEdgeId(std::string edgeId, const NBEdgeCont &ec)
const std::string getEdgeId() const
std::string getID() const
void setMyOrigEdgeId(const std::string &myOrigEdgeId)
NBPTStop * getBidiStop() const
SVCPermissions getPermissions() const
const std::map< std::string, std::string > & getMyAdditionalEdgeCandidates() const
const Position & getPosition() 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
A storage for options typed value containers)
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.
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...