refactoring
This commit is contained in:
parent
2fb157ef37
commit
4733b0c676
26 changed files with 774 additions and 406 deletions
|
|
@ -12,6 +12,8 @@
|
|||
#include "ad/cppgtfs/gtfs/Feed.h"
|
||||
#include "ad/cppgtfs/gtfs/Route.h"
|
||||
#include "pfaedle/trgraph/Graph.h"
|
||||
#include "pfaedle/gtfs/Feed.h"
|
||||
#include "util/Nullable.h"
|
||||
|
||||
using ad::cppgtfs::gtfs::Route;
|
||||
using ad::cppgtfs::gtfs::Stop;
|
||||
|
|
@ -24,6 +26,11 @@ struct NodeCand {
|
|||
double pen;
|
||||
};
|
||||
|
||||
struct EdgeCand {
|
||||
trgraph::Edge* e;
|
||||
double pen;
|
||||
};
|
||||
|
||||
struct RoutingOpts {
|
||||
RoutingOpts()
|
||||
: fullTurnPunishFac(2000),
|
||||
|
|
@ -33,7 +40,9 @@ struct RoutingOpts {
|
|||
oneWayEdgePunish(0),
|
||||
lineUnmatchedPunishFact(0.5),
|
||||
platformUnmatchedPen(0),
|
||||
stationDistPenFactor(0) {}
|
||||
stationDistPenFactor(0),
|
||||
popReachEdge(true),
|
||||
noSelfHops(true) {}
|
||||
double fullTurnPunishFac;
|
||||
double fullTurnAngle;
|
||||
double passThruStationsPunish;
|
||||
|
|
@ -44,6 +53,8 @@ struct RoutingOpts {
|
|||
double stationDistPenFactor;
|
||||
double nonOsmPen;
|
||||
double levelPunish[8];
|
||||
bool popReachEdge;
|
||||
bool noSelfHops;
|
||||
};
|
||||
|
||||
inline bool operator==(const RoutingOpts& a, const RoutingOpts& b) {
|
||||
|
|
@ -63,7 +74,8 @@ inline bool operator==(const RoutingOpts& a, const RoutingOpts& b) {
|
|||
fabs(a.levelPunish[4] - b.levelPunish[4]) < 0.01 &&
|
||||
fabs(a.levelPunish[5] - b.levelPunish[5]) < 0.01 &&
|
||||
fabs(a.levelPunish[6] - b.levelPunish[6]) < 0.01 &&
|
||||
fabs(a.levelPunish[7] - b.levelPunish[7]) < 0.01;
|
||||
fabs(a.levelPunish[7] - b.levelPunish[7]) < 0.01 &&
|
||||
a.popReachEdge == b.popReachEdge && a.noSelfHops == b.noSelfHops;
|
||||
}
|
||||
|
||||
struct EdgeCost {
|
||||
|
|
@ -124,6 +136,9 @@ typedef std::unordered_map<const Stop*, trgraph::Node*> FeedStops;
|
|||
typedef std::vector<NodeCand> NodeCandGroup;
|
||||
typedef std::vector<NodeCandGroup> NodeCandRoute;
|
||||
|
||||
typedef std::vector<EdgeCand> EdgeCandGroup;
|
||||
typedef std::vector<EdgeCandGroup> EdgeCandRoute;
|
||||
|
||||
typedef std::vector<trgraph::Edge*> EdgeList;
|
||||
typedef std::vector<trgraph::Node*> NodeList;
|
||||
|
||||
|
|
@ -136,6 +151,38 @@ struct EdgeListHop {
|
|||
typedef std::vector<EdgeListHop> EdgeListHops;
|
||||
|
||||
typedef std::set<Route::TYPE> MOTs;
|
||||
|
||||
inline MOTs motISect(const MOTs& a, const MOTs& b) {
|
||||
MOTs ret;
|
||||
for (auto mot : a)
|
||||
if (b.count(mot)) ret.insert(mot);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline pfaedle::router::FeedStops writeMotStops(const pfaedle::gtfs::Feed* feed,
|
||||
const MOTs mots,
|
||||
const std::string& tid) {
|
||||
pfaedle::router::FeedStops ret;
|
||||
for (auto t : feed->getTrips()) {
|
||||
if (!tid.empty() && t.getId() != tid) continue;
|
||||
if (mots.count(t.getRoute()->getType())) {
|
||||
for (auto st : t.getStopTimes()) ret[st.getStop()] = 0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline std::string getMotStr(const MOTs& mots) {
|
||||
bool first = false;
|
||||
std::string motStr;
|
||||
for (const auto& mot : mots) {
|
||||
if (first) motStr += ", ";
|
||||
motStr += "<" + ad::cppgtfs::gtfs::flat::Route::getTypeString(mot) + ">";
|
||||
first = true;
|
||||
}
|
||||
|
||||
return motStr;
|
||||
}
|
||||
} // namespace router
|
||||
} // namespace pfaedle
|
||||
|
||||
|
|
|
|||
|
|
@ -107,11 +107,14 @@ EdgeCost CostFunc::operator()(const trgraph::Edge* from, const trgraph::Node* n,
|
|||
|
||||
// _____________________________________________________________________________
|
||||
double CostFunc::transitLineCmp(const trgraph::EdgePL& e) const {
|
||||
if (_rAttrs.shortName.empty() && _rAttrs.toString.empty() &&
|
||||
_rAttrs.fromString.empty())
|
||||
return 0;
|
||||
double best = 1;
|
||||
for (const auto* l : e.getLines()) {
|
||||
double cur = _rAttrs.simi(l);
|
||||
|
||||
if (cur < 0.0001) return cur;
|
||||
if (cur < 0.0001) return 0;
|
||||
if (cur < best) best = cur;
|
||||
}
|
||||
|
||||
|
|
@ -206,10 +209,11 @@ Router::~Router() {
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
bool Router::compConned(const NodeCandGroup& a, const NodeCandGroup& b) const {
|
||||
bool Router::compConned(const EdgeCandGroup& a, const EdgeCandGroup& b) const {
|
||||
for (auto n1 : a) {
|
||||
for (auto n2 : b) {
|
||||
if (n1.nd->pl().getComp() == n2.nd->pl().getComp()) return true;
|
||||
if (n1.e->getFrom()->pl().getComp() == n2.e->getFrom()->pl().getComp())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -217,7 +221,7 @@ bool Router::compConned(const NodeCandGroup& a, const NodeCandGroup& b) const {
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
HopBand Router::getHopBand(const NodeCandGroup& a, const NodeCandGroup& b,
|
||||
HopBand Router::getHopBand(const EdgeCandGroup& a, const EdgeCandGroup& b,
|
||||
const RoutingAttrs& rAttrs, const RoutingOpts& rOpts,
|
||||
const osm::Restrictor& rest) const {
|
||||
assert(a.size());
|
||||
|
|
@ -226,8 +230,8 @@ HopBand Router::getHopBand(const NodeCandGroup& a, const NodeCandGroup& b,
|
|||
double pend = 0;
|
||||
for (size_t i = 0; i < a.size(); i++) {
|
||||
for (size_t j = 0; j < b.size(); j++) {
|
||||
double d =
|
||||
webMercMeterDist(*a[i].nd->pl().getGeom(), *b[j].nd->pl().getGeom());
|
||||
double d = webMercMeterDist(*a[i].e->getFrom()->pl().getGeom(),
|
||||
*b[j].e->getFrom()->pl().getGeom());
|
||||
if (d > pend) pend = d;
|
||||
}
|
||||
}
|
||||
|
|
@ -236,23 +240,18 @@ HopBand Router::getHopBand(const NodeCandGroup& a, const NodeCandGroup& b,
|
|||
|
||||
const trgraph::StatGroup* tgGrpTo = 0;
|
||||
|
||||
if (b.begin()->nd->pl().getSI())
|
||||
tgGrpTo = b.begin()->nd->pl().getSI()->getGroup();
|
||||
if (b.begin()->e->getFrom()->pl().getSI())
|
||||
tgGrpTo = b.begin()->e->getFrom()->pl().getSI()->getGroup();
|
||||
|
||||
CostFunc costF(rAttrs, rOpts, rest, tgGrpTo, pend * 50);
|
||||
|
||||
std::set<trgraph::Edge *> from, to;
|
||||
|
||||
// TODO(patrick): test if the two sets share a common connected component
|
||||
|
||||
for (auto n : a)
|
||||
from.insert(n.nd->getAdjListOut().begin(), n.nd->getAdjListOut().end());
|
||||
|
||||
for (auto n : b)
|
||||
to.insert(n.nd->getAdjListOut().begin(), n.nd->getAdjListOut().end());
|
||||
for (auto e : a) from.insert(e.e);
|
||||
for (auto e : b) to.insert(e.e);
|
||||
|
||||
LOG(VDEBUG) << "Doing pilot run between " << from.size() << "->" << to.size()
|
||||
<< " candidates";
|
||||
<< " edge candidates";
|
||||
|
||||
EdgeList el;
|
||||
EdgeCost ret = costF.inf();
|
||||
|
|
@ -282,7 +281,8 @@ HopBand Router::getHopBand(const NodeCandGroup& a, const NodeCandGroup& b,
|
|||
}
|
||||
|
||||
// TODO(patrick): derive the punish level here automatically
|
||||
double maxD = std::max(ret.getValue(), pend * rOpts.levelPunish[2]) * 3;
|
||||
double maxD = std::max(ret.getValue(), pend * rOpts.levelPunish[2]) * 3 +
|
||||
rOpts.fullTurnPunishFac + rOpts.platformUnmatchedPen;
|
||||
double minD = ret.getValue();
|
||||
|
||||
LOG(VDEBUG) << "Pilot run: min distance between two groups is "
|
||||
|
|
@ -379,7 +379,15 @@ EdgeListHops Router::routeGreedy2(const NodeCandRoute& route,
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
EdgeListHops Router::route(const NodeCandRoute& route,
|
||||
EdgeListHops Router::route(const EdgeCandRoute& route,
|
||||
const RoutingAttrs& rAttrs, const RoutingOpts& rOpts,
|
||||
const osm::Restrictor& rest) const {
|
||||
router::Graph cg;
|
||||
return Router::route(route, rAttrs, rOpts, rest, &cg);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
EdgeListHops Router::route(const EdgeCandRoute& route,
|
||||
const RoutingAttrs& rAttrs, const RoutingOpts& rOpts,
|
||||
const osm::Restrictor& rest,
|
||||
router::Graph* cgraph) const {
|
||||
|
|
@ -393,15 +401,14 @@ EdgeListHops Router::route(const NodeCandRoute& route,
|
|||
CombNodeMap nextNodes;
|
||||
|
||||
for (size_t i = 0; i < route[0].size(); i++) {
|
||||
for (const auto* e : route[0][i].nd->getAdjListOut()) {
|
||||
// we can be sure that each edge is exactly assigned to only one
|
||||
// node because the transitgraph is directed
|
||||
nodes[e] = cgraph->addNd(route[0][i].nd);
|
||||
cgraph->addEdg(source, nodes[e])
|
||||
->pl()
|
||||
.setCost(EdgeCost(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
route[0][i].pen, 0));
|
||||
}
|
||||
auto e = route[0][i].e;
|
||||
// we can be sure that each edge is exactly assigned to only one
|
||||
// node because the transitgraph is directed
|
||||
nodes[e] = cgraph->addNd(route[0][i].e->getFrom());
|
||||
cgraph->addEdg(source, nodes[e])
|
||||
->pl()
|
||||
.setCost(EdgeCost(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
route[0][i].pen, 0));
|
||||
}
|
||||
|
||||
size_t iters = EDijkstra::ITERS;
|
||||
|
|
@ -412,14 +419,11 @@ EdgeListHops Router::route(const NodeCandRoute& route,
|
|||
HopBand hopBand = getHopBand(route[i], route[i + 1], rAttrs, rOpts, rest);
|
||||
|
||||
const trgraph::StatGroup* tgGrp = 0;
|
||||
if (route[i + 1].begin()->nd->pl().getSI())
|
||||
tgGrp = route[i + 1].begin()->nd->pl().getSI()->getGroup();
|
||||
if (route[i + 1].begin()->e->getFrom()->pl().getSI())
|
||||
tgGrp = route[i + 1].begin()->e->getFrom()->pl().getSI()->getGroup();
|
||||
|
||||
std::set<trgraph::Edge*> froms;
|
||||
for (const auto& fr : route[i]) {
|
||||
froms.insert(fr.nd->getAdjListOut().begin(),
|
||||
fr.nd->getAdjListOut().end());
|
||||
}
|
||||
for (const auto& fr : route[i]) froms.insert(fr.e);
|
||||
|
||||
for (auto eFr : froms) {
|
||||
router::Node* cNodeFr = nodes.find(eFr)->second;
|
||||
|
|
@ -433,24 +437,22 @@ EdgeListHops Router::route(const NodeCandRoute& route,
|
|||
assert(route[i + 1].size());
|
||||
|
||||
for (const auto& to : route[i + 1]) {
|
||||
assert(to.nd->getAdjListOut().size());
|
||||
for (auto eTo : to.nd->getAdjListOut()) {
|
||||
tos.insert(eTo);
|
||||
if (!nextNodes.count(eTo)) nextNodes[eTo] = cgraph->addNd(to.nd);
|
||||
if (i == route.size() - 2) cgraph->addEdg(nextNodes[eTo], sink);
|
||||
auto eTo = to.e;
|
||||
tos.insert(eTo);
|
||||
if (!nextNodes.count(eTo))
|
||||
nextNodes[eTo] = cgraph->addNd(to.e->getFrom());
|
||||
if (i == route.size() - 2) cgraph->addEdg(nextNodes[eTo], sink);
|
||||
|
||||
auto* ce = cgraph->addEdg(cNodeFr, nextNodes[eTo]);
|
||||
edges[eTo] = ce;
|
||||
pens[eTo] = to.pen;
|
||||
edges[eTo] = cgraph->addEdg(cNodeFr, nextNodes[eTo]);
|
||||
pens[eTo] = to.pen;
|
||||
|
||||
edgeLists[eTo] = ce->pl().getEdges();
|
||||
ce->pl().setStartNode(eFr->getFrom());
|
||||
// for debugging
|
||||
ce->pl().setStartEdge(eFr);
|
||||
ce->pl().setEndNode(to.nd);
|
||||
// for debugging
|
||||
ce->pl().setEndEdge(eTo);
|
||||
}
|
||||
edgeLists[eTo] = edges[eTo]->pl().getEdges();
|
||||
edges[eTo]->pl().setStartNode(eFr->getFrom());
|
||||
// for debugging
|
||||
edges[eTo]->pl().setStartEdge(eFr);
|
||||
edges[eTo]->pl().setEndNode(to.e->getFrom());
|
||||
// for debugging
|
||||
edges[eTo]->pl().setEndEdge(eTo);
|
||||
}
|
||||
|
||||
size_t iters = EDijkstra::ITERS;
|
||||
|
|
@ -475,7 +477,7 @@ EdgeListHops Router::route(const NodeCandRoute& route,
|
|||
EdgeCost(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, pens[kv.first], 0) +
|
||||
costs[kv.first]);
|
||||
|
||||
if (kv.second->pl().getEdges()->size()) {
|
||||
if (rOpts.popReachEdge && kv.second->pl().getEdges()->size()) {
|
||||
if (kv.second->pl().getEdges() &&
|
||||
kv.second->pl().getEdges()->size()) {
|
||||
// the reach edge is included, but we dont want it in the geometry
|
||||
|
|
@ -516,6 +518,30 @@ EdgeListHops Router::route(const NodeCandRoute& route,
|
|||
return ret;
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
EdgeListHops Router::route(const NodeCandRoute& route,
|
||||
const RoutingAttrs& rAttrs, const RoutingOpts& rOpts,
|
||||
const osm::Restrictor& rest) const {
|
||||
router::Graph cg;
|
||||
return Router::route(route, rAttrs, rOpts, rest, &cg);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
EdgeListHops Router::route(const NodeCandRoute& route,
|
||||
const RoutingAttrs& rAttrs, const RoutingOpts& rOpts,
|
||||
const osm::Restrictor& rest,
|
||||
router::Graph* cgraph) const {
|
||||
EdgeCandRoute r;
|
||||
for (auto& nCands : route) {
|
||||
r.emplace_back();
|
||||
for (auto n : nCands)
|
||||
for (auto* e : n.nd->getAdjListOut())
|
||||
r.back().push_back(EdgeCand{e, n.pen});
|
||||
}
|
||||
|
||||
return Router::route(r, rAttrs, rOpts, rest, cgraph);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void Router::hops(trgraph::Edge* from, const std::set<trgraph::Edge*>& froms,
|
||||
const std::set<trgraph::Edge*> tos,
|
||||
|
|
@ -533,7 +559,7 @@ void Router::hops(trgraph::Edge* from, const std::set<trgraph::Edge*>& froms,
|
|||
for (auto e : cached) {
|
||||
// shortcut: if the nodes lie in two different connected components,
|
||||
// the distance between them is trivially infinite
|
||||
if (e == from || e->getFrom() == from->getFrom() ||
|
||||
if ((rOpts.noSelfHops && (e == from || e->getFrom() == from->getFrom())) ||
|
||||
from->getFrom()->pl().getComp() != e->getTo()->pl().getComp() ||
|
||||
e->pl().oneWay() == 2 || from->pl().oneWay() == 2) {
|
||||
(*rCosts)[e] = cost.inf();
|
||||
|
|
|
|||
|
|
@ -5,23 +5,23 @@
|
|||
#ifndef PFAEDLE_ROUTER_ROUTER_H_
|
||||
#define PFAEDLE_ROUTER_ROUTER_H_
|
||||
|
||||
#include <mutex>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include "pfaedle/Def.h"
|
||||
#include "pfaedle/osm/Restrictor.h"
|
||||
#include "pfaedle/router/Graph.h"
|
||||
#include "pfaedle/router/Misc.h"
|
||||
#include "pfaedle/router/RoutingAttrs.h"
|
||||
#include "pfaedle/trgraph/Graph.h"
|
||||
#include "util/geo/Geo.h"
|
||||
#include "util/graph/Dijkstra.h"
|
||||
#include "util/graph/EDijkstra.h"
|
||||
#include "util/geo/Geo.h"
|
||||
#include "pfaedle/Def.h"
|
||||
|
||||
using util::graph::EDijkstra;
|
||||
using util::graph::Dijkstra;
|
||||
|
|
@ -53,14 +53,12 @@ struct CostFunc
|
|||
: _rAttrs(rAttrs),
|
||||
_rOpts(rOpts),
|
||||
_res(res),
|
||||
_max(max),
|
||||
_tgGrp(tgGrp),
|
||||
_inf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _max, 0) {}
|
||||
_inf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, max, 0) {}
|
||||
|
||||
const RoutingAttrs& _rAttrs;
|
||||
const RoutingOpts& _rOpts;
|
||||
const osm::Restrictor& _res;
|
||||
double _max;
|
||||
const trgraph::StatGroup* _tgGrp;
|
||||
EdgeCost _inf;
|
||||
|
||||
|
|
@ -142,6 +140,17 @@ class Router {
|
|||
|
||||
// Find the most likely path through the graph for a node candidate route.
|
||||
EdgeListHops route(const NodeCandRoute& route, const RoutingAttrs& rAttrs,
|
||||
const RoutingOpts& rOpts,
|
||||
const osm::Restrictor& rest) const;
|
||||
EdgeListHops route(const NodeCandRoute& route, const RoutingAttrs& rAttrs,
|
||||
const RoutingOpts& rOpts, const osm::Restrictor& rest,
|
||||
router::Graph* cgraph) const;
|
||||
|
||||
// Find the most likely path through the graph for an edge candidate route.
|
||||
EdgeListHops route(const EdgeCandRoute& route, const RoutingAttrs& rAttrs,
|
||||
const RoutingOpts& rOpts,
|
||||
const osm::Restrictor& rest) const;
|
||||
EdgeListHops route(const EdgeCandRoute& route, const RoutingAttrs& rAttrs,
|
||||
const RoutingOpts& rOpts, const osm::Restrictor& rest,
|
||||
router::Graph* cgraph) const;
|
||||
|
||||
|
|
@ -164,7 +173,7 @@ class Router {
|
|||
private:
|
||||
mutable std::vector<Cache*> _cache;
|
||||
bool _caching;
|
||||
HopBand getHopBand(const NodeCandGroup& a, const NodeCandGroup& b,
|
||||
HopBand getHopBand(const EdgeCandGroup& a, const EdgeCandGroup& b,
|
||||
const RoutingAttrs& rAttrs, const RoutingOpts& rOpts,
|
||||
const osm::Restrictor& rest) const;
|
||||
|
||||
|
|
@ -187,7 +196,7 @@ class Router {
|
|||
void nestedCache(const EdgeList* el, const std::set<trgraph::Edge*>& froms,
|
||||
const CostFunc& cost, const RoutingAttrs& rAttrs) const;
|
||||
|
||||
bool compConned(const NodeCandGroup& a, const NodeCandGroup& b) const;
|
||||
bool compConned(const EdgeCandGroup& a, const EdgeCandGroup& b) const;
|
||||
};
|
||||
} // namespace router
|
||||
} // namespace pfaedle
|
||||
|
|
|
|||
|
|
@ -22,19 +22,22 @@ struct RoutingAttrs {
|
|||
|
||||
mutable std::map<const TransitEdgeLine*, double> _simiCache;
|
||||
|
||||
// carfull: lower return value = higher similarity
|
||||
double simi(const TransitEdgeLine* line) const {
|
||||
auto i = _simiCache.find(line);
|
||||
if (i != _simiCache.end()) return i->second;
|
||||
|
||||
double cur = 1;
|
||||
if (router::lineSimi(line->shortName, shortName) > 0.5) cur -= 0.33;
|
||||
if (shortName.empty() || router::lineSimi(line->shortName, shortName) > 0.5)
|
||||
cur -= 0.333333333;
|
||||
|
||||
if (line->toStr.empty() || router::statSimi(line->toStr, toString) > 0.5)
|
||||
cur -= 0.33;
|
||||
if (toString.empty() || line->toStr.empty() ||
|
||||
router::statSimi(line->toStr, toString) > 0.5)
|
||||
cur -= 0.333333333;
|
||||
|
||||
if (line->fromStr.empty() ||
|
||||
if (fromString.empty() || line->fromStr.empty() ||
|
||||
router::statSimi(line->fromStr, fromString) > 0.5)
|
||||
cur -= 0.33;
|
||||
cur -= 0.333333333;
|
||||
|
||||
_simiCache[line] = cur;
|
||||
|
||||
|
|
|
|||
|
|
@ -54,43 +54,27 @@ using ad::cppgtfs::gtfs::ShapePoint;
|
|||
// _____________________________________________________________________________
|
||||
ShapeBuilder::ShapeBuilder(Feed* feed, ad::cppgtfs::gtfs::Feed* evalFeed,
|
||||
MOTs mots, const config::MotConfig& motCfg,
|
||||
eval::Collector* ecoll, const config::Config& cfg)
|
||||
eval::Collector* ecoll, pfaedle::trgraph::Graph* g,
|
||||
router::FeedStops* fStops, osm::Restrictor* restr,
|
||||
const config::Config& cfg)
|
||||
: _feed(feed),
|
||||
_evalFeed(evalFeed),
|
||||
_mots(mots),
|
||||
_motCfg(motCfg),
|
||||
_ecoll(ecoll),
|
||||
_cfg(cfg),
|
||||
_g(g),
|
||||
_crouter(omp_get_num_procs(), cfg.useCaching),
|
||||
_curShpCnt(0) {
|
||||
_stops(fStops),
|
||||
_curShpCnt(0),
|
||||
_restr(restr) {
|
||||
_numThreads = _crouter.getCacheNumber();
|
||||
writeMotStops();
|
||||
|
||||
buildGraph();
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void ShapeBuilder::writeMotStops() {
|
||||
for (auto t : _feed->getTrips()) {
|
||||
if (!_cfg.shapeTripId.empty() && t.getId() != _cfg.shapeTripId) continue;
|
||||
if (_mots.count(t.getRoute()->getType()) &&
|
||||
_motCfg.mots.count(t.getRoute()->getType())) {
|
||||
for (auto st : t.getStopTimes()) {
|
||||
_stops[st.getStop()] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
FeedStops* ShapeBuilder::getFeedStops() { return &_stops; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const NodeCandGroup& ShapeBuilder::getNodeCands(const Stop* s) const {
|
||||
if (_stops.find(s) == _stops.end() || _stops.at(s) == 0) {
|
||||
return _emptyNCG;
|
||||
}
|
||||
return _stops.at(s)->pl().getSI()->getGroup()->getNodeCands(s);
|
||||
if (_stops->find(s) == _stops->end() || _stops->at(s) == 0) return _emptyNCG;
|
||||
return _stops->at(s)->pl().getSI()->getGroup()->getNodeCands(s);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
|
|
@ -138,7 +122,7 @@ EdgeListHops ShapeBuilder::route(const router::NodeCandRoute& ncr,
|
|||
|
||||
if (_cfg.solveMethod == "global") {
|
||||
const router::EdgeListHops& ret =
|
||||
_crouter.route(ncr, rAttrs, _motCfg.routingOpts, _restr, &g);
|
||||
_crouter.route(ncr, rAttrs, _motCfg.routingOpts, *_restr, &g);
|
||||
|
||||
// write combination graph
|
||||
if (!_cfg.shapeTripId.empty() && _cfg.writeCombGraph) {
|
||||
|
|
@ -150,9 +134,9 @@ EdgeListHops ShapeBuilder::route(const router::NodeCandRoute& ncr,
|
|||
|
||||
return ret;
|
||||
} else if (_cfg.solveMethod == "greedy") {
|
||||
return _crouter.routeGreedy(ncr, rAttrs, _motCfg.routingOpts, _restr);
|
||||
return _crouter.routeGreedy(ncr, rAttrs, _motCfg.routingOpts, *_restr);
|
||||
} else if (_cfg.solveMethod == "greedy2") {
|
||||
return _crouter.routeGreedy2(ncr, rAttrs, _motCfg.routingOpts, _restr);
|
||||
return _crouter.routeGreedy2(ncr, rAttrs, _motCfg.routingOpts, *_restr);
|
||||
} else {
|
||||
LOG(ERROR) << "Unknown solution method " << _cfg.solveMethod;
|
||||
exit(1);
|
||||
|
|
@ -228,15 +212,6 @@ void ShapeBuilder::shape(pfaedle::netgraph::Graph* ng) {
|
|||
LOG(INFO) << "@ " << j << " / " << clusters.size() << " ("
|
||||
<< (static_cast<int>((j * 1.0) / clusters.size() * 100))
|
||||
<< "%, " << (EDijkstra::ITERS - oiters) << " iters, "
|
||||
/**
|
||||
TODO: this is actually misleading. We are counting the
|
||||
Dijkstra iterations, but measuring them against
|
||||
the total running time (including all overhead + HMM solve)
|
||||
<< tput "
|
||||
<< (static_cast<double>(EDijkstra::ITERS - oiters)) /
|
||||
TOOK(t1, TIME())
|
||||
<< " iters/ms, "
|
||||
**/
|
||||
<< "matching " << (10.0 / (TOOK(t1, TIME()) / 1000))
|
||||
<< " trips/sec)";
|
||||
|
||||
|
|
@ -259,13 +234,13 @@ void ShapeBuilder::shape(pfaedle::netgraph::Graph* ng) {
|
|||
const ad::cppgtfs::gtfs::Shape& shp =
|
||||
getGtfsShape(cshp, clusters[i][0], &distances);
|
||||
|
||||
LOG(DEBUG) << "Took " << EDijkstra::ITERS - iters << " iterations.";
|
||||
LOG(VDEBUG) << "Took " << EDijkstra::ITERS - iters << " iterations.";
|
||||
iters = EDijkstra::ITERS;
|
||||
|
||||
totNumTrips += clusters[i].size();
|
||||
|
||||
for (auto t : clusters[i]) {
|
||||
if (_cfg.evaluate) {
|
||||
if (_cfg.evaluate && _evalFeed && _ecoll) {
|
||||
_ecoll->add(t, _evalFeed->getShapes().get(t->getShape()), shp,
|
||||
distances);
|
||||
}
|
||||
|
|
@ -472,27 +447,6 @@ void ShapeBuilder::getGtfsBox(const Feed* feed, const MOTs& mots,
|
|||
}
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void ShapeBuilder::buildGraph() {
|
||||
osm::OsmBuilder osmBuilder;
|
||||
|
||||
osm::BBoxIdx box(BOX_PADDING);
|
||||
getGtfsBox(_feed, _mots, _cfg.shapeTripId, _cfg.dropShapes, &box);
|
||||
|
||||
osmBuilder.read(_cfg.osmPath, _motCfg.osmBuildOpts, &_g, box, _cfg.gridSize,
|
||||
getFeedStops(), &_restr);
|
||||
|
||||
for (auto& feedStop : *getFeedStops()) {
|
||||
if (feedStop.second) {
|
||||
feedStop.second->pl().getSI()->getGroup()->writePens(
|
||||
_motCfg.osmBuildOpts.trackNormzer,
|
||||
_motCfg.routingOpts.platformUnmatchedPen,
|
||||
_motCfg.routingOpts.stationDistPenFactor,
|
||||
_motCfg.routingOpts.nonOsmPen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
NodeCandRoute ShapeBuilder::getNCR(Trip* trip) const {
|
||||
router::NodeCandRoute ncr(trip->getStopTimes().size());
|
||||
|
|
@ -613,14 +567,14 @@ bool ShapeBuilder::routingEqual(Trip* a, Trip* b) {
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const pfaedle::trgraph::Graph* ShapeBuilder::getGraph() const { return &_g; }
|
||||
const pfaedle::trgraph::Graph* ShapeBuilder::getGraph() const { return _g; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void ShapeBuilder::writeTransitGraph(const Shape& shp, TrGraphEdgs* edgs,
|
||||
const Cluster& cluster) const {
|
||||
for (auto hop : shp.hops) {
|
||||
for (const auto* e : hop.edges) {
|
||||
if (e->pl().isRev()) e = _g.getEdg(e->getTo(), e->getFrom());
|
||||
if (e->pl().isRev()) e = _g->getEdg(e->getTo(), e->getFrom());
|
||||
(*edgs)[e].insert(cluster.begin(), cluster.end());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ class ShapeBuilder {
|
|||
public:
|
||||
ShapeBuilder(Feed* feed, ad::cppgtfs::gtfs::Feed* evalFeed, MOTs mots,
|
||||
const config::MotConfig& motCfg, eval::Collector* ecoll,
|
||||
const config::Config& cfg);
|
||||
trgraph::Graph* g, router::FeedStops* stops,
|
||||
osm::Restrictor* restr, const config::Config& cfg);
|
||||
|
||||
void shape(pfaedle::netgraph::Graph* ng);
|
||||
|
||||
|
|
@ -79,10 +80,10 @@ class ShapeBuilder {
|
|||
config::MotConfig _motCfg;
|
||||
eval::Collector* _ecoll;
|
||||
config::Config _cfg;
|
||||
trgraph::Graph _g;
|
||||
trgraph::Graph* _g;
|
||||
router::Router _crouter;
|
||||
|
||||
router::FeedStops _stops;
|
||||
router::FeedStops* _stops;
|
||||
|
||||
NodeCandGroup _emptyNCG;
|
||||
|
||||
|
|
@ -92,10 +93,9 @@ class ShapeBuilder {
|
|||
|
||||
TripRAttrs _rAttrs;
|
||||
|
||||
osm::Restrictor _restr;
|
||||
osm::Restrictor* _restr;
|
||||
|
||||
void writeMotStops();
|
||||
void buildGraph();
|
||||
void buildGraph(router::FeedStops* fStops);
|
||||
|
||||
Clusters clusterTrips(Feed* f, MOTs mots);
|
||||
void writeTransitGraph(const Shape& shp, TrGraphEdgs* edgs,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue