refactoring

This commit is contained in:
Patrick Brosi 2018-07-25 20:14:46 +02:00
parent 7f0443243c
commit 5703eb47bd
5 changed files with 58 additions and 23 deletions

View file

@ -45,7 +45,7 @@ osm/spain-latest.osm.pbf:
mkdir -p osm mkdir -p osm
wget http://download.geofabrik.de/europe/spain-latest.osm.pbf -O $@ wget http://download.geofabrik.de/europe/spain-latest.osm.pbf -O $@
osm/spain-latest.osm: osm/spain-latest.osm.pbf osmconvert osm/spain-latest.osm: osm/spain-latest.osm.pbf osmconvert
@# pre-filter to vitoria gasteiz @# pre-filter to vitoria gasteiz
osmconvert -b=-2.8661,42.7480,-2.4788,43.0237 $< > $@ osmconvert -b=-2.8661,42.7480,-2.4788,43.0237 $< > $@
@ -53,14 +53,14 @@ osm/baden-wuerttemberg-latest.osm.pbf:
mkdir -p osm mkdir -p osm
wget http://download.geofabrik.de/europe/germany/baden-wuerttemberg-latest.osm.pbf -O $@ wget http://download.geofabrik.de/europe/germany/baden-wuerttemberg-latest.osm.pbf -O $@
osm/baden-wuerttemberg-latest.osm: osm/baden-wuerttemberg-latest.osm.pbf osmconvert osm/baden-wuerttemberg-latest.osm: osm/baden-wuerttemberg-latest.osm.pbf osmconvert
osmconvert $< > $@ osmconvert $< > $@
osm/france-latest.osm.pbf: osm/france-latest.osm.pbf:
mkdir -p osm mkdir -p osm
wget http://download.geofabrik.de/europe/france-latest.osm.pbf -O $@ wget http://download.geofabrik.de/europe/france-latest.osm.pbf -O $@
osm/paris-latest.osm: osm/france-latest.osm.pbf osmconvert osm/paris-latest.osm: osm/france-latest.osm.pbf osmconvert
@# pre-filter to greater ile de france @# pre-filter to greater ile de france
osmconvert -b=0.374,47.651,4.241,50.261 $< > $@ osmconvert -b=0.374,47.651,4.241,50.261 $< > $@
@ -68,7 +68,7 @@ osm/europe-latest.osm.pbf:
mkdir -p osm mkdir -p osm
wget http://download.geofabrik.de/europe-latest.osm.pbf -O $@ wget http://download.geofabrik.de/europe-latest.osm.pbf -O $@
osm/switzerland-latest.osm: osm/europe-latest.osm.pbf osmconvert osm/switzerland-latest.osm: osm/europe-latest.osm.pbf osmconvert
@# pre-filter to greater switzerland @# pre-filter to greater switzerland
osmconvert -b=3.757,44.245,15.579,52.670 $< > $@ osmconvert -b=3.757,44.245,15.579,52.670 $< > $@
@ -87,21 +87,21 @@ gtfs/stuttgart/%.txt:
echo "* to brosi@cs.informatik.uni-freiburg.de to receive the password. " echo "* to brosi@cs.informatik.uni-freiburg.de to receive the password. "
echo "******************************************************************" echo "******************************************************************"
wget http://www.vvs.de/download/opendata/VVS_GTFS.zip --ask-password --user vvsopendata01 -O gtfs/stuttgart/gtfs.zip wget http://www.vvs.de/download/opendata/VVS_GTFS.zip --ask-password --user vvsopendata01 -O gtfs/stuttgart/gtfs.zip
cd gtfs/stuttgart && unzip gtfs.zip cd gtfs/stuttgart && unzip -o gtfs.zip
rm gtfs/stuttgart/gtfs.zip rm gtfs/stuttgart/gtfs.zip
gtfs/paris/%.txt: gtfs/paris/%.txt:
mkdir -p gtfs mkdir -p gtfs
mkdir -p gtfs/paris mkdir -p gtfs/paris
wget https://transitfeeds.com/p/stif/822/latest/download -O gtfs/paris/gtfs.zip wget https://transitfeeds.com/p/stif/822/latest/download -O gtfs/paris/gtfs.zip
cd gtfs/paris && unzip gtfs.zip cd gtfs/paris && unzip -o gtfs.zip
rm gtfs/paris/gtfs.zip rm gtfs/paris/gtfs.zip
gtfs/switzerland/%.txt: gtfs/switzerland/%.txt:
mkdir -p gtfs mkdir -p gtfs
mkdir -p gtfs/switzerland mkdir -p gtfs/switzerland
wget http://gtfs.geops.ch/dl/gtfs_complete.zip -O gtfs/switzerland/gtfs.zip wget http://gtfs.geops.ch/dl/gtfs_complete.zip -O gtfs/switzerland/gtfs.zip
cd gtfs/switzerland && unzip gtfs.zip cd gtfs/switzerland && unzip -o gtfs.zip
rm gtfs/switzerland/gtfs.zip rm gtfs/switzerland/gtfs.zip
osm/vitoria.osm: osm/spain-latest.osm gtfs/vitoria/stops.txt eval.cfg osm/vitoria.osm: osm/spain-latest.osm gtfs/vitoria/stops.txt eval.cfg

