update segmentation in shapevl, add --unique mode
This commit is contained in:
parent
c3bc12eb8c
commit
15e84d930a
11 changed files with 177 additions and 95 deletions
|
|
@ -6,11 +6,11 @@
|
|||
#define PFAEDLE_ROUTER_ROUTER_H_
|
||||
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "pfaedle/Def.h"
|
||||
|
|
@ -52,12 +52,10 @@ typedef std::vector<std::pair<std::pair<size_t, size_t>, uint32_t>> CostMatrix;
|
|||
class Router {
|
||||
public:
|
||||
virtual ~Router() = default;
|
||||
virtual std::map<size_t, EdgeListHops> route(const TripTrie* trie,
|
||||
const EdgeCandMap& ecm,
|
||||
const RoutingOpts& rOpts,
|
||||
const osm::Restrictor& rest,
|
||||
HopCache* hopCache,
|
||||
bool noFastHops) const = 0;
|
||||
virtual std::map<size_t, EdgeListHops> route(
|
||||
const TripTrie<pfaedle::gtfs::Trip>* trie, const EdgeCandMap& ecm,
|
||||
const RoutingOpts& rOpts, const osm::Restrictor& rest, HopCache* hopCache,
|
||||
bool noFastHops) const = 0;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -69,8 +67,9 @@ class RouterImpl : public Router {
|
|||
public:
|
||||
// Find the most likely path through the graph for a trip trie.
|
||||
virtual std::map<size_t, EdgeListHops> route(
|
||||
const TripTrie* trie, const EdgeCandMap& ecm, const RoutingOpts& rOpts,
|
||||
const osm::Restrictor& rest, HopCache* hopCache, bool noFastHops) const;
|
||||
const TripTrie<pfaedle::gtfs::Trip>* trie, const EdgeCandMap& ecm,
|
||||
const RoutingOpts& rOpts, const osm::Restrictor& rest, HopCache* hopCache,
|
||||
bool noFastHops) const;
|
||||
|
||||
private:
|
||||
void hops(const EdgeCandGroup& from, const EdgeCandGroup& to,
|
||||
|
|
|
|||
|
|
@ -9,21 +9,22 @@
|
|||
#define omp_get_num_procs() 1
|
||||
#endif
|
||||
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <set>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using util::graph::EDijkstra;
|
||||
|
||||
// _____________________________________________________________________________
|
||||
template <typename TW>
|
||||
std::map<size_t, EdgeListHops> RouterImpl<TW>::route(
|
||||
const TripTrie* trie, const EdgeCandMap& ecm, const RoutingOpts& rOpts,
|
||||
const osm::Restrictor& rest, HopCache* hopCache, bool noFastHops) const {
|
||||
const TripTrie<pfaedle::gtfs::Trip>* trie, const EdgeCandMap& ecm,
|
||||
const RoutingOpts& rOpts, const osm::Restrictor& rest, HopCache* hopCache,
|
||||
bool noFastHops) const {
|
||||
std::map<size_t, EdgeListHops> ret;
|
||||
|
||||
// the current node costs in our DAG
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
#ifndef PFAEDLE_ROUTER_ROUTINGATTRS_H_
|
||||
#define PFAEDLE_ROUTER_ROUTINGATTRS_H_
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "pfaedle/statsimi-classifier/StatsimiClassifier.h"
|
||||
#include "pfaedle/trgraph/EdgePL.h"
|
||||
|
||||
|
|
@ -30,6 +30,13 @@ inline bool operator<(const LineSimilarity& a, const LineSimilarity& b) {
|
|||
struct RoutingAttrs {
|
||||
RoutingAttrs()
|
||||
: lineFrom(""), lineTo(), shortName(""), classifier(0), _simiCache() {}
|
||||
RoutingAttrs(const std::string& shortName, const std::string& lineFrom,
|
||||
const std::string& lineTo)
|
||||
: lineFrom(lineFrom),
|
||||
lineTo({lineTo}),
|
||||
shortName(shortName),
|
||||
classifier(0),
|
||||
_simiCache() {}
|
||||
std::string lineFrom;
|
||||
std::vector<std::string> lineTo;
|
||||
std::string shortName;
|
||||
|
|
|
|||
|
|
@ -328,14 +328,15 @@ std::pair<std::vector<LINE>, Stats> ShapeBuilder::shapeL(Trip* trip) {
|
|||
|
||||
// _____________________________________________________________________________
|
||||
std::map<size_t, pfaedle::router::EdgeListHops> ShapeBuilder::route(
|
||||
const TripTrie* trie, const EdgeCandMap& ecm, HopCache* hopCache) const {
|
||||
const TripTrie<pfaedle::gtfs::Trip>* trie, const EdgeCandMap& ecm,
|
||||
HopCache* hopCache) const {
|
||||
return _router->route(trie, ecm, _motCfg.routingOpts, *_restr, hopCache,
|
||||
_cfg.noFastHops);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
std::map<size_t, EdgeListHops> ShapeBuilder::shapeify(
|
||||
const TripTrie* trie, HopCache* hopCache) const {
|
||||
const TripTrie<pfaedle::gtfs::Trip>* trie, HopCache* hopCache) const {
|
||||
LOG(VDEBUG) << "Map-matching trie " << trie;
|
||||
|
||||
// TODO(patrick): assumes the trie is not empty, check this!
|
||||
|
|
@ -362,7 +363,7 @@ EdgeListHops ShapeBuilder::shapeify(Trip* trip) {
|
|||
<< trip->getRoute()->getType() << "(sn=" << trip->getShortname()
|
||||
<< ", rsn=" << trip->getRoute()->getShortName()
|
||||
<< ", rln=" << trip->getRoute()->getLongName() << ")";
|
||||
TripTrie trie;
|
||||
TripTrie<pfaedle::gtfs::Trip> trie;
|
||||
trie.addTrip(trip, getRAttrs(trip),
|
||||
_motCfg.routingOpts.transPenMethod == "timenorm", false);
|
||||
const auto& routes = route(&trie, getECM(&trie), 0);
|
||||
|
|
@ -748,7 +749,8 @@ std::vector<double> ShapeBuilder::getTransDists(Trip* trip) const {
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
EdgeCandMap ShapeBuilder::getECM(const TripTrie* trie) const {
|
||||
EdgeCandMap ShapeBuilder::getECM(
|
||||
const TripTrie<pfaedle::gtfs::Trip>* trie) const {
|
||||
EdgeCandMap ecm(trie->getNds().size());
|
||||
|
||||
for (size_t nid = 1; nid < trie->getNds().size(); nid++) {
|
||||
|
|
@ -1146,7 +1148,7 @@ void ShapeBuilder::shapeWorker(
|
|||
if (!_cfg.noHopCache) hopCache = &hopCacheLoc;
|
||||
|
||||
for (size_t i = 0; i < forest.size(); i++) {
|
||||
const TripTrie* trie = &(forest[i]);
|
||||
const TripTrie<pfaedle::gtfs::Trip>* trie = &(forest[i]);
|
||||
const auto& hops = shapeify(trie, hopCache);
|
||||
|
||||
for (const auto& leaf : trie->getNdTrips()) {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
namespace pfaedle {
|
||||
namespace router {
|
||||
|
||||
typedef std::vector<TripTrie> TripForest;
|
||||
typedef std::vector<TripTrie<pfaedle::gtfs::Trip>> TripForest;
|
||||
typedef std::map<router::RoutingAttrs, TripForest> TripForests;
|
||||
typedef std::pair<const ad::cppgtfs::gtfs::Stop*,
|
||||
const ad::cppgtfs::gtfs::Stop*>
|
||||
|
|
@ -64,8 +64,8 @@ class ShapeBuilder {
|
|||
// shape single trip
|
||||
std::pair<std::vector<LINE>, Stats> shapeL(pfaedle::gtfs::Trip* trip);
|
||||
|
||||
std::map<size_t, EdgeListHops> shapeify(const TripTrie* trie,
|
||||
HopCache* hopCache) const;
|
||||
std::map<size_t, EdgeListHops> shapeify(
|
||||
const TripTrie<pfaedle::gtfs::Trip>* trie, HopCache* hopCache) const;
|
||||
EdgeListHops shapeify(pfaedle::gtfs::Trip* trip);
|
||||
|
||||
const trgraph::Graph* getGraph() const;
|
||||
|
|
@ -112,14 +112,14 @@ class ShapeBuilder {
|
|||
|
||||
EdgeCandGroup getEdgCands(const ad::cppgtfs::gtfs::Stop* s) const;
|
||||
|
||||
router::EdgeCandMap getECM(const TripTrie* trie) const;
|
||||
router::EdgeCandMap getECM(const TripTrie<pfaedle::gtfs::Trip>* trie) const;
|
||||
std::vector<double> getTransTimes(pfaedle::gtfs::Trip* trip) const;
|
||||
std::vector<double> getTransDists(pfaedle::gtfs::Trip* trip) const;
|
||||
const router::RoutingAttrs& getRAttrs(const pfaedle::gtfs::Trip* trip) const;
|
||||
const router::RoutingAttrs& getRAttrs(const pfaedle::gtfs::Trip* trip);
|
||||
std::map<size_t, router::EdgeListHops> route(const TripTrie* trie,
|
||||
const EdgeCandMap& ecm,
|
||||
HopCache* hopCache) const;
|
||||
std::map<size_t, router::EdgeListHops> route(
|
||||
const TripTrie<pfaedle::gtfs::Trip>* trie, const EdgeCandMap& ecm,
|
||||
HopCache* hopCache) const;
|
||||
double emWeight(double mDist) const;
|
||||
|
||||
void buildCandCache(const TripForests& clusters);
|
||||
|
|
|
|||
|
|
@ -31,26 +31,27 @@ struct TripTrieNd {
|
|||
RoutingAttrs rAttrs;
|
||||
};
|
||||
|
||||
template <typename TRIP>
|
||||
class TripTrie {
|
||||
public:
|
||||
// init node 0, this is the first decision node
|
||||
TripTrie() : _nds(1) {}
|
||||
bool addTrip(pfaedle::gtfs::Trip* trip, const RoutingAttrs& rAttrs,
|
||||
bool addTrip(TRIP* trip, const RoutingAttrs& rAttrs,
|
||||
bool timeEx, bool degen);
|
||||
|
||||
const std::vector<TripTrieNd>& getNds() const;
|
||||
const TripTrieNd& getNd(size_t nid) const;
|
||||
|
||||
void toDot(std::ostream& os, const std::string& rootName, size_t gid) const;
|
||||
const std::map<size_t, std::vector<pfaedle::gtfs::Trip*>>& getNdTrips() const;
|
||||
const std::map<size_t, std::vector<TRIP*>>& getNdTrips() const;
|
||||
|
||||
private:
|
||||
std::vector<TripTrieNd> _nds;
|
||||
std::map<pfaedle::gtfs::Trip*, size_t> _tripNds;
|
||||
std::map<size_t, std::vector<pfaedle::gtfs::Trip*>> _ndTrips;
|
||||
std::map<TRIP*, size_t> _tripNds;
|
||||
std::map<size_t, std::vector<TRIP*>> _ndTrips;
|
||||
|
||||
bool add(pfaedle::gtfs::Trip* trip, const RoutingAttrs& rAttrs, bool timeEx);
|
||||
size_t get(pfaedle::gtfs::Trip* trip, bool timeEx);
|
||||
bool add(TRIP* trip, const RoutingAttrs& rAttrs, bool timeEx);
|
||||
size_t get(TRIP* trip, bool timeEx);
|
||||
|
||||
size_t getMatchChild(size_t parentNid, const std::string& stopName,
|
||||
const std::string& platform, POINT pos, int time,
|
||||
|
|
@ -59,6 +60,7 @@ class TripTrie {
|
|||
const POINT& pos, int time, bool arr, size_t parent);
|
||||
};
|
||||
|
||||
#include "pfaedle/router/TripTrie.tpp"
|
||||
} // namespace router
|
||||
} // namespace pfaedle
|
||||
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@
|
|||
#include "ad/cppgtfs/gtfs/Feed.h"
|
||||
#include "pfaedle/gtfs/Feed.h"
|
||||
#include "pfaedle/gtfs/StopTime.h"
|
||||
#include "pfaedle/router/TripTrie.h"
|
||||
|
||||
using pfaedle::gtfs::Trip;
|
||||
using pfaedle::router::TripTrie;
|
||||
|
||||
// _____________________________________________________________________________
|
||||
bool TripTrie::addTrip(pfaedle::gtfs::Trip* trip, const RoutingAttrs& rAttrs,
|
||||
template <typename TRIP>
|
||||
bool TripTrie<TRIP>::addTrip(TRIP* trip, const RoutingAttrs& rAttrs,
|
||||
bool timeEx, bool degen) {
|
||||
if (!degen) return add(trip, rAttrs, timeEx);
|
||||
|
||||
|
|
@ -31,7 +31,8 @@ bool TripTrie::addTrip(pfaedle::gtfs::Trip* trip, const RoutingAttrs& rAttrs,
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
bool TripTrie::add(pfaedle::gtfs::Trip* trip, const RoutingAttrs& rAttrs,
|
||||
template <typename TRIP>
|
||||
bool TripTrie<TRIP>::add(TRIP* trip, const RoutingAttrs& rAttrs,
|
||||
bool timeEx) {
|
||||
if (trip->getStopTimes().size() == 0) return false;
|
||||
|
||||
|
|
@ -92,7 +93,8 @@ bool TripTrie::add(pfaedle::gtfs::Trip* trip, const RoutingAttrs& rAttrs,
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
size_t TripTrie::get(pfaedle::gtfs::Trip* trip, bool timeEx) {
|
||||
template <typename TRIP>
|
||||
size_t TripTrie<TRIP>::get(TRIP* trip, bool timeEx) {
|
||||
if (trip->getStopTimes().size() == 0) return false;
|
||||
|
||||
int startSecs = trip->getStopTimes().front().getDepartureTime().seconds();
|
||||
|
|
@ -137,7 +139,8 @@ size_t TripTrie::get(pfaedle::gtfs::Trip* trip, bool timeEx) {
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
size_t TripTrie::insert(const ad::cppgtfs::gtfs::Stop* stop,
|
||||
template <typename TRIP>
|
||||
size_t TripTrie<TRIP>::insert(const ad::cppgtfs::gtfs::Stop* stop,
|
||||
const RoutingAttrs& rAttrs, const POINT& pos, int time,
|
||||
bool arr, size_t parent) {
|
||||
_nds.emplace_back(TripTrieNd{stop,
|
||||
|
|
@ -158,12 +161,14 @@ size_t TripTrie::insert(const ad::cppgtfs::gtfs::Stop* stop,
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const std::vector<pfaedle::router::TripTrieNd>& TripTrie::getNds() const {
|
||||
template <typename TRIP>
|
||||
const std::vector<pfaedle::router::TripTrieNd>& TripTrie<TRIP>::getNds() const {
|
||||
return _nds;
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
size_t TripTrie::getMatchChild(size_t parentNid, const std::string& stopName,
|
||||
template <typename TRIP>
|
||||
size_t TripTrie<TRIP>::getMatchChild(size_t parentNid, const std::string& stopName,
|
||||
const std::string& platform, POINT pos, int time,
|
||||
bool timeEx) const {
|
||||
for (size_t child : _nds[parentNid].childs) {
|
||||
|
|
@ -179,7 +184,8 @@ size_t TripTrie::getMatchChild(size_t parentNid, const std::string& stopName,
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void TripTrie::toDot(std::ostream& os, const std::string& rootName,
|
||||
template <typename TRIP>
|
||||
void TripTrie<TRIP>::toDot(std::ostream& os, const std::string& rootName,
|
||||
size_t gid) const {
|
||||
os << "digraph triptrie" << gid << " {";
|
||||
|
||||
|
|
@ -208,12 +214,14 @@ void TripTrie::toDot(std::ostream& os, const std::string& rootName,
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const std::map<size_t, std::vector<pfaedle::gtfs::Trip*>>&
|
||||
TripTrie::getNdTrips() const {
|
||||
template <typename TRIP>
|
||||
const std::map<size_t, std::vector<TRIP*>>&
|
||||
TripTrie<TRIP>::getNdTrips() const {
|
||||
return _ndTrips;
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const pfaedle::router::TripTrieNd& TripTrie::getNd(size_t nid) const {
|
||||
template <typename TRIP>
|
||||
const pfaedle::router::TripTrieNd& TripTrie<TRIP>::getNd(size_t nid) const {
|
||||
return _nds[nid];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue