Skip to content

Commit

Permalink
add -W [ --warn ] flag to output warning messages, update cppgtfs
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbr committed Jan 30, 2024
1 parent a078b22 commit ad02526
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 27 deletions.
16 changes: 10 additions & 6 deletions src/pfaedle/PfaedleMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ enum class RetCode {
std::string getFileNameMotStr(const MOTs& mots);
std::vector<std::string> getCfgPaths(const Config& cfg);

// _____________________________________________________________________________
void gtfsWarnCb(std::string msg) { LOG(WARN) << msg; }

// _____________________________________________________________________________
int main(int argc, char** argv) {
// disable output buffering for standard output
Expand Down Expand Up @@ -136,7 +139,8 @@ int main(int argc, char** argv) {
LOG(INFO) << "Reading GTFS feed " << cfg.feedPaths[0] << " ...";
try {
ad::cppgtfs::Parser p(cfg.feedPaths[0], false,
cfg.parseAdditionalGTFSFields);
cfg.parseAdditionalGTFSFields,
cfg.verbosity ? gtfsWarnCb : 0);
p.parse(&gtfs[0]);
} catch (const ad::cppgtfs::ParserException& ex) {
LOG(ERROR) << "Could not parse input GTFS feed, reason was:";
Expand Down Expand Up @@ -193,7 +197,7 @@ int main(int argc, char** argv) {

for (size_t i = 0; i < cfg.feedPaths.size(); i++) {
ShapeBuilder::getGtfsBox(&gtfs[i], cmdCfgMots, cfg.shapeTripId, true,
&box, maxSpeed, 0);
&box, maxSpeed, 0, cfg.verbosity);
}
OsmBuilder osmBuilder;
std::vector<pfaedle::osm::OsmReadOpts> opts;
Expand All @@ -215,7 +219,7 @@ int main(int argc, char** argv) {
BBoxIdx box(BOX_PADDING);
for (size_t i = 0; i < cfg.feedPaths.size(); i++) {
ShapeBuilder::getGtfsBox(&gtfs[i], cmdCfgMots, cfg.shapeTripId, true,
&box, maxSpeed, 0);
&box, maxSpeed, 0, cfg.verbosity);
}
OsmBuilder osmBuilder;
std::vector<pfaedle::osm::OsmReadOpts> opts;
Expand Down Expand Up @@ -270,9 +274,9 @@ int main(int argc, char** argv) {
pfaedle::osm::OsmBuilder osmBuilder;

pfaedle::osm::BBoxIdx box(BOX_PADDING);
ShapeBuilder::getGtfsBox(&gtfs[0], usedMots, cfg.shapeTripId,
cfg.dropShapes, &box,
motCfg.osmBuildOpts.maxSpeed, &hopDists);
ShapeBuilder::getGtfsBox(
&gtfs[0], usedMots, cfg.shapeTripId, cfg.dropShapes, &box,
motCfg.osmBuildOpts.maxSpeed, &hopDists, cfg.verbosity);

T_START(osmBuild);

Expand Down
8 changes: 7 additions & 1 deletion src/pfaedle/config/ConfigReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ void ConfigReader::help(const char* bin) {
<< "Disable hop cache \n"
<< std::setw(35) << " --stats"
<< "write stats to stats.json\n"
<< std::setw(35) << " -W [ --warn ]"
<< "enable verbose warning messages\n"
<< std::setw(35) << " -P"
<< "additional parameter string (in cfg file format)\n";
}
Expand Down Expand Up @@ -144,11 +146,12 @@ void ConfigReader::read(Config* cfg, int argc, char** argv) {
{"stats", no_argument, 0, 14},
{"no-hop-cache", no_argument, 0, 15},
{"gaussian-noise", required_argument, 0, 16},
{"warn", no_argument, 0, 'W'},
{"keep-additional-gtfs-fields", no_argument, 0, 'F'},
{0, 0, 0, 0}};

int c;
while ((c = getopt_long(argc, argv, ":o:hvi:c:x:Dm:g:X:T:d:pP:F", ops, 0)) !=
while ((c = getopt_long(argc, argv, ":o:hvi:c:x:Dm:g:X:T:d:pP:FW", ops, 0)) !=
-1) {
switch (c) {
case 1:
Expand Down Expand Up @@ -220,6 +223,9 @@ void ConfigReader::read(Config* cfg, int argc, char** argv) {
case 16:
cfg->gaussianNoise = atof(optarg);
break;
case 'W':
cfg->verbosity = 1;
break;
case 'F':
cfg->parseAdditionalGTFSFields = true;
break;
Expand Down
5 changes: 4 additions & 1 deletion src/pfaedle/config/PfaedleConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ struct Config {
writeStats(false),
parseAdditionalGTFSFields(false),
gridSize(2000 / util::geo::M_PER_DEG),
gaussianNoise(0) {}
gaussianNoise(0),
verbosity(0) {}
std::string dbgOutputPath;
std::string solveMethod;
std::string shapeTripId;
Expand Down Expand Up @@ -67,6 +68,7 @@ struct Config {
bool parseAdditionalGTFSFields;
double gridSize;
double gaussianNoise;
uint8_t verbosity;

std::string toString() {
std::stringstream ss;
Expand All @@ -88,6 +90,7 @@ struct Config {
<< "no-a-star: " << noAStar << "\n"
<< "no-trie: " << noTrie << "\n"
<< "no-hop-cache: " << noHopCache << "\n"
<< "verbosity: " << verbosity << "\n"
<< "parse-additional-gtfs-fields: " << parseAdditionalGTFSFields << "\n"
<< "write-stats: " << writeStats << "\n"
<< "feed-paths: ";
Expand Down
68 changes: 52 additions & 16 deletions src/pfaedle/router/ShapeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ShapeBuilder::ShapeBuilder(
_router(router) {
pfaedle::osm::BBoxIdx box(BOX_PADDING);
ShapeBuilder::getGtfsBox(feed, mots, cfg.shapeTripId, cfg.dropShapes, &box,
_motCfg.osmBuildOpts.maxSpeed, 0);
_motCfg.osmBuildOpts.maxSpeed, 0, cfg.verbosity);

_eGrid = EdgeGrid(cfg.gridSize, cfg.gridSize, box.getFullBox(), false);
_nGrid = NodeGrid(cfg.gridSize, cfg.gridSize, box.getFullBox(), false);
Expand Down Expand Up @@ -270,6 +270,11 @@ EdgeCandGroup ShapeBuilder::getEdgCands(const Stop* s) const {
{}});
}

if (ret.size() == 1 && _cfg.verbosity) {
LOG(WARN) << "No snapping candidate found for stop '" << s->getName()
<< "' (" << s->getId() << ")";
}

return ret;
}

Expand Down Expand Up @@ -321,7 +326,7 @@ std::pair<std::vector<LINE>, Stats> ShapeBuilder::shapeL(Trip* trip) {
LOG(INFO) << "Matched 1 trip in " << std::fixed << std::setprecision(2)
<< stats.solveTime << " ms.";
// print to line
return {getGeom(hops, getRAttrs(trip), &colors), stats};
return {getGeom(hops, getRAttrs(trip), &colors, trip, 1), stats};
} catch (const std::runtime_error& e) {
LOG(ERROR) << e.what();
return {std::vector<LINE>(), stats};
Expand Down Expand Up @@ -558,15 +563,16 @@ void ShapeBuilder::setShape(Trip* t, const ad::cppgtfs::gtfs::Shape& s,

// _____________________________________________________________________________
ad::cppgtfs::gtfs::Shape ShapeBuilder::getGtfsShape(
const EdgeListHops& hops, Trip* t, const RoutingAttrs& rAttrs,
std::vector<float>* hopDists, uint32_t* bestColor) {
const EdgeListHops& hops, Trip* t, size_t numOthers,
const RoutingAttrs& rAttrs, std::vector<float>* hopDists,
uint32_t* bestColor) {
ad::cppgtfs::gtfs::Shape ret(getFreeShapeId(t));

assert(hops.size() == t->getStopTimes().size() - 1);

std::map<uint32_t, double> colors;

const std::vector<LINE>& gl = getGeom(hops, rAttrs, &colors);
const std::vector<LINE>& gl = getGeom(hops, rAttrs, &colors, t, numOthers);
const std::vector<float>& measures = getMeasure(gl);

size_t seq = 0;
Expand Down Expand Up @@ -651,7 +657,8 @@ const RoutingAttrs& ShapeBuilder::getRAttrs(const Trip* trip) const {
void ShapeBuilder::getGtfsBox(const Feed* feed, const MOTs& mots,
const std::string& tid, bool dropShapes,
osm::BBoxIdx* box, double maxSpeed,
std::vector<double>* hopDists) {
std::vector<double>* hopDists,
uint8_t verbosity) {
for (const auto& t : feed->getTrips()) {
if (!tid.empty() && t.getId() != tid) continue;
if (tid.empty() && !t.getShape().empty() && !dropShapes) continue;
Expand Down Expand Up @@ -695,11 +702,21 @@ void ShapeBuilder::getGtfsBox(const Feed* feed, const MOTs& mots,
if (reqToTime > (BUFFER + toTime) * 3 * MAX_ROUTE_COST_DOUBLING_STEPS &&
reqFromTime >
(BUFFER + fromTime) * 3 * MAX_ROUTE_COST_DOUBLING_STEPS) {
LOG(DEBUG) << "Skipping station " << st.getStop()->getId() << " ("
<< st.getStop()->getName() << ") @ "
<< st.getStop()->getLat() << ", " << st.getStop()->getLng()
<< " for bounding box as the vehicle cannot realistically "
"reach and leave it in the scheduled time";
if (verbosity) {
LOG(WARN)
<< "Skipping station '" << st.getStop()->getName() << "' ("
<< st.getStop()->getId() << ") @ " << st.getStop()->getLat()
<< ", " << st.getStop()->getLng()
<< " for bounding box as the vehicle cannot realistically "
"reach and leave it in the scheduled time";
} else {
LOG(DEBUG)
<< "Skipping station '" << st.getStop()->getName() << "' ("
<< st.getStop()->getId() << ") @ " << st.getStop()->getLat()
<< ", " << st.getStop()->getLng()
<< " for bounding box as the vehicle cannot realistically "
"reach and leave it in the scheduled time";
}
continue;
}

Expand Down Expand Up @@ -954,16 +971,34 @@ void ShapeBuilder::buildNetGraph(TrGraphEdgs* edgs,
}

// _____________________________________________________________________________
std::vector<LINE> ShapeBuilder::getGeom(
const EdgeListHops& hops, const RoutingAttrs& rAttrs,
std::map<uint32_t, double>* colors) const {
std::vector<LINE> ShapeBuilder::getGeom(const EdgeListHops& hops,
const RoutingAttrs& rAttrs,
std::map<uint32_t, double>* colors,
Trip* t, size_t numOthers) const {
std::vector<LINE> ret;

for (size_t i = hops.size(); i > 0; i--) {
const auto& hop = hops[i - 1];
if (!hop.start || !hop.end) {
// no hop was found, use the fallback geometry

if (_cfg.verbosity) {
const auto stopFr = t->getStopTimes()[hops.size() - i].getStop();
const auto stopTo = t->getStopTimes()[hops.size() - i + 1].getStop();

LOG(WARN) << "No viable hop found between stops '" << stopFr->getName()
<< "' (" << stopFr->getId() << ") and '" << stopTo->getName()
<< "' (" << stopTo->getId() << ") for trip " << t->getId()
<< " of type '"
<< ad::cppgtfs::gtfs::flat::Route::getTypeString(
t->getRoute()->getType())
<< "'"
<< (numOthers > 1 ? " (and " + std::to_string(numOthers) +
" similar trips)"
: "")
<< ", falling back to straight line";
}

if (hop.start) {
if (hop.progrStart > 0) {
auto l = getLine(hop.start);
Expand Down Expand Up @@ -1159,8 +1194,9 @@ void ShapeBuilder::shapeWorker(

uint32_t color;

const ad::cppgtfs::gtfs::Shape& shp = getGtfsShape(
hops.at(leaf.first), leaf.second[0], rAttrs, &distances, &color);
const ad::cppgtfs::gtfs::Shape& shp =
getGtfsShape(hops.at(leaf.first), leaf.second[0],
leaf.second.size(), rAttrs, &distances, &color);

if (_cfg.buildTransitGraph) {
writeTransitGraph(hops.at(leaf.first), gtfsGraph, leaf.second);
Expand Down
7 changes: 5 additions & 2 deletions src/pfaedle/router/ShapeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <unordered_map>
#include <utility>
#include <vector>

#include "ad/cppgtfs/gtfs/Feed.h"
#include "pfaedle/Def.h"
#include "pfaedle/config/MotConfig.h"
Expand Down Expand Up @@ -73,7 +74,7 @@ class ShapeBuilder {
static void getGtfsBox(const pfaedle::gtfs::Feed* feed, const MOTs& mots,
const std::string& tid, bool dropShapes,
osm::BBoxIdx* box, double maxSpeed,
std::vector<double>* hopDists);
std::vector<double>* hopDists, uint8_t verbosity);

private:
pfaedle::gtfs::Feed* _feed;
Expand Down Expand Up @@ -103,6 +104,7 @@ class ShapeBuilder {
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<float>* hopDists,
uint32_t* bestColor);
Expand All @@ -126,7 +128,8 @@ class ShapeBuilder {
void buildIndex();

std::vector<LINE> getGeom(const EdgeListHops& shp, const RoutingAttrs& rAttrs,
std::map<uint32_t, double>* colors) const;
std::map<uint32_t, double>* colors, Trip* t,
size_t numOthers) const;
double timePen(int candTime, int schedTime) const;

LINE getLine(const EdgeListHop& hop, const RoutingAttrs&,
Expand Down

0 comments on commit ad02526

Please sign in to comment.