2018-06-09 17:14:08 +02:00
|
|
|
// Copyright 2018, University of Freiburg,
|
|
|
|
|
// Chair of Algorithms and Data Structures.
|
|
|
|
|
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
|
|
|
|
|
|
|
|
|
|
#ifndef PFAEDLE_ROUTER_SHAPEBUILDER_H_
|
|
|
|
|
#define PFAEDLE_ROUTER_SHAPEBUILDER_H_
|
|
|
|
|
|
2022-01-17 13:29:35 +01:00
|
|
|
#include <map>
|
2018-06-09 17:14:08 +02:00
|
|
|
#include <mutex>
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
2024-01-30 12:51:22 +01:00
|
|
|
|
2018-06-09 17:14:08 +02:00
|
|
|
#include "ad/cppgtfs/gtfs/Feed.h"
|
2018-08-10 16:42:38 +02:00
|
|
|
#include "pfaedle/Def.h"
|
2018-06-09 17:14:08 +02:00
|
|
|
#include "pfaedle/config/MotConfig.h"
|
|
|
|
|
#include "pfaedle/config/PfaedleConfig.h"
|
2019-01-10 16:52:59 +01:00
|
|
|
#include "pfaedle/gtfs/Feed.h"
|
2018-06-09 17:14:08 +02:00
|
|
|
#include "pfaedle/netgraph/Graph.h"
|
|
|
|
|
#include "pfaedle/osm/Restrictor.h"
|
|
|
|
|
#include "pfaedle/router/Misc.h"
|
|
|
|
|
#include "pfaedle/router/Router.h"
|
2022-01-03 22:27:59 +01:00
|
|
|
#include "pfaedle/router/Stats.h"
|
|
|
|
|
#include "pfaedle/router/TripTrie.h"
|
|
|
|
|
#include "pfaedle/statsimi-classifier/StatsimiClassifier.h"
|
2018-06-09 17:14:08 +02:00
|
|
|
#include "pfaedle/trgraph/Graph.h"
|
2018-08-10 16:42:38 +02:00
|
|
|
#include "util/geo/Geo.h"
|
2018-06-09 17:14:08 +02:00
|
|
|
|
|
|
|
|
namespace pfaedle {
|
|
|
|
|
namespace router {
|
|
|
|
|
|
2022-01-21 23:58:49 +01:00
|
|
|
typedef std::vector<TripTrie<pfaedle::gtfs::Trip>> TripForest;
|
2022-01-03 22:27:59 +01:00
|
|
|
typedef std::map<router::RoutingAttrs, TripForest> TripForests;
|
|
|
|
|
typedef std::pair<const ad::cppgtfs::gtfs::Stop*,
|
|
|
|
|
const ad::cppgtfs::gtfs::Stop*>
|
|
|
|
|
StopPair;
|
|
|
|
|
typedef std::unordered_map<const pfaedle::gtfs::Trip*, router::RoutingAttrs>
|
|
|
|
|
TripRAttrs;
|
|
|
|
|
typedef std::unordered_map<const trgraph::Edge*,
|
|
|
|
|
std::vector<const pfaedle::gtfs::Trip*>>
|
2018-06-09 17:14:08 +02:00
|
|
|
TrGraphEdgs;
|
2022-01-03 22:27:59 +01:00
|
|
|
typedef std::map<Route*, std::map<uint32_t, std::vector<gtfs::Trip*>>>
|
|
|
|
|
RouteRefColors;
|
|
|
|
|
typedef std::unordered_map<const ad::cppgtfs::gtfs::Stop*, EdgeCandGroup>
|
|
|
|
|
GrpCache;
|
2018-06-09 17:14:08 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Layer class for the router. Provides an interface for direct usage with
|
|
|
|
|
* GTFS data
|
|
|
|
|
*/
|
|
|
|
|
class ShapeBuilder {
|
|
|
|
|
public:
|
2022-01-03 22:27:59 +01:00
|
|
|
ShapeBuilder(
|
|
|
|
|
pfaedle::gtfs::Feed* feed, MOTs mots, const config::MotConfig& motCfg,
|
|
|
|
|
trgraph::Graph* g, router::FeedStops* stops, osm::Restrictor* restr,
|
|
|
|
|
const pfaedle::statsimiclassifier::StatsimiClassifier* classifier,
|
|
|
|
|
router::Router* router, const config::Config& cfg);
|
2018-06-09 17:14:08 +02:00
|
|
|
|
2022-01-03 22:27:59 +01:00
|
|
|
Stats shapeify(pfaedle::netgraph::Graph* outNg);
|
2018-06-09 17:14:08 +02:00
|
|
|
|
|
|
|
|
router::FeedStops* getFeedStops();
|
|
|
|
|
|
2022-01-03 22:27:59 +01:00
|
|
|
// shape single trip
|
|
|
|
|
std::pair<std::vector<LINE>, Stats> shapeL(pfaedle::gtfs::Trip* trip);
|
2018-06-09 17:14:08 +02:00
|
|
|
|
2022-01-21 23:58:49 +01:00
|
|
|
std::map<size_t, EdgeListHops> shapeify(
|
|
|
|
|
const TripTrie<pfaedle::gtfs::Trip>* trie, HopCache* hopCache) const;
|
2022-01-03 22:27:59 +01:00
|
|
|
EdgeListHops shapeify(pfaedle::gtfs::Trip* trip);
|
2018-06-09 17:14:08 +02:00
|
|
|
|
|
|
|
|
const trgraph::Graph* getGraph() const;
|
|
|
|
|
|
2022-01-03 22:27:59 +01:00
|
|
|
static void getGtfsBox(const pfaedle::gtfs::Feed* feed, const MOTs& mots,
|
2019-01-10 16:52:59 +01:00
|
|
|
const std::string& tid, bool dropShapes,
|
2022-01-17 13:29:35 +01:00
|
|
|
osm::BBoxIdx* box, double maxSpeed,
|
2024-01-30 12:51:22 +01:00
|
|
|
std::vector<double>* hopDists, uint8_t verbosity);
|
2018-06-09 17:14:08 +02:00
|
|
|
|
|
|
|
|
private:
|
2022-01-03 22:27:59 +01:00
|
|
|
pfaedle::gtfs::Feed* _feed;
|
2018-06-09 17:14:08 +02:00
|
|
|
MOTs _mots;
|
|
|
|
|
config::MotConfig _motCfg;
|
|
|
|
|
config::Config _cfg;
|
2019-02-03 12:48:48 +01:00
|
|
|
trgraph::Graph* _g;
|
|
|
|
|
router::FeedStops* _stops;
|
2018-06-09 17:14:08 +02:00
|
|
|
|
2022-01-03 22:27:59 +01:00
|
|
|
EdgeCandGroup _emptyNCG;
|
2018-06-09 17:14:08 +02:00
|
|
|
|
2022-01-03 22:27:59 +01:00
|
|
|
size_t _curShpCnt;
|
2018-06-09 17:14:08 +02:00
|
|
|
|
|
|
|
|
std::mutex _shpMutex;
|
|
|
|
|
|
|
|
|
|
TripRAttrs _rAttrs;
|
|
|
|
|
|
2019-02-03 12:48:48 +01:00
|
|
|
osm::Restrictor* _restr;
|
2022-01-03 22:27:59 +01:00
|
|
|
const pfaedle::statsimiclassifier::StatsimiClassifier* _classifier;
|
|
|
|
|
GrpCache _grpCache;
|
|
|
|
|
|
|
|
|
|
router::Router* _router;
|
|
|
|
|
|
|
|
|
|
TripForests clusterTrips(pfaedle::gtfs::Feed* f, MOTs mots);
|
|
|
|
|
void buildNetGraph(TrGraphEdgs* edgs, pfaedle::netgraph::Graph* ng) const;
|
|
|
|
|
|
|
|
|
|
std::string getFreeShapeId(pfaedle::gtfs::Trip* t);
|
|
|
|
|
ad::cppgtfs::gtfs::Shape getGtfsShape(const EdgeListHops& shp,
|
|
|
|
|
pfaedle::gtfs::Trip* t,
|
2024-01-30 12:51:22 +01:00
|
|
|
size_t numOthers,
|
2022-01-03 22:27:59 +01:00
|
|
|
const RoutingAttrs& rAttrs,
|
|
|
|
|
std::vector<float>* hopDists,
|
|
|
|
|
uint32_t* bestColor);
|
|
|
|
|
|
|
|
|
|
void setShape(pfaedle::gtfs::Trip* t, const ad::cppgtfs::gtfs::Shape& s,
|
|
|
|
|
const std::vector<float>& dists);
|
2018-06-09 17:14:08 +02:00
|
|
|
|
2022-01-03 22:27:59 +01:00
|
|
|
EdgeCandGroup getEdgCands(const ad::cppgtfs::gtfs::Stop* s) const;
|
2018-06-09 17:14:08 +02:00
|
|
|
|
2022-01-21 23:58:49 +01:00
|
|
|
router::EdgeCandMap getECM(const TripTrie<pfaedle::gtfs::Trip>* trie) const;
|
2022-01-03 22:27:59 +01:00
|
|
|
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);
|
2022-01-21 23:58:49 +01:00
|
|
|
std::map<size_t, router::EdgeListHops> route(
|
|
|
|
|
const TripTrie<pfaedle::gtfs::Trip>* trie, const EdgeCandMap& ecm,
|
|
|
|
|
HopCache* hopCache) const;
|
2022-01-11 17:32:50 +01:00
|
|
|
double emWeight(double mDist) const;
|
|
|
|
|
|
2022-01-03 22:27:59 +01:00
|
|
|
void buildCandCache(const TripForests& clusters);
|
|
|
|
|
void buildIndex();
|
2018-06-09 17:14:08 +02:00
|
|
|
|
2022-01-03 22:27:59 +01:00
|
|
|
std::vector<LINE> getGeom(const EdgeListHops& shp, const RoutingAttrs& rAttrs,
|
2024-01-30 12:51:22 +01:00
|
|
|
std::map<uint32_t, double>* colors, Trip* t,
|
|
|
|
|
size_t numOthers) const;
|
2022-01-03 22:27:59 +01:00
|
|
|
double timePen(int candTime, int schedTime) const;
|
2018-06-09 17:14:08 +02:00
|
|
|
|
2022-01-03 22:27:59 +01:00
|
|
|
LINE getLine(const EdgeListHop& hop, const RoutingAttrs&,
|
|
|
|
|
std::map<uint32_t, double>* colMap) const;
|
|
|
|
|
LINE getLine(const trgraph::Edge* edg) const;
|
|
|
|
|
std::vector<float> getMeasure(const std::vector<LINE>& lines) const;
|
2018-06-09 17:14:08 +02:00
|
|
|
|
2022-01-03 22:27:59 +01:00
|
|
|
trgraph::Edge* deg2reachable(trgraph::Edge* e,
|
|
|
|
|
std::set<trgraph::Edge*> edgs) const;
|
2018-06-09 17:14:08 +02:00
|
|
|
|
2022-01-03 22:27:59 +01:00
|
|
|
EdgeCandGroup timeExpand(const EdgeCand& ec, int time) const;
|
|
|
|
|
|
|
|
|
|
std::set<uint32_t> getColorMatch(const trgraph::Edge* e,
|
|
|
|
|
const RoutingAttrs& rAttrs) const;
|
|
|
|
|
|
|
|
|
|
void updateRouteColors(const RouteRefColors& c);
|
|
|
|
|
|
|
|
|
|
uint32_t getTextColor(uint32_t c) const;
|
|
|
|
|
|
|
|
|
|
void writeTransitGraph(const router::EdgeListHops& shp, TrGraphEdgs* edgs,
|
|
|
|
|
const std::vector<pfaedle::gtfs::Trip*>& trips) const;
|
|
|
|
|
|
|
|
|
|
void shapeWorker(
|
|
|
|
|
const std::vector<const TripForest*>* tries, std::atomic<size_t>* at,
|
|
|
|
|
std::map<std::string, size_t>* shpUsage,
|
|
|
|
|
std::map<Route*, std::map<uint32_t, std::vector<gtfs::Trip*>>>*,
|
|
|
|
|
TrGraphEdgs* gtfsGraph);
|
|
|
|
|
|
|
|
|
|
void edgCandWorker(std::vector<const Stop*>* stops, GrpCache* cache);
|
|
|
|
|
void clusterWorker(const std::vector<RoutingAttrs>* rAttrs,
|
|
|
|
|
const std::map<RoutingAttrs, std::vector<Trip*>>* trips,
|
|
|
|
|
TripForests* forest);
|
|
|
|
|
|
|
|
|
|
pfaedle::trgraph::EdgeGrid _eGrid;
|
|
|
|
|
pfaedle::trgraph::NodeGrid _nGrid;
|
2018-06-09 17:14:08 +02:00
|
|
|
};
|
2022-01-03 22:27:59 +01:00
|
|
|
|
2018-06-09 17:14:08 +02:00
|
|
|
} // namespace router
|
|
|
|
|
} // namespace pfaedle
|
|
|
|
|
|
|
|
|
|
#endif // PFAEDLE_ROUTER_SHAPEBUILDER_H_
|