From 647a596deace01999f449d4b298c31caf72c29c5 Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Mon, 31 Jan 2022 23:44:53 +0100 Subject: [PATCH] make jaccard-geodist the default statsimi classifier --- pfaedle.cfg | 2 +- src/pfaedle/PfaedleMain.cpp | 3 +++ src/pfaedle/config/MotConfigReader.cpp | 2 +- .../StatsimiClassifier.cpp | 27 +++++++++++++++++++ .../statsimi-classifier/StatsimiClassifier.h | 8 ++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/pfaedle.cfg b/pfaedle.cfg index f31ddbc..d2c77aa 100644 --- a/pfaedle.cfg +++ b/pfaedle.cfg @@ -7,7 +7,7 @@ routing_transition_penalty_fac: 0.0083 routing_station_move_penalty_fac: 0.002 -station_similarity_classification_method: jaccard +station_similarity_classification_method: jaccard-geodist # Regular expressions and station comparision is # always case insensitive! diff --git a/src/pfaedle/PfaedleMain.cpp b/src/pfaedle/PfaedleMain.cpp index cefc888..c4af14a 100644 --- a/src/pfaedle/PfaedleMain.cpp +++ b/src/pfaedle/PfaedleMain.cpp @@ -61,6 +61,7 @@ using pfaedle::router::RouterImpl; using pfaedle::router::ShapeBuilder; using pfaedle::router::Stats; using pfaedle::statsimiclassifier::JaccardClassifier; +using pfaedle::statsimiclassifier::JaccardGeodistClassifier; using pfaedle::statsimiclassifier::StatsimiClassifier; using pfaedle::statsimiclassifier::BTSClassifier; using pfaedle::statsimiclassifier::EDClassifier; @@ -288,6 +289,8 @@ int main(int argc, char** argv) { statsimiClassifier = new BTSClassifier(); } else if (motCfg.routingOpts.statsimiMethod == "jaccard") { statsimiClassifier = new JaccardClassifier(); + } else if (motCfg.routingOpts.statsimiMethod == "jaccard-geodist") { + statsimiClassifier = new JaccardGeodistClassifier(); } else if (motCfg.routingOpts.statsimiMethod == "ed") { statsimiClassifier = new EDClassifier(); } else if (motCfg.routingOpts.statsimiMethod == "ped") { diff --git a/src/pfaedle/config/MotConfigReader.cpp b/src/pfaedle/config/MotConfigReader.cpp index 8a26c7f..87be86e 100644 --- a/src/pfaedle/config/MotConfigReader.cpp +++ b/src/pfaedle/config/MotConfigReader.cpp @@ -65,7 +65,7 @@ void MotConfigReader::parse(const std::vector& paths, cfg.routingOpts.statsimiMethod = p.getStr(secStr, "station_similarity_classification_method"); } else { - cfg.routingOpts.statsimiMethod = "bts"; + cfg.routingOpts.statsimiMethod = "jaccard-geodist"; } if (p.hasKey(secStr, "routing_use_stations")) { diff --git a/src/pfaedle/statsimi-classifier/StatsimiClassifier.cpp b/src/pfaedle/statsimi-classifier/StatsimiClassifier.cpp index 7b98532..e8011e6 100644 --- a/src/pfaedle/statsimi-classifier/StatsimiClassifier.cpp +++ b/src/pfaedle/statsimi-classifier/StatsimiClassifier.cpp @@ -12,8 +12,35 @@ using pfaedle::statsimiclassifier::BTSClassifier; using pfaedle::statsimiclassifier::EDClassifier; using pfaedle::statsimiclassifier::JaccardClassifier; +using pfaedle::statsimiclassifier::JaccardGeodistClassifier; using pfaedle::statsimiclassifier::PEDClassifier; +// _____________________________________________________________________________ +bool JaccardGeodistClassifier::similar(const std::string& nameA, + const POINT& posA, + const std::string& nameB, + const POINT& posB) const { + const double THRES_M = + 0.00815467271246994481; // ln 2/85 from statsimi evaluation + const double THRES_JACC = .5; // from statsimi evaluation + + const double m = exp(-THRES_M * util::geo::haversine(posA, posB)); + double jacc = util::jaccardSimi(nameA, nameB); + + if (jacc > THRES_JACC) + jacc = .5 + (jacc - THRES_JACC) / (2.0 * (1.0 - THRES_JACC)); + else + jacc = jacc / (2.0 * THRES_JACC); + + return (m + jacc) / 2.0; +} + +// _____________________________________________________________________________ +bool JaccardGeodistClassifier::similar(const std::string& nameA, + const std::string& nameB) const { + return util::jaccardSimi(nameA, nameB) > 0.45; // 0.45 from statsimi paper +} + // _____________________________________________________________________________ bool JaccardClassifier::similar(const std::string& nameA, const POINT& posA, const std::string& nameB, diff --git a/src/pfaedle/statsimi-classifier/StatsimiClassifier.h b/src/pfaedle/statsimi-classifier/StatsimiClassifier.h index 7890ff3..cdde205 100644 --- a/src/pfaedle/statsimi-classifier/StatsimiClassifier.h +++ b/src/pfaedle/statsimi-classifier/StatsimiClassifier.h @@ -30,6 +30,14 @@ class JaccardClassifier : public StatsimiClassifier { const std::string& nameB) const; }; +class JaccardGeodistClassifier : public StatsimiClassifier { + public: + virtual bool similar(const std::string& nameA, const POINT& posA, + const std::string& nameB, const POINT& posB) const; + virtual bool similar(const std::string& nameA, + const std::string& nameB) const; +}; + class BTSClassifier : public StatsimiClassifier { public: virtual bool similar(const std::string& nameA, const POINT& posA,