View file

@ -36,6 +36,7 @@ using pfaedle::config::ConfigReader;
using pfaedle::eval::Collector; using pfaedle::eval::Collector;
std::string getMotStr(const MOTs& mots); std::string getMotStr(const MOTs& mots);
std::string getFileNameMotStr(const MOTs& mots);
MOTs getContMots(const MotConfig& motCfg, const MOTs& mots); MOTs getContMots(const MotConfig& motCfg, const MOTs& mots);
// _____________________________________________________________________________ // _____________________________________________________________________________
@ -116,8 +117,11 @@ int main(int argc, char** argv) {
Collector ecoll(cfg.evalPath, dfBins); Collector ecoll(cfg.evalPath, dfBins);
for (const auto& motCfg : motCfgReader.getConfigs()) { for (const auto& motCfg : motCfgReader.getConfigs()) {
std::string filePost;
auto usedMots = getContMots(motCfg, cmdCfgMots); auto usedMots = getContMots(motCfg, cmdCfgMots);
if (!usedMots.size()) continue; if (!usedMots.size()) continue;
if (motCfgReader.getConfigs().size() > 1)
filePost = getFileNameMotStr(usedMots);
std::string motStr = getMotStr(usedMots); std::string motStr = getMotStr(usedMots);
LOG(INFO) << "Calculating shapes for mots " << motStr; LOG(INFO) << "Calculating shapes for mots " << motStr;
@ -125,7 +129,7 @@ int main(int argc, char** argv) {
ShapeBuilder shapeBuilder(&gtfs, cmdCfgMots, motCfg, &ecoll, cfg); ShapeBuilder shapeBuilder(&gtfs, cmdCfgMots, motCfg, &ecoll, cfg);
if (cfg.writeGraph) { if (cfg.writeGraph) {
LOG(INFO) << "Outputting graph.json..."; LOG(INFO) << "Outputting graph" + filePost + ".json...";
util::geo::output::GeoGraphJsonOutput out; util::geo::output::GeoGraphJsonOutput out;
std::ofstream fstr(cfg.dbgOutputPath + "/graph.json"); std::ofstream fstr(cfg.dbgOutputPath + "/graph.json");
out.print(*shapeBuilder.getGraph(), fstr); out.print(*shapeBuilder.getGraph(), fstr);
@ -155,9 +159,9 @@ int main(int argc, char** argv) {
shapeBuilder.shape(&ng); shapeBuilder.shape(&ng);
if (cfg.buildTransitGraph) { if (cfg.buildTransitGraph) {
LOG(INFO) << "Outputting trgraph.json...";
util::geo::output::GeoGraphJsonOutput out; util::geo::output::GeoGraphJsonOutput out;
std::ofstream fstr(cfg.dbgOutputPath + "/trgraph.json"); LOG(INFO) << "Outputting trgraph" + filePost + ".json...";
std::ofstream fstr(cfg.dbgOutputPath + "/trgraph" + filePost + ".json");
out.print(ng, fstr); out.print(ng, fstr);
fstr.close(); fstr.close();
} }
@ -187,6 +191,16 @@ std::string getMotStr(const MOTs& mots) {
return motStr; return motStr;
} }
// _____________________________________________________________________________
std::string getFileNameMotStr(const MOTs& mots) {
std::string motStr;
for (const auto& mot : mots) {
motStr += "-" + Route::getTypeString(mot);
}
return motStr;
}
// _____________________________________________________________________________ // _____________________________________________________________________________
MOTs getContMots(const MotConfig& motCfg, const MOTs& mots) { MOTs getContMots(const MotConfig& motCfg, const MOTs& mots) {
MOTs ret; MOTs ret;

View file

@ -26,20 +26,19 @@ static const char* AUTHORS = "Patrick Brosi <brosi@informatik.uni-freiburg.de>";
// _____________________________________________________________________________ // _____________________________________________________________________________
void ConfigReader::help(const char* bin) { void ConfigReader::help(const char* bin) {
std::cout std::cout
<< std::setfill(' ') << std::left << std::setfill(' ') << std::left << "pfaedle GTFS map matcher\n"
<< "pfaedle GTFS map matcher\n"
<< VERSION_FULL << " (built " << __DATE__ << " " << __TIME__ << ")\n\n" << VERSION_FULL << " (built " << __DATE__ << " " << __TIME__ << ")\n\n"
<< "(C) " << YEAR << " " << COPY << "\n" << "(C) " << YEAR << " " << COPY << "\n"
<< "Authors: " << AUTHORS << "\n\n" << "Authors: " << AUTHORS << "\n\n"
<< "Usage: " << "Usage: " << bin << " -x <OSM FILE> -c <CFG FILE> <GTFS FEED>\n\n"
<< bin
<< " -x <OSM FILE> -c <CFG FILE> <GTFS FEED>\n\n"
<< "Allowed options:\n\n" << "Allowed options:\n\n"
<< "General:\n" << "General:\n"
<< std::setw(35) << " -v [ --version ]" << std::setw(35) << " -v [ --version ]"
<< "print version\n" << "print version\n"
<< std::setw(35) << " -h [ --help ]" << std::setw(35) << " -h [ --help ]"
<< "show this help message\n" << "show this help message\n"
<< std::setw(35) << " -D [ --drop-shapes ]"
<< "drop shapes already present in the feed and recalculate them\n"
<< "\nInput:\n" << "\nInput:\n"
<< std::setw(35) << " -c [ --config ] arg" << std::setw(35) << " -c [ --config ] arg"
<< "pfaedle config file\n" << "pfaedle config file\n"
@ -68,7 +67,8 @@ void ConfigReader::help(const char* bin) {
<< std::setw(35) << " --write-graph" << std::setw(35) << " --write-graph"
<< "write routing graph as GeoJSON to <dbg-path>/graph.json\n" << "write routing graph as GeoJSON to <dbg-path>/graph.json\n"
<< std::setw(35) << " --write-cgraph" << std::setw(35) << " --write-cgraph"
<< "write combination graph as GeoJSON to <dbg-path>/combraph.json\n" << "if -T is set, write combination graph as GeoJSON to "
"<dbg-path>/combgraph.json\n"
<< std::setw(35) << " --method arg (=global)" << std::setw(35) << " --method arg (=global)"
<< "matching method to use, either 'global' (based on HMM), 'greedy' or " << "matching method to use, either 'global' (based on HMM), 'greedy' or "
"'greedy2'\n" "'greedy2'\n"

View file

@ -5,10 +5,11 @@
#ifndef PFAEDLE_NETGRAPH_EDGEPL_H_ #ifndef PFAEDLE_NETGRAPH_EDGEPL_H_
#define PFAEDLE_NETGRAPH_EDGEPL_H_ #define PFAEDLE_NETGRAPH_EDGEPL_H_
#include <map>
#include <set> #include <set>
#include <string> #include <string>
#include <map>
#include "ad/cppgtfs/gtfs/Feed.h" #include "ad/cppgtfs/gtfs/Feed.h"
#include "util/String.h"
#include "util/geo/GeoGraph.h" #include "util/geo/GeoGraph.h"
using util::geograph::GeoEdgePL; using util::geograph::GeoEdgePL;
@ -25,15 +26,26 @@ class EdgePL : public GeoEdgePL<float> {
public: public:
EdgePL() {} EdgePL() {}
EdgePL(const util::geo::FLine& l, const std::set<const Trip*>& trips) EdgePL(const util::geo::FLine& l, const std::set<const Trip*>& trips)
: _l(l), _trips(trips) {} : _l(l), _trips(trips) {
for (const auto t : _trips) {
_routeShortNames.insert(t->getRoute()->getShortName());
_tripShortNames.insert(t->getShortname());
}
}
const util::geo::FLine* getGeom() const { return &_l; } const util::geo::FLine* getGeom() const { return &_l; }
void getAttrs(std::map<std::string, std::string>* obj) const { void getAttrs(std::map<std::string, std::string>* obj) const {
(*obj)["numtrips"] = std::to_string(_trips.size()); (*obj)["num_trips"] = std::to_string(_trips.size());
(*obj)["route_short_names"] =
util::implode(_routeShortNames.begin(), _routeShortNames.end(), ", ");
(*obj)["trip_short_names"] =
util::implode(_tripShortNames.begin(), _tripShortNames.end(), ", ");
} }
private: private:
util::geo::FLine _l; util::geo::FLine _l;
std::set<const Trip*> _trips; std::set<const Trip*> _trips;
std::set<std::string> _routeShortNames;
std::set<std::string> _tripShortNames;
}; };
} // namespace netgraph } // namespace netgraph
} // namespace pfaedle } // namespace pfaedle

View file

@ -143,16 +143,25 @@ inline size_t editDist(const std::string& s1, const std::string& s2) {
} }
// _____________________________________________________________________________ // _____________________________________________________________________________
template <typename T> template <class Iter>
inline std::string implode(const std::vector<T>& vec, const char* del) { inline std::string implode(Iter begin, const Iter& end, const char* del) {
std::stringstream ss; std::stringstream ss;
for (size_t i = 0; i < vec.size(); i++) { size_t i = 0;
while (begin != end) {
if (i != 0) ss << del; if (i != 0) ss << del;
ss << vec[i]; ss << *begin;
begin++;
i++;
} }
return ss.str(); return ss.str();
} }
// _____________________________________________________________________________
template <typename T>
inline std::string implode(const std::vector<T>& vec, const char* del) {
return implode(vec.begin(), vec.end(), del);
}
} }
#endif // UTIL_STRING_H_ #endif // UTIL_STRING_H_