* speed up hop-to-hop calculations

* better and faster trip clustering: trip tries
* add --write-colors to extract line colors from OSM data
* refactor config parameter names, update default pfaedle.cfg
* add --stats for writing a stats.json file
* add --no-fast-hops, --no-a-star, --no-trie for debugging
* general refactoring
This commit is contained in:
Patrick Brosi 2022-01-03 22:27:59 +01:00
parent f1822868c5
commit 4c29892658
126 changed files with 14576 additions and 12196 deletions

View file

@ -6,7 +6,6 @@
#define PFAEDLE_GTFS_FEED_H_
#include <string>
#include "Route.h"
#include "Service.h"
#include "ShapeContainer.h"
#include "StopTime.h"
@ -21,14 +20,15 @@ namespace pfaedle {
namespace gtfs {
typedef ad::cppgtfs::gtfs::FeedB<
ad::cppgtfs::gtfs::Agency, Route, ad::cppgtfs::gtfs::Stop, Service,
StopTime, Shape, ad::cppgtfs::gtfs::Fare, ad::cppgtfs::gtfs::Container,
ad::cppgtfs::gtfs::ContContainer, ad::cppgtfs::gtfs::NullContainer,
ad::cppgtfs::gtfs::ContContainer, ad::cppgtfs::gtfs::ContContainer,
ShapeContainer, ad::cppgtfs::gtfs::NullContainer>
ad::cppgtfs::gtfs::Agency, ad::cppgtfs::gtfs::Route,
ad::cppgtfs::gtfs::Stop, Service, StopTime, Shape, ad::cppgtfs::gtfs::Fare,
ad::cppgtfs::gtfs::Container, ad::cppgtfs::gtfs::Container,
ad::cppgtfs::gtfs::NullContainer, ad::cppgtfs::gtfs::ContContainer,
ad::cppgtfs::gtfs::ContContainer, ShapeContainer,
ad::cppgtfs::gtfs::Container>
Feed;
typedef ad::cppgtfs::gtfs::TripB<StopTime<ad::cppgtfs::gtfs::Stop>, Service,
Route, Shape>
ad::cppgtfs::gtfs::Route, Shape>
Trip;
} // namespace gtfs

View file

@ -1,61 +0,0 @@
// Copyright 2016, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
#ifndef PFAEDLE_GTFS_ROUTE_H_
#define PFAEDLE_GTFS_ROUTE_H_
#include <stdint.h>
#include <algorithm>
#include <iomanip>
#include <set>
#include <sstream>
#include <string>
#include "ad/cppgtfs/gtfs/Agency.h"
#include "ad/cppgtfs/gtfs/Route.h"
#include "util/Misc.h"
using std::exception;
using std::string;
namespace pfaedle {
namespace gtfs {
class Route {
public:
typedef Route* Ref;
static std::string getId(Ref r) { return r->getId(); }
Route() {}
Route(const string& id, ad::cppgtfs::gtfs::Agency* agency,
const string& short_name, const string& long_name, const string& desc,
ad::cppgtfs::gtfs::flat::Route::TYPE type, const string& url,
uint32_t color, uint32_t text_color)
: _id(id), _short_name(short_name), _long_name(long_name), _type(type) {
UNUSED(agency);
UNUSED(desc);
UNUSED(url);
UNUSED(color);
UNUSED(text_color);
}
const std::string& getId() const { return _id; }
const std::string& getShortName() const { return _short_name; }
const std::string& getLongName() const { return _long_name; }
ad::cppgtfs::gtfs::flat::Route::TYPE getType() const { return _type; }
private:
string _id;
string _short_name;
string _long_name;
ad::cppgtfs::gtfs::flat::Route::TYPE _type;
};
} // namespace gtfs
} // namespace pfaedle
#endif // PFAEDLE_GTFS_ROUTE_H_

View file

@ -45,15 +45,15 @@ bool ShapeContainer<T>::remove(const std::string& id) {
// ____________________________________________________________________________
template <typename T>
T* ShapeContainer<T>::get(const std::string& id) {
if (!has(id)) return 0;
return reinterpret_cast<T*>(1);
UNUSED(id);
return reinterpret_cast<T*>(0);
}
// ____________________________________________________________________________
template <typename T>
const T* ShapeContainer<T>::get(const std::string& id) const {
if (!has(id)) return 0;
return reinterpret_cast<T*>(1);
UNUSED(id);
return reinterpret_cast<T*>(0);
}
// ____________________________________________________________________________

View file

@ -27,14 +27,11 @@ class StopTime {
ad::cppgtfs::gtfs::flat::StopTime::PU_DO_TYPE put,
ad::cppgtfs::gtfs::flat::StopTime::PU_DO_TYPE dot, float distTrav,
bool isTp)
: _s(s), _sequence(seq), _dist(distTrav) {
UNUSED(at);
UNUSED(dt);
: _s(s), _sequence(seq), _dist(distTrav), _at(at), _dt(dt), _isTp(isTp) {
UNUSED(hs);
UNUSED(put);
UNUSED(dot);
UNUSED(distTrav);
UNUSED(isTp);
}
const typename StopT::Ref getStop() const { return _s; }
@ -42,20 +39,23 @@ class StopTime {
void setShapeDistanceTravelled(double d) { _dist = d; }
ad::cppgtfs::gtfs::Time getArrivalTime() const {
return ad::cppgtfs::gtfs::Time(0, 0, 0);
return _at;
}
ad::cppgtfs::gtfs::Time getDepartureTime() const {
return ad::cppgtfs::gtfs::Time(0, 0, 0);
return _dt;
}
float getShapeDistanceTravelled() const { return _dist; }
uint16_t getSeq() const { return _sequence; }
bool isTp() const { return _isTp; }
private:
typename StopT::Ref _s;
uint32_t _sequence;
float _dist;
ad::cppgtfs::gtfs::Time _at, _dt;
bool _isTp;
};
template <typename StopTimeT>

View file

@ -13,13 +13,13 @@
#include "ad/util/CsvWriter.h"
#include "pfaedle/gtfs/Writer.h"
using ad::util::CsvWriter;
using ad::cppgtfs::Parser;
using pfaedle::gtfs::Writer;
using ad::util::CsvWriter;
using pfaedle::getTmpFName;
using pfaedle::gtfs::Writer;
// ____________________________________________________________________________
bool Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const {
void Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const {
std::ofstream fs;
std::ifstream is;
std::string gtfsPath(path);
@ -59,8 +59,7 @@ bool Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const {
if (!fs.good()) cannotWrite(curFile, curFileTg);
writeCalendar(sourceFeed, &fs);
fs.close();
if (std::rename(curFile.c_str(), curFileTg.c_str()))
cannotWrite(curFileTg);
if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg);
}
is.open((sourceFeed->getPath() + "/calendar_dates.txt").c_str());
@ -72,8 +71,7 @@ bool Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const {
if (!fs.good()) cannotWrite(curFile, curFileTg);
writeCalendarDates(sourceFeed, &fs);
fs.close();
if (std::rename(curFile.c_str(), curFileTg.c_str()))
cannotWrite(curFileTg);
if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg);
}
is.open((sourceFeed->getPath() + "/transfers.txt").c_str());
@ -85,8 +83,7 @@ bool Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const {
if (!fs.good()) cannotWrite(curFile, curFileTg);
writeTransfers(sourceFeed, &fs);
fs.close();
if (std::rename(curFile.c_str(), curFileTg.c_str()))
cannotWrite(curFileTg);
if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg);
}
is.open((sourceFeed->getPath() + "/fare_attributes.txt").c_str());
@ -98,8 +95,7 @@ bool Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const {
if (!fs.good()) cannotWrite(curFile, curFileTg);
writeFares(sourceFeed, &fs);
fs.close();
if (std::rename(curFile.c_str(), curFileTg.c_str()))
cannotWrite(curFileTg);
if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg);
}
is.open((sourceFeed->getPath() + "/fare_rules.txt").c_str());
@ -111,8 +107,7 @@ bool Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const {
if (!fs.good()) cannotWrite(curFile, curFileTg);
writeFareRules(sourceFeed, &fs);
fs.close();
if (std::rename(curFile.c_str(), curFileTg.c_str()))
cannotWrite(curFileTg);
if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg);
}
is.close();
@ -142,14 +137,14 @@ bool Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const {
if (!fs.good()) cannotWrite(curFile, curFileTg);
writeFrequencies(sourceFeed, &fs);
fs.close();
if (std::rename(curFile.c_str(), curFileTg.c_str()))
cannotWrite(curFileTg);
if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg);
}
is.close();
curFile = getTmpFName(gtfsPath, "stop_times.txt");
curFileTg = gtfsPath + "/stop_times.txt";
fs.open(curFile.c_str());
if (!fs.good()) cannotWrite(curFile, curFileTg);
writeStopTimes(sourceFeed, &fs);
fs.close();
@ -163,15 +158,12 @@ bool Writer::write(gtfs::Feed* sourceFeed, const std::string& path) const {
if (!fs.good()) cannotWrite(curFile, curFileTg);
writeFeedInfo(sourceFeed, &fs);
fs.close();
if (std::rename(curFile.c_str(), curFileTg.c_str()))
cannotWrite(curFileTg);
if (std::rename(curFile.c_str(), curFileTg.c_str())) cannotWrite(curFileTg);
}
return true;
}
// ____________________________________________________________________________
bool Writer::writeFeedInfo(gtfs::Feed* f, std::ostream* os) const {
void Writer::writeFeedInfo(gtfs::Feed* f, std::ostream* os) const {
auto csvw = ad::cppgtfs::Writer::getFeedInfoCsvw(os);
csvw.flushLine();
csvw.writeString(f->getPublisherName());
@ -187,12 +179,10 @@ bool Writer::writeFeedInfo(gtfs::Feed* f, std::ostream* os) const {
csvw.skip();
csvw.writeString(f->getVersion());
csvw.flushLine();
return true;
}
// ____________________________________________________________________________
bool Writer::writeAgency(gtfs::Feed* sourceFeed, std::ostream* os) const {
void Writer::writeAgency(gtfs::Feed* sourceFeed, std::ostream* os) const {
std::ifstream fs;
fs.open((sourceFeed->getPath() + "/agency.txt").c_str());
@ -210,12 +200,10 @@ bool Writer::writeAgency(gtfs::Feed* sourceFeed, std::ostream* os) const {
w.writeAgency(fa, &csvw);
}
fs.close();
return true;
}
// ____________________________________________________________________________
bool Writer::writeStops(gtfs::Feed* sourceFeed, std::ostream* os) const {
void Writer::writeStops(gtfs::Feed* sourceFeed, std::ostream* os) const {
std::ifstream fs;
fs.open((sourceFeed->getPath() + "/stops.txt").c_str());
@ -233,35 +221,22 @@ bool Writer::writeStops(gtfs::Feed* sourceFeed, std::ostream* os) const {
w.writeStop(s, &csvw);
}
fs.close();
return true;
}
// ____________________________________________________________________________
bool Writer::writeRoutes(gtfs::Feed* sourceFeed, std::ostream* os) const {
std::ifstream fs;
fs.open((sourceFeed->getPath() + "/routes.txt").c_str());
CsvParser csvp(&fs);
Parser p;
void Writer::writeRoutes(gtfs::Feed* sourceFeed, std::ostream* os) const {
ad::cppgtfs::Writer w;
CsvWriter csvw = ad::cppgtfs::Writer::getRoutesCsvw(os);
csvw.flushLine();
ad::cppgtfs::gtfs::flat::Route s;
auto flds = Parser::getRouteFlds(&csvp);
while (p.nextRoute(&csvp, &s, flds)) {
w.writeRoute(s, &csvw);
for (auto r : sourceFeed->getRoutes()) {
w.writeRoute(r.second->getFlat(), &csvw);
}
fs.close();
return true;
}
// ____________________________________________________________________________
bool Writer::writeCalendar(gtfs::Feed* sourceFeed, std::ostream* os) const {
void Writer::writeCalendar(gtfs::Feed* sourceFeed, std::ostream* os) const {
std::ifstream fs;
fs.open((sourceFeed->getPath() + "/calendar.txt").c_str());
@ -279,12 +254,10 @@ bool Writer::writeCalendar(gtfs::Feed* sourceFeed, std::ostream* os) const {
w.writeCalendar(c, &csvw);
}
fs.close();
return true;
}
// ____________________________________________________________________________
bool Writer::writeCalendarDates(gtfs::Feed* sourceFeed,
void Writer::writeCalendarDates(gtfs::Feed* sourceFeed,
std::ostream* os) const {
std::ifstream fs;
fs.open((sourceFeed->getPath() + "/calendar_dates.txt").c_str());
@ -303,12 +276,10 @@ bool Writer::writeCalendarDates(gtfs::Feed* sourceFeed,
w.writeCalendarDate(c, &csvw);
}
fs.close();
return true;
}
// ____________________________________________________________________________
bool Writer::writeFrequencies(gtfs::Feed* sourceFeed, std::ostream* os) const {
void Writer::writeFrequencies(gtfs::Feed* sourceFeed, std::ostream* os) const {
std::ifstream fs;
fs.open((sourceFeed->getPath() + "/frequencies.txt").c_str());
@ -326,12 +297,10 @@ bool Writer::writeFrequencies(gtfs::Feed* sourceFeed, std::ostream* os) const {
w.writeFrequency(f, &csvw);
}
fs.close();
return true;
}
// ____________________________________________________________________________
bool Writer::writeTransfers(gtfs::Feed* sourceFeed, std::ostream* os) const {
void Writer::writeTransfers(gtfs::Feed* sourceFeed, std::ostream* os) const {
std::ifstream fs;
fs.open((sourceFeed->getPath() + "/transfers.txt").c_str());
@ -349,12 +318,10 @@ bool Writer::writeTransfers(gtfs::Feed* sourceFeed, std::ostream* os) const {
w.writeTransfer(t, &csvw);
}
fs.close();
return true;
}
// ____________________________________________________________________________
bool Writer::writeFares(gtfs::Feed* sourceFeed, std::ostream* os) const {
void Writer::writeFares(gtfs::Feed* sourceFeed, std::ostream* os) const {
std::ifstream fs;
fs.open((sourceFeed->getPath() + "/fare_attributes.txt").c_str());
@ -372,12 +339,10 @@ bool Writer::writeFares(gtfs::Feed* sourceFeed, std::ostream* os) const {
w.writeFare(f, &csvw);
}
fs.close();
return true;
}
// ____________________________________________________________________________
bool Writer::writeFareRules(gtfs::Feed* sourceFeed, std::ostream* os) const {
void Writer::writeFareRules(gtfs::Feed* sourceFeed, std::ostream* os) const {
std::ifstream fs;
fs.open((sourceFeed->getPath() + "/fare_rules.txt").c_str());
@ -395,12 +360,10 @@ bool Writer::writeFareRules(gtfs::Feed* sourceFeed, std::ostream* os) const {
w.writeFareRule(f, &csvw);
}
fs.close();
return true;
}
// ____________________________________________________________________________
bool Writer::writeShapes(gtfs::Feed* sourceFeed, std::ostream* os) const {
void Writer::writeShapes(gtfs::Feed* sourceFeed, std::ostream* os) const {
std::ifstream fs;
fs.open((sourceFeed->getPath() + "/shapes.txt").c_str());
@ -439,8 +402,6 @@ bool Writer::writeShapes(gtfs::Feed* sourceFeed, std::ostream* os) const {
}
fs.close();
return true;
}
// ____________________________________________________________________________
@ -460,7 +421,7 @@ bool Writer::writeTrips(gtfs::Feed* sourceFeed, std::ostream* os) const {
}
// ____________________________________________________________________________
bool Writer::writeStopTimes(gtfs::Feed* sourceFeed, std::ostream* os) const {
void Writer::writeStopTimes(gtfs::Feed* sourceFeed, std::ostream* os) const {
std::ifstream fs;
fs.open((sourceFeed->getPath() + "/stop_times.txt").c_str());
@ -491,8 +452,6 @@ bool Writer::writeStopTimes(gtfs::Feed* sourceFeed, std::ostream* os) const {
w.writeStopTime(st, &csvw);
}
fs.close();
return true;
}
// ___________________________________________________________________________
@ -508,4 +467,3 @@ void Writer::cannotWrite(const std::string& file, const std::string& file2) {
ss << "(temporary file for " << file2 << ") Could not write to file";
throw ad::cppgtfs::WriterException(ss.str(), file);
}

View file

@ -16,22 +16,22 @@ class Writer {
public:
Writer() {}
bool write(Feed* sourceFeed, const std::string& path) const;
void write(Feed* sourceFeed, const std::string& path) const;
private:
bool writeFeedInfo(Feed* f, std::ostream* os) const;
bool writeAgency(Feed* f, std::ostream* os) const;
bool writeStops(Feed* f, std::ostream* os) const;
bool writeRoutes(Feed* f, std::ostream* os) const;
bool writeCalendar(Feed* f, std::ostream* os) const;
bool writeCalendarDates(Feed* f, std::ostream* os) const;
bool writeFrequencies(Feed* f, std::ostream* os) const;
bool writeTransfers(Feed* f, std::ostream* os) const;
bool writeFares(Feed* f, std::ostream* os) const;
bool writeFareRules(Feed* f, std::ostream* os) const;
bool writeShapes(Feed* f, std::ostream* os) const;
void writeFeedInfo(Feed* f, std::ostream* os) const;
void writeAgency(Feed* f, std::ostream* os) const;
void writeStops(Feed* f, std::ostream* os) const;
void writeRoutes(Feed* f, std::ostream* os) const;
void writeCalendar(Feed* f, std::ostream* os) const;
void writeCalendarDates(Feed* f, std::ostream* os) const;
void writeFrequencies(Feed* f, std::ostream* os) const;
void writeTransfers(Feed* f, std::ostream* os) const;
void writeFares(Feed* f, std::ostream* os) const;
void writeFareRules(Feed* f, std::ostream* os) const;
void writeShapes(Feed* f, std::ostream* os) const;
bool writeTrips(Feed* f, std::ostream* os) const;
bool writeStopTimes(Feed* f, std::ostream* os) const;
void writeStopTimes(Feed* f, std::ostream* os) const;
static void cannotWrite(const std::string& file, const std::string& file2);
static void cannotWrite(const std::string& file);