From 39fb167cbffb3c8fb3910770aa6a9432c551e624 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Mon, 17 Jan 2022 13:29:35 +0100 Subject: [PATCH] some minor changes --- src/pfaedle/PfaedleMain.cpp | 11 ++++++++--- src/pfaedle/router/ShapeBuilder.cpp | 6 ++++-- src/pfaedle/router/ShapeBuilder.h | 5 +++-- src/shapevl/Collector.cpp | 17 +++++++++++++++-- src/shapevl/Collector.h | 1 + src/shapevl/ShapevlMain.cpp | 12 ++++++++++-- src/util/geo/Geo.h | 16 ++++++++-------- 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/pfaedle/PfaedleMain.cpp b/src/pfaedle/PfaedleMain.cpp index 8ea073b..cefc888 100644 --- a/src/pfaedle/PfaedleMain.cpp +++ b/src/pfaedle/PfaedleMain.cpp @@ -188,7 +188,7 @@ int main(int argc, char** argv) { for (size_t i = 0; i < cfg.feedPaths.size(); i++) { ShapeBuilder::getGtfsBox(>fs[i], cmdCfgMots, cfg.shapeTripId, true, - &box, maxSpeed); + &box, maxSpeed, 0); } OsmBuilder osmBuilder; std::vector opts; @@ -210,7 +210,7 @@ int main(int argc, char** argv) { BBoxIdx box(BOX_PADDING); for (size_t i = 0; i < cfg.feedPaths.size(); i++) { ShapeBuilder::getGtfsBox(>fs[i], cmdCfgMots, cfg.shapeTripId, true, - &box, maxSpeed); + &box, maxSpeed, 0); } OsmBuilder osmBuilder; std::vector opts; @@ -242,6 +242,7 @@ int main(int argc, char** argv) { Stats stats; double tOsmBuild = 0; std::map> graphDimensions; + std::vector hopDists; for (const auto& motCfg : motCfgReader.getConfigs()) { std::string filePost; @@ -266,7 +267,7 @@ int main(int argc, char** argv) { pfaedle::osm::BBoxIdx box(BOX_PADDING); ShapeBuilder::getGtfsBox(>fs[0], usedMots, cfg.shapeTripId, cfg.dropShapes, &box, - motCfg.osmBuildOpts.maxSpeed); + motCfg.osmBuildOpts.maxSpeed, &hopDists); T_START(osmBuild); @@ -389,11 +390,15 @@ int main(int argc, char** argv) { graphSizes[gd.first] = a; } + double hopDistSum = 0; + for (auto d : hopDists) hopDistSum += d; + util::json::Dict jsonStats = { {"statistics", util::json::Dict{ {"gtfs_num_stations", gtfs[0].getStops().size()}, {"gtfs_num_trips", gtfs[0].getTrips().size()}, + {"gtfs_avg_hop_dist", hopDistSum / (hopDists.size() * 1.0)}, {"graph_dimension", graphSizes}, {"num_nodes_tot", numNodesTot}, {"num_edges_tot", numEdgesTot}, diff --git a/src/pfaedle/router/ShapeBuilder.cpp b/src/pfaedle/router/ShapeBuilder.cpp index 57e4bca..3615ed1 100644 --- a/src/pfaedle/router/ShapeBuilder.cpp +++ b/src/pfaedle/router/ShapeBuilder.cpp @@ -72,7 +72,7 @@ ShapeBuilder::ShapeBuilder( _router(router) { pfaedle::osm::BBoxIdx box(BOX_PADDING); ShapeBuilder::getGtfsBox(feed, mots, cfg.shapeTripId, cfg.dropShapes, &box, - _motCfg.osmBuildOpts.maxSpeed); + _motCfg.osmBuildOpts.maxSpeed, 0); _eGrid = EdgeGrid(cfg.gridSize, cfg.gridSize, box.getFullBox(), false); _nGrid = NodeGrid(cfg.gridSize, cfg.gridSize, box.getFullBox(), false); @@ -647,7 +647,8 @@ const RoutingAttrs& ShapeBuilder::getRAttrs(const Trip* trip) const { // _____________________________________________________________________________ void ShapeBuilder::getGtfsBox(const Feed* feed, const MOTs& mots, const std::string& tid, bool dropShapes, - osm::BBoxIdx* box, double maxSpeed) { + osm::BBoxIdx* box, double maxSpeed, + std::vector* hopDists) { for (const auto& t : feed->getTrips()) { if (!tid.empty() && t.getId() != tid) continue; if (tid.empty() && !t.getShape().empty() && !dropShapes) continue; @@ -671,6 +672,7 @@ void ShapeBuilder::getGtfsBox(const Feed* feed, const MOTs& mots, toD = util::geo::haversine( st.getStop()->getLat(), st.getStop()->getLng(), stPrev.getStop()->getLat(), stPrev.getStop()->getLng()); + if (hopDists) hopDists->push_back(toD); } if (i < t.getStopTimes().size() - 1) { diff --git a/src/pfaedle/router/ShapeBuilder.h b/src/pfaedle/router/ShapeBuilder.h index fc176fc..3e243ad 100644 --- a/src/pfaedle/router/ShapeBuilder.h +++ b/src/pfaedle/router/ShapeBuilder.h @@ -5,11 +5,11 @@ #ifndef PFAEDLE_ROUTER_SHAPEBUILDER_H_ #define PFAEDLE_ROUTER_SHAPEBUILDER_H_ +#include #include #include #include #include -#include #include #include #include "ad/cppgtfs/gtfs/Feed.h" @@ -72,7 +72,8 @@ class ShapeBuilder { static void getGtfsBox(const pfaedle::gtfs::Feed* feed, const MOTs& mots, const std::string& tid, bool dropShapes, - osm::BBoxIdx* box, double maxSpeed); + osm::BBoxIdx* box, double maxSpeed, + std::vector* hopDists); private: pfaedle::gtfs::Feed* _feed; diff --git a/src/shapevl/Collector.cpp b/src/shapevl/Collector.cpp index def02f5..33608a8 100644 --- a/src/shapevl/Collector.cpp +++ b/src/shapevl/Collector.cpp @@ -75,6 +75,7 @@ double Collector::add(const Trip* oldT, const Shape* oldS, const Trip* newT, for (const auto& p : oldLenDists) { _distDiffs.push_back(fabs(p.first - p.second)); + _hopDists.push_back(p.first); } // new lines build from cleaned-up shapes @@ -352,6 +353,15 @@ std::map Collector::getStats() { stats["median-dist-diff"] = -1; } + if (_hopDists.size()) { + double s = 0; + for (auto d : _hopDists) s += d; + + stats["avg-hop-dist"] = s / (_hopDists.size() * 1.0); + } else { + stats["avg-hop-dist"] = -1; + } + stats["num-trips"] = _trips; stats["num-trips-matched"] = _results.size(); stats["num-trips-wo-shapes"] = _noOrigShp; @@ -386,10 +396,13 @@ std::pair Collector::getDa(const std::vector& a, std::pair ret{0, 0}; // convert (roughly) to degrees - double SEGL = 15.0 / util::geo::M_PER_DEG; + double SEGL = 15 / util::geo::M_PER_DEG; + + double MAX = 50; for (size_t i = 0; i < a.size(); i++) { double fdMeter = 0; + auto old = _dACache.find(a[i]); if (old != _dACache.end()) { auto match = old->second.find(b[i]); @@ -404,7 +417,7 @@ std::pair Collector::getDa(const std::vector& a, _dACache[a[i]][b[i]] = fdMeter; } - if (fdMeter >= 50) { + if (fdMeter >= MAX) { ret.first++; ret.second += util::geo::latLngLen(a[i]); } diff --git a/src/shapevl/Collector.h b/src/shapevl/Collector.h index 18474bf..683c55b 100644 --- a/src/shapevl/Collector.h +++ b/src/shapevl/Collector.h @@ -98,6 +98,7 @@ class Collector { size_t _noOrigShp; std::vector _distDiffs; + std::vector _hopDists; double _fdSum; size_t _unmatchedSegSum; diff --git a/src/shapevl/ShapevlMain.cpp b/src/shapevl/ShapevlMain.cpp index 26e16b0..6be9856 100644 --- a/src/shapevl/ShapevlMain.cpp +++ b/src/shapevl/ShapevlMain.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include "ad/cppgtfs/Parser.h" #include "shapevl/Collector.h" @@ -42,8 +44,7 @@ void eval(const std::vector* paths, int myFeed = count-- - 1; if (myFeed < 0) return; std::string path = (*paths)[myFeed]; - LOG(DEBUG) << "Reading eval feed " << path << " " - << " ..."; + LOG(DEBUG) << "Reading eval feed " << path << " ..."; ad::cppgtfs::gtfs::Feed feed; ad::cppgtfs::Parser p; @@ -80,6 +81,13 @@ int main(int argc, char** argv) { // initialize randomness srand(time(NULL) + rand()); // NOLINT + // increase max stack size for frechet distance calc + + struct rlimit rl; + getrlimit(RLIMIT_STACK, &rl); + + std::cout << rl.rlim_max << std::endl; + std::string groundTruthFeedPath, motStr; motStr = "all"; ad::cppgtfs::gtfs::Feed groundTruthFeed; diff --git a/src/util/geo/Geo.h b/src/util/geo/Geo.h index 20c5b36..3da7da0 100644 --- a/src/util/geo/Geo.h +++ b/src/util/geo/Geo.h @@ -1861,8 +1861,8 @@ inline double frechetDist(const Line& a, const Line& b, double d) { // based on Eiter / Mannila // http://www.kr.tuwien.ac.at/staff/eiter/et-archive/cdtr9464.pdf - auto p = densify(a, d); - auto q = densify(b, d); + const auto& p = densify(a, d); + const auto& q = densify(b, d); std::vector ca(p.size() * q.size(), -1.0); double fd = frechetDistC(p.size() - 1, q.size() - 1, p, q, ca); @@ -1873,8 +1873,8 @@ inline double frechetDist(const Line& a, const Line& b, double d) { // _____________________________________________________________________________ template inline double accFrechetDistC(const Line& a, const Line& b, double d) { - auto p = densify(a, d); - auto q = densify(b, d); + const auto& p = densify(a, d); + const auto& q = densify(b, d); assert(p.size()); assert(q.size()); @@ -1935,8 +1935,8 @@ inline double frechetDistHav(const Line& a, const Line& b, double d) { // based on Eiter / Mannila // http://www.kr.tuwien.ac.at/staff/eiter/et-archive/cdtr9464.pdf - auto p = densify(a, d); - auto q = densify(b, d); + const auto& p = densify(a, d); + const auto& q = densify(b, d); std::vector ca(p.size() * q.size(), -1.0); double fd = frechetDistCHav(p.size() - 1, q.size() - 1, p, q, ca); @@ -1947,8 +1947,8 @@ inline double frechetDistHav(const Line& a, const Line& b, double d) { // _____________________________________________________________________________ template inline double accFrechetDistCHav(const Line& a, const Line& b, double d) { - auto p = densify(a, d); - auto q = densify(b, d); + const auto& p = densify(a, d); + const auto& q = densify(b, d); assert(p.size()); assert(q.size());