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());
115 const std::vector<std::string>& waysIds = line->
getWays();
116 if (waysIds.size() == 1 && line->
getStops().size() > 1) {
120 if (waysIds.size() <= 1) {
121 WRITE_WARNINGF(
TL(
"Cannot revise pt stop localization for pt line '%', which consist of one way only. Ignoring!"), line->
getLineID());
125 WRITE_WARNINGF(
TL(
"Cannot revise pt stop localization for pt line '%', which has no route edges. Ignoring!"), line->
getLineID());
128 std::vector<std::shared_ptr<NBPTStop> > stops = line->
getStops();
129 for (std::shared_ptr<NBPTStop> stop : stops) {
131 stop =
findWay(line, stop, ec, sc);
132 if (stop ==
nullptr) {
136 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
137 if (waysIdsIt == waysIds.end()) {
142 const std::vector<long long int>*
const way = line->
getWayNodes(stop->getOrigEdgeId());
143 if (way ==
nullptr) {
144 WRITE_WARNINGF(
TL(
"Cannot assign stop '%' on edge '%' to pt line '%' (wayNodes not found). Ignoring!"),
145 stop->getID(), stop->getOrigEdgeId(), line->
getLineID());
150 const std::vector<long long int>* wayPrev =
nullptr;
151 if (waysIdsIt != waysIds.begin()) {
154 const std::vector<long long int>* wayNext =
nullptr;
155 if (waysIdsIt != (waysIds.end() - 1)) {
158 if (wayPrev ==
nullptr && wayNext ==
nullptr) {
162 const long long int wayEnds = way->back();
163 const long long int wayBegins = way->front();
164 const long long int wayPrevEnds = wayPrev !=
nullptr ? wayPrev->back() : 0;
165 const long long int wayPrevBegins = wayPrev !=
nullptr ? wayPrev->front() : 0;
166 const long long int wayNextEnds = wayNext !=
nullptr ? wayNext->back() : 0;
167 const long long int wayNextBegins = wayNext !=
nullptr ? wayNext->front() : 0;
168 if (wayBegins == wayPrevEnds || wayBegins == wayPrevBegins || wayEnds == wayNextBegins || wayEnds == wayNextEnds) {
170 }
else if (wayEnds == wayPrevBegins || wayEnds == wayPrevEnds || wayBegins == wayNextEnds || wayBegins == wayNextBegins) {
177 std::string edgeId = stop->getEdgeId();
179 int assignedTo = edgeId.at(0) ==
'-' ?
BWD :
FWD;
181 if (dir != assignedTo) {
183 if (reverse ==
nullptr) {
184 WRITE_WARNINGF(
TL(
"Could not re-assign PT stop '%', probably broken osm file."), stop->getID());
187 if (stop->getLines().size() > 0) {
188 std::shared_ptr<NBPTStop> reverseStop = sc.
getReverseStop(stop, ec);
195 stop->setEdgeId(reverse->
getID(), ec);
197 stop->addLine(line->
getRef());
203 const std::vector<std::string>& waysIds = line->
getWays();
204 for (std::shared_ptr<NBPTStop> stop : line->
getStops()) {
206 stop =
findWay(line, stop, ec, sc);
207 if (stop ==
nullptr) {
211 auto waysIdsIt = std::find(waysIds.begin(), waysIds.end(), stop->getOrigEdgeId());
212 if (waysIdsIt == waysIds.end()) {
216 stop->addLine(line->
getRef());
221std::shared_ptr<NBPTStop>
223 const std::vector<std::string>& waysIds = line->
getWays();
226 std::cout <<
" stop=" << stop->getID() <<
" line=" << line->
getLineID() <<
" edgeID=" << stop->getEdgeId() <<
" origID=" << stop->getOrigEdgeId() <<
"\n";
229 if (stop->isLoose()) {
231 double minDist = std::numeric_limits<double>::max();
235 if (dist < minDist) {
243 <<
" found=" << (std::find(waysIds.begin(), waysIds.end(),
getWayID(best->
getID())) != waysIds.end())
244 <<
" wayIDs=" <<
toString(waysIds) <<
"\n";
249 if (stop->getEdgeId() ==
"") {
250 stop->setEdgeId(best->
getID(), ec);
251 stop->setOrigEdgeId(wayID);
252 }
else if (stop->getEdgeId() != best->
getID()) {
255 std::shared_ptr<NBPTStop> newStop = sc.
findStop(wayID, stop->getPosition());
256 if (newStop ==
nullptr) {
257 newStop = std::make_shared<NBPTStop>(stop->getID() +
"@" + line->
getLineID(), stop->getPosition(), best->
getID(), wayID, stop->getLength(), stop->getName(), stop->getPermissions());
258 newStop->setEdgeId(best->
getID(), ec);
265 WRITE_WARNINGF(
TL(
"Could not assign stop '%' to pt line '%' (closest edge '%', distance %). Ignoring!"),
271 auto waysIdsIt = waysIds.begin();
272 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
273 if ((*waysIdsIt) == stop->getOrigEdgeId()) {
278 if (waysIdsIt == waysIds.end()) {
280 for (
auto& edgeCand : stop->getAdditionalEdgeCandidates()) {
282 waysIdsIt = waysIds.begin();
283 for (; waysIdsIt != waysIds.end(); waysIdsIt++) {
284 if ((*waysIdsIt) == edgeCand.first) {
285 if (stop->setEdgeId(edgeCand.second, ec)) {
286 stop->setOrigEdgeId(edgeCand.first);
296 if (waysIdsIt == waysIds.end()) {
297 WRITE_WARNINGF(
TL(
"Cannot assign stop % on edge '%' to pt line '%'. Ignoring!"), stop->getID(), stop->getOrigEdgeId(), line->
getLineID());
306 std::vector<NBEdge*> edges;
310 std::vector<NBEdge*> prevWayEdges;
311 std::vector<NBEdge*> prevWayMinusEdges;
312 std::vector<NBEdge*> currentWayEdges;
313 std::vector<NBEdge*> currentWayMinusEdges;
314 for (
auto it3 = pTLine->
getWays().begin(); it3 != pTLine->
getWays().end(); it3++) {
316 int foundForward = 0;
317 if (cont.
retrieve(*it3,
false) !=
nullptr) {
318 currentWayEdges.push_back(cont.
retrieve(*it3,
false));
322 while (cont.
retrieve(*it3 +
"#" + std::to_string(i),
true) !=
nullptr) {
323 if (cont.
retrieve(*it3 +
"#" + std::to_string(i),
false)) {
324 currentWayEdges.push_back(cont.
retrieve(*it3 +
"#" + std::to_string(i),
false));
331 int foundReverse = 0;
332 if (cont.
retrieve(
"-" + *it3,
false) !=
nullptr) {
333 currentWayMinusEdges.push_back(cont.
retrieve(
"-" + *it3,
false));
337 while (cont.
retrieve(
"-" + *it3 +
"#" + std::to_string(i),
true) !=
nullptr) {
338 if (cont.
retrieve(
"-" + *it3 +
"#" + std::to_string(i),
false)) {
339 currentWayMinusEdges.insert(currentWayMinusEdges.end() - foundReverse,
340 cont.
retrieve(
"-" + *it3 +
"#" + std::to_string(i),
false));
346 bool fakeMinus =
false;
350 currentWayMinusEdges.insert(currentWayMinusEdges.begin(), currentWayEdges.rbegin(), currentWayEdges.rbegin() + foundForward);
353#ifdef DEBUG_CONSTRUCT_ROUTE
355 std::cout <<
" way=" << (*it3)
359 <<
"\n +=" <<
toString(currentWayEdges)
360 <<
"\n -=" <<
toString(currentWayMinusEdges)
361 <<
"\n p+=" <<
toString(prevWayEdges)
362 <<
"\n p-=" <<
toString(prevWayMinusEdges)
366 if (currentWayEdges.empty()) {
369 if (last == currentWayEdges.front()->getFromNode() && last !=
nullptr) {
370 if (!prevWayEdges.empty()) {
371 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
372 prevWayEdges.clear();
373 prevWayMinusEdges.clear();
375 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
376 last = currentWayEdges.back()->getToNode();
377 }
else if (last == currentWayEdges.back()->getToNode() && last !=
nullptr) {
378 if (!prevWayEdges.empty()) {
379 edges.insert(edges.end(), prevWayEdges.begin(), prevWayEdges.end());
380 prevWayEdges.clear();
381 prevWayMinusEdges.clear();
383 if (currentWayMinusEdges.empty()) {
384 currentWayEdges.clear();
388 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
390 last = currentWayMinusEdges.back()->getFromNode();
392 last = currentWayMinusEdges.back()->getToNode();
395 }
else if (first == currentWayEdges.front()->getFromNode() && first !=
nullptr) {
396 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
397 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
398 last = currentWayEdges.back()->getToNode();
399 prevWayEdges.clear();
400 prevWayMinusEdges.clear();
401 }
else if (first == currentWayEdges.back()->getToNode() && first !=
nullptr) {
402 edges.insert(edges.end(), prevWayMinusEdges.begin(), prevWayMinusEdges.end());
403 if (currentWayMinusEdges.empty()) {
404 currentWayEdges.clear();
406 prevWayEdges.clear();
407 prevWayMinusEdges.clear();
410 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
411 last = currentWayMinusEdges.back()->getToNode();
412 prevWayEdges.clear();
413 prevWayMinusEdges.clear();
416 if (it3 != pTLine->
getWays().begin()) {
417#ifdef DEBUG_CONSTRUCT_ROUTE
419 std::cout <<
" way " << (*it3)
420 <<
" is not the start of ptline " << pTLine->
getLineID()
421 <<
" (" + pTLine->
getName() +
")\n";
424 }
else if (pTLine->
getWays().size() == 1) {
425 if (currentWayEdges.size() > 0) {
426 edges.insert(edges.end(), currentWayEdges.begin(), currentWayEdges.end());
428 edges.insert(edges.end(), currentWayMinusEdges.begin(), currentWayMinusEdges.end());
431 prevWayEdges = currentWayEdges;
432 prevWayMinusEdges = currentWayMinusEdges;
433 if (!prevWayEdges.empty()) {
434 first = prevWayEdges.front()->getFromNode();
435 last = prevWayEdges.back()->getToNode();
441 currentWayEdges.clear();
442 currentWayMinusEdges.clear();
454 for (
const NBEdge* e : item.second->getRoute()) {
460 line->replaceEdge(edgeID, replacement);
461 for (
const NBEdge* e : replacement) {
471 std::set<std::string> result;
474 for (std::shared_ptr<NBPTStop> stop : line->
getStops()) {
475 result.insert(stop->getID());
484 std::map<std::string, SUMOVehicleClass> types;
501 std::vector<std::shared_ptr<NBPTStop> > stops = line->
getStops();
502 if (stops.size() < 2) {
505 if (types.count(line->
getType()) == 0) {
506 WRITE_WARNINGF(
TL(
"Could not determine vehicle class for public transport line of type '%'."), line->
getType());
510 std::vector<std::shared_ptr<NBPTStop> > newStops;
511 std::shared_ptr<NBPTStop> from =
nullptr;
512 for (
auto it = stops.begin(); it != stops.end(); ++it) {
513 std::shared_ptr<NBPTStop> to = *it;
514 std::shared_ptr<NBPTStop> used = *it;
515 if (to->getBidiStop() !=
nullptr) {
516 double best = std::numeric_limits<double>::max();
517 std::shared_ptr<NBPTStop> to2 = to->getBidiStop();
518 if (from ==
nullptr) {
519 if ((it + 1) != stops.end()) {
521 std::shared_ptr<NBPTStop> from2 = to2;
523 const double c1 =
getCost(ec, *router, from, to, &veh);
524 const double c2 =
getCost(ec, *router, from2, to, &veh);
528 if (to->getBidiStop() !=
nullptr) {
529 to2 = to->getBidiStop();
530 const double c3 =
getCost(ec, *router, from, to2, &veh);
531 const double c4 =
getCost(ec, *router, from2, to2, &veh);
556 const double c1 =
getCost(ec, *router, from, to, &veh);
557 const double c2 =
getCost(ec, *router, from, to2, &veh);
568 if (best < std::numeric_limits<double>::max()) {
575 newStops.push_back(used);
577 assert(stops.size() == newStops.size());
587 item.second->removeInvalidEdges(ec);
596 const std::vector<NBEdge*>& route = line->
getRoute();
598 for (
int i = 1; i < (int)route.size(); i++) {
599 NBEdge* e1 = route[i - 1];
602 if (cons.size() == 0) {
606 for (
const auto& c : cons) {
613 int lane = cons[0].fromLane;
624 const std::shared_ptr<NBPTStop> from,
const std::shared_ptr<NBPTStop> to,
const NBVehicle* veh) {
627 if (fromEdge ==
nullptr || toEdge ==
nullptr) {
628 return std::numeric_limits<double>::max();
629 }
else if (fromEdge == toEdge) {
630 if (from->getEndPos() <= to->getEndPos()) {
631 return to->getEndPos() - from->getEndPos();
633 return std::numeric_limits<double>::max();
636 return std::numeric_limits<double>::max();
638 std::vector<const NBRouterEdge*> route;
639 router.
compute(fromEdge, toEdge, veh, 0, route);
640 if (route.size() == 0) {
641 return std::numeric_limits<double>::max();
650 std::size_t found = edgeID.rfind(
"#");
651 std::string result = edgeID;
652 if (found != std::string::npos) {
653 result = edgeID.substr(0, found);
655 if (result[0] ==
'-') {
656 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 (exclusive) 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)
~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)
std::set< std::string > getServedPTStops()
void replaceEdge(const std::string &edgeID, const EdgeVector &replacement)
replace the edge with the given edge list in all lines
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