// Copyright 2018, University of Freiburg, // Chair of Algorithms and Data Structures. // Authors: Patrick Brosi #ifndef PFAEDLE_ROUTER_SHAPEBUILDER_H_ #define PFAEDLE_ROUTER_SHAPEBUILDER_H_ #include #include #include #include #include #include #include #include "ad/cppgtfs/gtfs/Feed.h" #include "pfaedle/Def.h" #include "pfaedle/config/MotConfig.h" #include "pfaedle/config/PfaedleConfig.h" #include "pfaedle/gtfs/Feed.h" #include "pfaedle/netgraph/Graph.h" #include "pfaedle/osm/Restrictor.h" #include "pfaedle/router/Misc.h" #include "pfaedle/router/Router.h" #include "pfaedle/router/Stats.h" #include "pfaedle/router/TripTrie.h" #include "pfaedle/statsimi-classifier/StatsimiClassifier.h" #include "pfaedle/trgraph/Graph.h" #include "util/geo/Geo.h" namespace pfaedle { namespace router { typedef std::vector> TripForest; typedef std::map TripForests; typedef std::pair StopPair; typedef std::unordered_map TripRAttrs; typedef std::unordered_map> TrGraphEdgs; typedef std::map>> RouteRefColors; typedef std::unordered_map GrpCache; /* * Layer class for the router. Provides an interface for direct usage with * GTFS data */ class ShapeBuilder { public: 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); Stats shapeify(pfaedle::netgraph::Graph* outNg); router::FeedStops* getFeedStops(); // shape single trip std::pair, Stats> shapeL(pfaedle::gtfs::Trip* trip); std::map shapeify( const TripTrie* trie, HopCache* hopCache) const; EdgeListHops shapeify(pfaedle::gtfs::Trip* trip); const trgraph::Graph* getGraph() const; static void getGtfsBox(const pfaedle::gtfs::Feed* feed, const MOTs& mots, const std::string& tid, bool dropShapes, osm::BBoxIdx* box, double maxSpeed, std::vector* hopDists, uint8_t verbosity); private: pfaedle::gtfs::Feed* _feed; MOTs _mots; config::MotConfig _motCfg; config::Config _cfg; trgraph::Graph* _g; router::FeedStops* _stops; EdgeCandGroup _emptyNCG; size_t _curShpCnt; std::mutex _shpMutex; TripRAttrs _rAttrs; osm::Restrictor* _restr; 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, size_t numOthers, const RoutingAttrs& rAttrs, std::vector* hopDists, uint32_t* bestColor); void setShape(pfaedle::gtfs::Trip* t, const ad::cppgtfs::gtfs::Shape& s, const std::vector& dists); EdgeCandGroup getEdgCands(const ad::cppgtfs::gtfs::Stop* s) const; router::EdgeCandMap getECM(const TripTrie* trie) const; std::vector getTransTimes(pfaedle::gtfs::Trip* trip) const; std::vector 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 route( const TripTrie* trie, const EdgeCandMap& ecm, HopCache* hopCache) const; double emWeight(double mDist) const; void buildCandCache(const TripForests& clusters); void buildIndex(); std::vector getGeom(const EdgeListHops& shp, const RoutingAttrs& rAttrs, std::map* colors, Trip* t, size_t numOthers) const; double timePen(int candTime, int schedTime) const; LINE getLine(const EdgeListHop& hop, const RoutingAttrs&, std::map* colMap) const; LINE getLine(const trgraph::Edge* edg) const; std::vector getMeasure(const std::vector& lines) const; trgraph::Edge* deg2reachable(trgraph::Edge* e, std::set edgs) const; EdgeCandGroup timeExpand(const EdgeCand& ec, int time) const; std::set 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& trips) const; void shapeWorker( const std::vector* tries, std::atomic* at, std::map* shpUsage, std::map>>*, TrGraphEdgs* gtfsGraph); void edgCandWorker(std::vector* stops, GrpCache* cache); void clusterWorker(const std::vector* rAttrs, const std::map>* trips, TripForests* forest); pfaedle::trgraph::EdgeGrid _eGrid; pfaedle::trgraph::NodeGrid _nGrid; }; } // namespace router } // namespace pfaedle #endif // PFAEDLE_ROUTER_SHAPEBUILDER_H_