some minor changes

This commit is contained in:
Patrick Brosi 2022-01-17 13:29:35 +01:00
parent ea79e3ac52
commit 39fb167cbf
7 changed files with 49 additions and 19 deletions

View file

@ -188,7 +188,7 @@ int main(int argc, char** argv) {
for (size_t i = 0; i < cfg.feedPaths.size(); i++) { for (size_t i = 0; i < cfg.feedPaths.size(); i++) {
ShapeBuilder::getGtfsBox(&gtfs[i], cmdCfgMots, cfg.shapeTripId, true, ShapeBuilder::getGtfsBox(&gtfs[i], cmdCfgMots, cfg.shapeTripId, true,
&box, maxSpeed); &box, maxSpeed, 0);
} }
OsmBuilder osmBuilder; OsmBuilder osmBuilder;
std::vector<pfaedle::osm::OsmReadOpts> opts; std::vector<pfaedle::osm::OsmReadOpts> opts;
@ -210,7 +210,7 @@ int main(int argc, char** argv) {
BBoxIdx box(BOX_PADDING); BBoxIdx box(BOX_PADDING);
for (size_t i = 0; i < cfg.feedPaths.size(); i++) { for (size_t i = 0; i < cfg.feedPaths.size(); i++) {
ShapeBuilder::getGtfsBox(&gtfs[i], cmdCfgMots, cfg.shapeTripId, true, ShapeBuilder::getGtfsBox(&gtfs[i], cmdCfgMots, cfg.shapeTripId, true,
&box, maxSpeed); &box, maxSpeed, 0);
} }
OsmBuilder osmBuilder; OsmBuilder osmBuilder;
std::vector<pfaedle::osm::OsmReadOpts> opts; std::vector<pfaedle::osm::OsmReadOpts> opts;
@ -242,6 +242,7 @@ int main(int argc, char** argv) {
Stats stats; Stats stats;
double tOsmBuild = 0; double tOsmBuild = 0;
std::map<std::string, std::pair<size_t, size_t>> graphDimensions; std::map<std::string, std::pair<size_t, size_t>> graphDimensions;
std::vector<double> hopDists;
for (const auto& motCfg : motCfgReader.getConfigs()) { for (const auto& motCfg : motCfgReader.getConfigs()) {
std::string filePost; std::string filePost;
@ -266,7 +267,7 @@ int main(int argc, char** argv) {
pfaedle::osm::BBoxIdx box(BOX_PADDING); pfaedle::osm::BBoxIdx box(BOX_PADDING);
ShapeBuilder::getGtfsBox(&gtfs[0], usedMots, cfg.shapeTripId, ShapeBuilder::getGtfsBox(&gtfs[0], usedMots, cfg.shapeTripId,
cfg.dropShapes, &box, cfg.dropShapes, &box,
motCfg.osmBuildOpts.maxSpeed); motCfg.osmBuildOpts.maxSpeed, &hopDists);
T_START(osmBuild); T_START(osmBuild);
@ -389,11 +390,15 @@ int main(int argc, char** argv) {
graphSizes[gd.first] = a; graphSizes[gd.first] = a;
} }
double hopDistSum = 0;
for (auto d : hopDists) hopDistSum += d;
util::json::Dict jsonStats = { util::json::Dict jsonStats = {
{"statistics", {"statistics",
util::json::Dict{ util::json::Dict{
{"gtfs_num_stations", gtfs[0].getStops().size()}, {"gtfs_num_stations", gtfs[0].getStops().size()},
{"gtfs_num_trips", gtfs[0].getTrips().size()}, {"gtfs_num_trips", gtfs[0].getTrips().size()},
{"gtfs_avg_hop_dist", hopDistSum / (hopDists.size() * 1.0)},
{"graph_dimension", graphSizes}, {"graph_dimension", graphSizes},
{"num_nodes_tot", numNodesTot}, {"num_nodes_tot", numNodesTot},
{"num_edges_tot", numEdgesTot}, {"num_edges_tot", numEdgesTot},

View file

@ -72,7 +72,7 @@ ShapeBuilder::ShapeBuilder(
_router(router) { _router(router) {
pfaedle::osm::BBoxIdx box(BOX_PADDING); pfaedle::osm::BBoxIdx box(BOX_PADDING);
ShapeBuilder::getGtfsBox(feed, mots, cfg.shapeTripId, cfg.dropShapes, &box, 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); _eGrid = EdgeGrid(cfg.gridSize, cfg.gridSize, box.getFullBox(), false);
_nGrid = NodeGrid(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, void ShapeBuilder::getGtfsBox(const Feed* feed, const MOTs& mots,
const std::string& tid, bool dropShapes, const std::string& tid, bool dropShapes,
osm::BBoxIdx* box, double maxSpeed) { osm::BBoxIdx* box, double maxSpeed,
std::vector<double>* hopDists) {
for (const auto& t : feed->getTrips()) { for (const auto& t : feed->getTrips()) {
if (!tid.empty() && t.getId() != tid) continue; if (!tid.empty() && t.getId() != tid) continue;
if (tid.empty() && !t.getShape().empty() && !dropShapes) 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( toD = util::geo::haversine(
st.getStop()->getLat(), st.getStop()->getLng(), st.getStop()->getLat(), st.getStop()->getLng(),
stPrev.getStop()->getLat(), stPrev.getStop()->getLng()); stPrev.getStop()->getLat(), stPrev.getStop()->getLng());
if (hopDists) hopDists->push_back(toD);
} }
if (i < t.getStopTimes().size() - 1) { if (i < t.getStopTimes().size() - 1) {

View file

@ -5,11 +5,11 @@
#ifndef PFAEDLE_ROUTER_SHAPEBUILDER_H_ #ifndef PFAEDLE_ROUTER_SHAPEBUILDER_H_
#define PFAEDLE_ROUTER_SHAPEBUILDER_H_ #define PFAEDLE_ROUTER_SHAPEBUILDER_H_
#include <map>
#include <mutex> #include <mutex>
#include <set> #include <set>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <map>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "ad/cppgtfs/gtfs/Feed.h" #include "ad/cppgtfs/gtfs/Feed.h"
@ -72,7 +72,8 @@ class ShapeBuilder {
static void getGtfsBox(const pfaedle::gtfs::Feed* feed, const MOTs& mots, static void getGtfsBox(const pfaedle::gtfs::Feed* feed, const MOTs& mots,
const std::string& tid, bool dropShapes, const std::string& tid, bool dropShapes,
osm::BBoxIdx* box, double maxSpeed); osm::BBoxIdx* box, double maxSpeed,
std::vector<double>* hopDists);
private: private:
pfaedle::gtfs::Feed* _feed; pfaedle::gtfs::Feed* _feed;

View file

@ -75,6 +75,7 @@ double Collector::add(const Trip* oldT, const Shape* oldS, const Trip* newT,
for (const auto& p : oldLenDists) { for (const auto& p : oldLenDists) {
_distDiffs.push_back(fabs(p.first - p.second)); _distDiffs.push_back(fabs(p.first - p.second));
_hopDists.push_back(p.first);
} }
// new lines build from cleaned-up shapes // new lines build from cleaned-up shapes
@ -352,6 +353,15 @@ std::map<string, double> Collector::getStats() {
stats["median-dist-diff"] = -1; 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"] = _trips;
stats["num-trips-matched"] = _results.size(); stats["num-trips-matched"] = _results.size();
stats["num-trips-wo-shapes"] = _noOrigShp; stats["num-trips-wo-shapes"] = _noOrigShp;
@ -386,10 +396,13 @@ std::pair<size_t, double> Collector::getDa(const std::vector<LINE>& a,
std::pair<size_t, double> ret{0, 0}; std::pair<size_t, double> ret{0, 0};
// convert (roughly) to degrees // 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++) { for (size_t i = 0; i < a.size(); i++) {
double fdMeter = 0; double fdMeter = 0;
auto old = _dACache.find(a[i]); auto old = _dACache.find(a[i]);
if (old != _dACache.end()) { if (old != _dACache.end()) {
auto match = old->second.find(b[i]); auto match = old->second.find(b[i]);
@ -404,7 +417,7 @@ std::pair<size_t, double> Collector::getDa(const std::vector<LINE>& a,
_dACache[a[i]][b[i]] = fdMeter; _dACache[a[i]][b[i]] = fdMeter;
} }
if (fdMeter >= 50) { if (fdMeter >= MAX) {
ret.first++; ret.first++;
ret.second += util::geo::latLngLen(a[i]); ret.second += util::geo::latLngLen(a[i]);
} }

View file

@ -98,6 +98,7 @@ class Collector {
size_t _noOrigShp; size_t _noOrigShp;
std::vector<double> _distDiffs; std::vector<double> _distDiffs;
std::vector<double> _hopDists;
double _fdSum; double _fdSum;
size_t _unmatchedSegSum; size_t _unmatchedSegSum;

View file

@ -8,6 +8,8 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <thread> #include <thread>
#include <sys/resource.h>
#include <stdio.h>
#include <vector> #include <vector>
#include "ad/cppgtfs/Parser.h" #include "ad/cppgtfs/Parser.h"
#include "shapevl/Collector.h" #include "shapevl/Collector.h"
@ -42,8 +44,7 @@ void eval(const std::vector<std::string>* paths,
int myFeed = count-- - 1; int myFeed = count-- - 1;
if (myFeed < 0) return; if (myFeed < 0) return;
std::string path = (*paths)[myFeed]; std::string path = (*paths)[myFeed];
LOG(DEBUG) << "Reading eval feed " << path << " " LOG(DEBUG) << "Reading eval feed " << path << " ...";
<< " ...";
ad::cppgtfs::gtfs::Feed feed; ad::cppgtfs::gtfs::Feed feed;
ad::cppgtfs::Parser p; ad::cppgtfs::Parser p;
@ -80,6 +81,13 @@ int main(int argc, char** argv) {
// initialize randomness // initialize randomness
srand(time(NULL) + rand()); // NOLINT 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; std::string groundTruthFeedPath, motStr;
motStr = "all"; motStr = "all";
ad::cppgtfs::gtfs::Feed groundTruthFeed; ad::cppgtfs::gtfs::Feed groundTruthFeed;

View file

@ -1861,8 +1861,8 @@ inline double frechetDist(const Line<T>& a, const Line<T>& b, double d) {
// based on Eiter / Mannila // based on Eiter / Mannila
// http://www.kr.tuwien.ac.at/staff/eiter/et-archive/cdtr9464.pdf // http://www.kr.tuwien.ac.at/staff/eiter/et-archive/cdtr9464.pdf
auto p = densify(a, d); const auto& p = densify(a, d);
auto q = densify(b, d); const auto& q = densify(b, d);
std::vector<float> ca(p.size() * q.size(), -1.0); std::vector<float> ca(p.size() * q.size(), -1.0);
double fd = frechetDistC(p.size() - 1, q.size() - 1, p, q, ca); double fd = frechetDistC(p.size() - 1, q.size() - 1, p, q, ca);
@ -1873,8 +1873,8 @@ inline double frechetDist(const Line<T>& a, const Line<T>& b, double d) {
// _____________________________________________________________________________ // _____________________________________________________________________________
template <typename T> template <typename T>
inline double accFrechetDistC(const Line<T>& a, const Line<T>& b, double d) { inline double accFrechetDistC(const Line<T>& a, const Line<T>& b, double d) {
auto p = densify(a, d); const auto& p = densify(a, d);
auto q = densify(b, d); const auto& q = densify(b, d);
assert(p.size()); assert(p.size());
assert(q.size()); assert(q.size());
@ -1935,8 +1935,8 @@ inline double frechetDistHav(const Line<T>& a, const Line<T>& b, double d) {
// based on Eiter / Mannila // based on Eiter / Mannila
// http://www.kr.tuwien.ac.at/staff/eiter/et-archive/cdtr9464.pdf // http://www.kr.tuwien.ac.at/staff/eiter/et-archive/cdtr9464.pdf
auto p = densify(a, d); const auto& p = densify(a, d);
auto q = densify(b, d); const auto& q = densify(b, d);
std::vector<float> ca(p.size() * q.size(), -1.0); std::vector<float> ca(p.size() * q.size(), -1.0);
double fd = frechetDistCHav(p.size() - 1, q.size() - 1, p, q, ca); double fd = frechetDistCHav(p.size() - 1, q.size() - 1, p, q, ca);
@ -1947,8 +1947,8 @@ inline double frechetDistHav(const Line<T>& a, const Line<T>& b, double d) {
// _____________________________________________________________________________ // _____________________________________________________________________________
template <typename T> template <typename T>
inline double accFrechetDistCHav(const Line<T>& a, const Line<T>& b, double d) { inline double accFrechetDistCHav(const Line<T>& a, const Line<T>& b, double d) {
auto p = densify(a, d); const auto& p = densify(a, d);
auto q = densify(b, d); const auto& q = densify(b, d);
assert(p.size()); assert(p.size());
assert(q.size()); assert(q.size());