37 #define DEBUGLINEID "1986097"
38 #define DEBUGSTOPID ""
54 delete myPTLine.second;
65 const bool silent = routeOnly;
68 if (item.second->getMyWays().size() > 0) {
87 const std::vector<std::string>& waysIds = line->
getMyWays();
88 if (waysIds.size() == 1 && line->
getStops().size() > 1) {
92 if (waysIds.size() <= 1) {
93 WRITE_WARNINGF(
"Cannot revise pt stop localization for pt line '%', which consist of one way only. Ignoring!", line->
getLineID());
97 WRITE_WARNINGF(
"Cannot revise pt stop localization for pt line '%', which has no route edges. Ignoring!", line->
getLineID());
100 std::vector<NBPTStop*> stops = line->
getStops();
103 stop =
findWay(line, stop, ec, sc);
104 if (stop ==
nullptr) {
108 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
109 if (waysIdsIt == waysIds.end()) {
114 std::vector<long long int>* way = line->
getWaysNodes(stop->getOrigEdgeId());
115 if (way ==
nullptr) {
116 WRITE_WARNINGF(
"Cannot assign stop '%' on edge '%' to pt line '%' (wayNodes not found). Ignoring!",
117 stop->getID(), stop->getOrigEdgeId(), line->
getLineID());
123 std::string adjIdPrev;
124 std::string adjIdNext;
125 if (waysIdsIt != waysIds.begin()) {
126 adjIdPrev = *(waysIdsIt - 1);
128 if (waysIdsIt != (waysIds.end() - 1)) {
129 adjIdNext = *(waysIdsIt + 1);
131 std::vector<long long int>* wayPrev = line->
getWaysNodes(adjIdPrev);
132 std::vector<long long int>* wayNext = line->
getWaysNodes(adjIdNext);
133 if (wayPrev ==
nullptr && wayNext ==
nullptr) {
137 long long int wayEnds = *(way->end() - 1);
138 long long int wayBegins = *(way->begin());
139 long long int wayPrevEnds = wayPrev !=
nullptr ? *(wayPrev->end() - 1) : 0;
140 long long int wayPrevBegins = wayPrev !=
nullptr ? *(wayPrev->begin()) : 0;
141 long long int wayNextEnds = wayNext !=
nullptr ? *(wayNext->end() - 1) : 0;
142 long long int wayNextBegins = wayNext !=
nullptr ? *(wayNext->begin()) : 0;
143 if (wayBegins == wayPrevEnds || wayBegins == wayPrevBegins || wayEnds == wayNextBegins
144 || wayEnds == wayNextEnds) {
146 }
else if (wayEnds == wayPrevBegins || wayEnds == wayPrevEnds || wayBegins == wayNextEnds
147 || wayBegins == wayNextBegins) {
154 std::string edgeId = stop->getEdgeId();
156 int assignedTo = edgeId.at(0) ==
'-' ?
BWD :
FWD;
158 if (dir != assignedTo) {
160 if (reverse ==
nullptr) {
161 WRITE_WARNINGF(
"Could not re-assign PT stop '%', probably broken osm file.", stop->getID());
164 if (stop->getLines().size() > 0) {
170 WRITE_WARNINGF(
"PT stop '%' has been moved to edge '%'.", stop->getID(), reverse->
getID());
172 stop->setEdgeId(reverse->
getID(), ec);
174 stop->addLine(line->
getRef());
180 const std::vector<std::string>& waysIds = line->
getMyWays();
183 stop =
findWay(line, stop, ec, sc);
184 if (stop ==
nullptr) {
188 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
189 if (waysIdsIt == waysIds.end()) {
193 stop->addLine(line->
getRef());
200 const std::vector<std::string>& waysIds = line->
getMyWays();
201 #ifdef DEBUG_FIND_WAY
208 double minDist = std::numeric_limits<double>::max();
212 if (dist < minDist) {
217 #ifdef DEBUG_FIND_WAY
220 <<
" found=" << (std::find(waysIds.begin(), waysIds.end(),
getWayID(best->
getID())) != waysIds.end())
221 <<
" wayIDs=" <<
toString(waysIds) <<
"\n";
233 if (newStop ==
nullptr) {
242 WRITE_WARNINGF(
"Could not assign stop '%' to pt line '%' (closest edge '%', distance %). Ignoring!",
248 auto waysIdsIt = waysIds.begin();
249 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
255 if (waysIdsIt == waysIds.end()) {
259 waysIdsIt = waysIds.begin();
260 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
261 if ((*waysIdsIt) == edgeCand.first) {
262 if (stop->
setEdgeId(edgeCand.second, ec)) {
273 if (waysIdsIt == waysIds.end()) {
283 std::vector<NBEdge*> edges;
287 std::vector<NBEdge*> prevWayEdges;
288 std::vector<NBEdge*> prevWayMinusEdges;
289 prevWayEdges.clear();
290 prevWayMinusEdges.clear();
291 std::vector<NBEdge*> currentWayEdges;
292 std::vector<NBEdge*> currentWayMinusEdges;
293 for (
auto it3 = pTLine->
getMyWays().begin();
294 it3 != pTLine->
getMyWays().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()) {
332 #ifdef DEBUG_CONSTRUCT_ROUTE
334 std::cout <<
" if0\n";
339 if (last == currentWayEdges.front()->getFromNode() && last !=
nullptr) {
340 #ifdef DEBUG_CONSTRUCT_ROUTE
342 std::cout <<
" if1\n";
345 if (!prevWayEdges.empty()) {
346 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
347 prevWayEdges.clear();
348 prevWayMinusEdges.clear();
350 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
351 last = currentWayEdges.back()->getToNode();
352 }
else if (last == currentWayEdges.back()->getToNode() && last !=
nullptr) {
353 #ifdef DEBUG_CONSTRUCT_ROUTE
355 std::cout <<
" if2\n";
358 if (!prevWayEdges.empty()) {
359 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
360 prevWayEdges.clear();
361 prevWayMinusEdges.clear();
363 if (currentWayMinusEdges.empty()) {
364 currentWayEdges.clear();
366 #ifdef DEBUG_CONSTRUCT_ROUTE
368 std::cout <<
" continue1\n";
373 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
374 last = currentWayMinusEdges.back()->getToNode();
376 }
else if (first == currentWayEdges.front()->getFromNode() && first !=
nullptr) {
377 #ifdef DEBUG_CONSTRUCT_ROUTE
379 std::cout <<
" if3\n";
382 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
383 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
384 last = currentWayEdges.back()->getToNode();
385 prevWayEdges.clear();
386 prevWayMinusEdges.clear();
387 }
else if (first == currentWayEdges.back()->getToNode() && first !=
nullptr) {
388 #ifdef DEBUG_CONSTRUCT_ROUTE
390 std::cout <<
" if4\n";
393 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
394 if (currentWayMinusEdges.empty()) {
395 currentWayEdges.clear();
397 prevWayEdges.clear();
398 prevWayMinusEdges.clear();
399 #ifdef DEBUG_CONSTRUCT_ROUTE
401 std::cout <<
" continue2\n";
406 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
407 last = currentWayMinusEdges.back()->getToNode();
408 prevWayEdges.clear();
409 prevWayMinusEdges.clear();
412 #ifdef DEBUG_CONSTRUCT_ROUTE
414 std::cout <<
" if5\n";
417 if (it3 != pTLine->
getMyWays().begin()) {
422 }
else if (pTLine->
getMyWays().size() == 1) {
423 if (currentWayEdges.size() > 0) {
424 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
426 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
429 prevWayEdges = currentWayEdges;
430 prevWayMinusEdges = currentWayMinusEdges;
431 if (!prevWayEdges.empty()) {
432 first = prevWayEdges.front()->getFromNode();
433 last = prevWayEdges.back()->getToNode();
439 currentWayEdges.clear();
440 currentWayMinusEdges.clear();
448 if (oc.
isSet(
"ptline-output")) {
450 for (
auto edge : item.second->getRoute()) {
451 into.insert(edge->getID());
464 for (
const NBEdge* e : item.second->getRoute()) {
470 line->replaceEdge(edgeID, replacement);
471 for (
const NBEdge* e : replacement) {
479 std::set<std::string>&
487 std::map<std::string, SUMOVehicleClass> types;
500 std::vector<NBPTStop*> stops = line->
getStops();
501 if (stops.size() < 2) {
504 if (types.count(line->
getType()) == 0) {
505 WRITE_WARNINGF(
"Could not determine vehicle class for public transport line of type '%'.", line->
getType());
509 std::vector<NBPTStop*> newStops;
511 for (
auto it = stops.begin(); it != stops.end(); ++it) {
515 double best = std::numeric_limits<double>::max();
517 if (from ==
nullptr) {
518 if ((it + 1) != stops.end()) {
522 const double c1 =
getCost(ec, *router, from, to, &veh);
523 const double c2 =
getCost(ec, *router, from2, to, &veh);
529 const double c3 =
getCost(ec, *router, from, to2, &veh);
530 const double c4 =
getCost(ec, *router, from2, to2, &veh);
555 const double c1 =
getCost(ec, *router, from, to, &veh);
556 const double c2 =
getCost(ec, *router, from, to2, &veh);
567 if (best < std::numeric_limits<double>::max()) {
574 newStops.push_back(used);
576 assert(stops.size() == newStops.size());
586 item.second->removeInvalidEdges(ec);
595 const std::vector<NBEdge*>& route = line->
getRoute();
597 for (
int i = 1; i < (int)route.size(); i++) {
598 NBEdge* e1 = route[i - 1];
601 if (cons.size() == 0) {
605 for (
const auto& c : cons) {
612 int lane = cons[0].fromLane;
625 if (fromEdge ==
nullptr || toEdge ==
nullptr) {
626 return std::numeric_limits<double>::max();
627 }
else if (fromEdge == toEdge) {
631 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
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 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 addEdges2Keep(const OptionsCont &oc, std::set< std::string > &into)
add edges that must be kept
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
void constructRoute(NBPTLine *myPTLine, const NBEdgeCont &cont, bool silent=false)
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.
void deleteInvalidStops(const NBEdgeCont &ec, const NBPTStopCont &sc)
remove invalid stops from the line
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)
SUMOVehicleClass getVClass() const
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
NBPTStop * getReverseStop(NBPTStop *pStop, const NBEdgeCont &ec)
The representation of a single pt stop.
bool setEdgeId(std::string edgeId, const NBEdgeCont &ec)
const std::string getEdgeId() const
void setOrigEdgeId(const std::string &origEdgeId)
std::string getID() const
NBPTStop * getBidiStop() const
SVCPermissions getPermissions() const
const Position & getPosition() const
const std::map< std::string, std::string > & getAdditionalEdgeCandidates() 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...
std::string to_string(const std::vector< double > &value)