* 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:
parent
f1822868c5
commit
4c29892658
126 changed files with 14576 additions and 12196 deletions
|
|
@ -11,15 +11,12 @@
|
|||
using pfaedle::trgraph::EdgePL;
|
||||
using pfaedle::trgraph::TransitEdgeLine;
|
||||
|
||||
|
||||
std::map<LINE*, size_t> EdgePL::_flines;
|
||||
std::map<const TransitEdgeLine*, size_t> EdgePL::_tlines;
|
||||
|
||||
// _____________________________________________________________________________
|
||||
EdgePL::EdgePL()
|
||||
: _length(0), _oneWay(0), _hasRestr(false), _rev(false), _lvl(0) {
|
||||
_l = new LINE();
|
||||
_flines[_l] = 1;
|
||||
: _oneWay(0), _hasRestr(false), _rev(false), _lvl(0), _cost(0), _l(0) {
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
|
|
@ -27,17 +24,20 @@ EdgePL::EdgePL(const EdgePL& pl) : EdgePL(pl, false) {}
|
|||
|
||||
// _____________________________________________________________________________
|
||||
EdgePL::EdgePL(const EdgePL& pl, bool geoflat)
|
||||
: _length(pl._length),
|
||||
_oneWay(pl._oneWay),
|
||||
: _oneWay(pl._oneWay),
|
||||
_hasRestr(pl._hasRestr),
|
||||
_rev(pl._rev),
|
||||
_lvl(pl._lvl) {
|
||||
if (geoflat) {
|
||||
_l = pl._l;
|
||||
} else {
|
||||
_l = new LINE(*pl._l);
|
||||
_lvl(pl._lvl),
|
||||
_cost(pl._cost),
|
||||
_l(0) {
|
||||
if (pl._l) {
|
||||
if (geoflat) {
|
||||
_l = pl._l;
|
||||
} else {
|
||||
_l = new LINE(*pl._l);
|
||||
}
|
||||
_flines[_l]++;
|
||||
}
|
||||
_flines[_l]++;
|
||||
|
||||
for (auto l : pl._lines) addLine(l);
|
||||
}
|
||||
|
|
@ -75,16 +75,23 @@ EdgePL EdgePL::revCopy() const {
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void EdgePL::setLength(double d) { _length = d; }
|
||||
double EdgePL::getLength() const {
|
||||
double len = 0;
|
||||
|
||||
// _____________________________________________________________________________
|
||||
double EdgePL::getLength() const { return _length; }
|
||||
for (size_t i = 1; i < _l->size(); i++) {
|
||||
len += haversine((*_l)[i-1], (*_l)[i]);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void EdgePL::addLine(const TransitEdgeLine* l) {
|
||||
if (std::find(_lines.begin(), _lines.end(), l) == _lines.end()) {
|
||||
auto lb = std::lower_bound(_lines.begin(), _lines.end(), l);
|
||||
if (lb == _lines.end() || *lb != l) {
|
||||
_lines.reserve(_lines.size() + 1);
|
||||
_lines.push_back(l);
|
||||
lb = std::lower_bound(_lines.begin(), _lines.end(), l);
|
||||
_lines.insert(lb, l);
|
||||
if (_tlines.count(l))
|
||||
_tlines[l]++;
|
||||
else
|
||||
|
|
@ -103,7 +110,13 @@ const std::vector<const TransitEdgeLine*>& EdgePL::getLines() const {
|
|||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void EdgePL::addPoint(const POINT& p) { _l->push_back(p); }
|
||||
void EdgePL::addPoint(const POINT& p) {
|
||||
if (!_l) {
|
||||
_l = new LINE();
|
||||
_flines[_l] = 1;
|
||||
}
|
||||
_l->push_back(p);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const LINE* EdgePL::getGeom() const { return _l; }
|
||||
|
|
@ -114,8 +127,9 @@ LINE* EdgePL::getGeom() { return _l; }
|
|||
// _____________________________________________________________________________
|
||||
util::json::Dict EdgePL::getAttrs() const {
|
||||
util::json::Dict obj;
|
||||
obj["m_length"] = std::to_string(_length);
|
||||
obj["m_length"] = std::to_string(getLength());
|
||||
obj["oneway"] = std::to_string(static_cast<int>(_oneWay));
|
||||
obj["cost"] = std::to_string(static_cast<double>(_cost) / 10.0);
|
||||
obj["level"] = std::to_string(_lvl);
|
||||
obj["restriction"] = isRestricted() ? "yes" : "no";
|
||||
|
||||
|
|
@ -152,10 +166,10 @@ void EdgePL::setOneWay(uint8_t dir) { _oneWay = dir; }
|
|||
void EdgePL::setOneWay() { _oneWay = 1; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void EdgePL::setLvl(uint8_t lvl) { _lvl = lvl; }
|
||||
uint32_t EdgePL::getCost() const { return _cost; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
uint8_t EdgePL::lvl() const { return _lvl; }
|
||||
void EdgePL::setCost(uint32_t c) { _cost = c; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void EdgePL::setRev() { _rev = true; }
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
using util::geograph::GeoEdgePL;
|
||||
|
||||
|
||||
|
||||
namespace pfaedle {
|
||||
namespace trgraph {
|
||||
|
||||
|
|
@ -28,14 +26,17 @@ struct TransitEdgeLine {
|
|||
std::string fromStr;
|
||||
std::string toStr;
|
||||
std::string shortName;
|
||||
uint32_t color;
|
||||
};
|
||||
|
||||
inline bool operator==(const TransitEdgeLine& a, const TransitEdgeLine& b) {
|
||||
// ignoring color here!
|
||||
return a.fromStr == b.fromStr && a.toStr == b.toStr &&
|
||||
a.shortName == b.shortName;
|
||||
}
|
||||
|
||||
inline bool operator<(const TransitEdgeLine& a, const TransitEdgeLine& b) {
|
||||
// ignoring color here!
|
||||
return a.fromStr < b.fromStr ||
|
||||
(a.fromStr == b.fromStr && a.toStr < b.toStr) ||
|
||||
(a.fromStr == b.fromStr && a.toStr == b.toStr &&
|
||||
|
|
@ -65,14 +66,20 @@ class EdgePL {
|
|||
// Return the length in meters stored for this edge payload
|
||||
double getLength() const;
|
||||
|
||||
// Set the length in meters for this edge payload
|
||||
void setLength(double d);
|
||||
|
||||
// Set this edge as a one way node, either in the default direction of
|
||||
// the edge (no arg), or the direction specified in dir
|
||||
void setOneWay();
|
||||
void setOneWay(uint8_t dir);
|
||||
|
||||
void setLvl(uint8_t lvl) { assert(lvl < 9); _lvl = lvl; }
|
||||
uint8_t lvl() const { return _lvl; }
|
||||
|
||||
// Return the cost for this edge payload
|
||||
uint32_t getCost() const;
|
||||
|
||||
// Set the cost for this edge payload
|
||||
void setCost(uint32_t d);
|
||||
|
||||
// Mark this payload' edge as having some restrictions
|
||||
void setRestricted();
|
||||
|
||||
|
|
@ -85,12 +92,6 @@ class EdgePL {
|
|||
// True if this edge is restricted
|
||||
bool isRestricted() const;
|
||||
|
||||
// Set the level of this edge.
|
||||
void setLvl(uint8_t lvl);
|
||||
|
||||
// Return the level of this edge.
|
||||
uint8_t lvl() const;
|
||||
|
||||
// Return the one-way code stored for this edge.
|
||||
uint8_t oneWay() const;
|
||||
|
||||
|
|
@ -115,11 +116,11 @@ class EdgePL {
|
|||
EdgePL revCopy() const;
|
||||
|
||||
private:
|
||||
float _length;
|
||||
uint8_t _oneWay : 2;
|
||||
bool _hasRestr : 1;
|
||||
bool _rev : 1;
|
||||
uint8_t _lvl : 3;
|
||||
uint8_t _lvl: 4;
|
||||
uint32_t _cost; // costs in 1/10th seconds
|
||||
|
||||
LINE* _l;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ namespace trgraph {
|
|||
typedef util::graph::Edge<NodePL, EdgePL> Edge;
|
||||
typedef util::graph::Node<NodePL, EdgePL> Node;
|
||||
typedef util::graph::DirGraph<NodePL, EdgePL> Graph;
|
||||
typedef Grid<Node*, Point, PFAEDLE_PRECISION> NodeGrid;
|
||||
typedef Grid<Edge*, Line, PFAEDLE_PRECISION> EdgeGrid;
|
||||
typedef Grid<Node*, Point, PFDL_PREC> NodeGrid;
|
||||
typedef Grid<Edge*, Line, PFDL_PREC> EdgeGrid;
|
||||
|
||||
} // namespace trgraph
|
||||
} // namespace pfaedle
|
||||
|
|
|
|||
|
|
@ -3,22 +3,19 @@
|
|||
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
#include <unordered_map>
|
||||
#include "pfaedle/trgraph/NodePL.h"
|
||||
#include "pfaedle/trgraph/StatGroup.h"
|
||||
#include "pfaedle/trgraph/StatInfo.h"
|
||||
#include "util/String.h"
|
||||
|
||||
using pfaedle::trgraph::StatInfo;
|
||||
using pfaedle::trgraph::NodePL;
|
||||
using pfaedle::trgraph::Component;
|
||||
using pfaedle::trgraph::NodePL;
|
||||
using pfaedle::trgraph::StatInfo;
|
||||
|
||||
// we use the adress of this dummy station info as a special value
|
||||
// of this node, meaning "is a station block". Re-using the _si field here
|
||||
// saves some memory
|
||||
StatInfo NodePL::_blockerSI = StatInfo();
|
||||
|
||||
std::unordered_map<const Component*, size_t> NodePL::_comps;
|
||||
std::vector<Component> NodePL::comps;
|
||||
std::vector<StatInfo> NodePL::_statInfos;
|
||||
|
||||
// _____________________________________________________________________________
|
||||
NodePL::NodePL()
|
||||
|
|
@ -32,19 +29,6 @@ NodePL::NodePL()
|
|||
{
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
NodePL::NodePL(const NodePL& pl)
|
||||
: _geom(pl._geom),
|
||||
_si(0),
|
||||
_component(pl._component)
|
||||
#ifdef PFAEDLE_DBG
|
||||
,
|
||||
_vis(pl._vis)
|
||||
#endif
|
||||
{
|
||||
if (pl._si) setSI(*(pl._si));
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
NodePL::NodePL(const POINT& geom)
|
||||
: _geom(geom),
|
||||
|
|
@ -70,18 +54,6 @@ NodePL::NodePL(const POINT& geom, const StatInfo& si)
|
|||
setSI(si);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
NodePL::~NodePL() {
|
||||
if (getSI()) delete _si;
|
||||
if (_component) {
|
||||
_comps[_component]--;
|
||||
if (_comps[_component] == 0) {
|
||||
delete _component;
|
||||
_comps.erase(_comps.find(_component));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void NodePL::setVisited() const {
|
||||
#ifdef PFAEDLE_DBG
|
||||
|
|
@ -93,18 +65,14 @@ void NodePL::setVisited() const {
|
|||
void NodePL::setNoStat() { _si = 0; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const Component* NodePL::getComp() const { return _component; }
|
||||
const Component& NodePL::getComp() const { return comps[_component - 1]; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void NodePL::setComp(const Component* c) {
|
||||
if (_component == c) return;
|
||||
_component = c;
|
||||
uint32_t NodePL::getCompId() const { return _component; }
|
||||
|
||||
// NOT thread safe!
|
||||
if (!_comps.count(c))
|
||||
_comps[c] = 1;
|
||||
else
|
||||
_comps[c]++;
|
||||
// _____________________________________________________________________________
|
||||
void NodePL::setComp(uint32_t id) {
|
||||
_component = id;
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
|
|
@ -116,54 +84,59 @@ void NodePL::setGeom(const POINT& geom) { _geom = geom; }
|
|||
// _____________________________________________________________________________
|
||||
util::json::Dict NodePL::getAttrs() const {
|
||||
util::json::Dict obj;
|
||||
obj["component"] = std::to_string(reinterpret_cast<size_t>(_component));
|
||||
obj["component"] = std::to_string(_component);
|
||||
#ifdef PFAEDLE_DBG
|
||||
obj["dijkstra_vis"] = _vis ? "yes" : "no";
|
||||
#endif
|
||||
if (getSI()) {
|
||||
obj["station_info_ptr"] = util::toString(_si);
|
||||
obj["station_name"] = _si->getName();
|
||||
obj["station_alt_names"] = util::implode(_si->getAltNames(), ",");
|
||||
obj["from_osm"] = _si->isFromOsm() ? "yes" : "no";
|
||||
obj["station_platform"] = _si->getTrack();
|
||||
obj["station_group"] =
|
||||
std::to_string(reinterpret_cast<size_t>(_si->getGroup()));
|
||||
obj["station_name"] = getSI()->getName();
|
||||
obj["station_alt_names"] =
|
||||
util::implode(getSI()->getAltNames(), ",");
|
||||
obj["station_platform"] = getSI()->getTrack();
|
||||
|
||||
#ifdef PFAEDLE_STATION_IDS
|
||||
// only print this in debug mode
|
||||
obj["station_id"] = _si->getId();
|
||||
obj["station_id"] = getSI()->getId();
|
||||
#endif
|
||||
|
||||
|
||||
std::stringstream gtfsIds;
|
||||
if (_si->getGroup()) {
|
||||
for (auto* s : _si->getGroup()->getStops()) {
|
||||
gtfsIds << s->getId() << " (" << s->getName() << "),";
|
||||
}
|
||||
}
|
||||
|
||||
obj["station_group_stops"] = gtfsIds.str();
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void NodePL::setSI(const StatInfo& si) { _si = new StatInfo(si); }
|
||||
void NodePL::setSI(const StatInfo& si) {
|
||||
_statInfos.emplace_back(si);
|
||||
_si = _statInfos.size();
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const StatInfo* NodePL::getSI() const {
|
||||
if (isBlocker()) return 0;
|
||||
return _si;
|
||||
if (isTurnCycle()) return 0;
|
||||
if (_si == 0) return 0;
|
||||
return &_statInfos[_si - 1];
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
StatInfo* NodePL::getSI() {
|
||||
if (isBlocker()) return 0;
|
||||
return _si;
|
||||
if (isTurnCycle()) return 0;
|
||||
if (_si == 0) return 0;
|
||||
return &_statInfos[_si - 1];
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void NodePL::setBlocker() { _si = &_blockerSI; }
|
||||
void NodePL::setTurnCycle() { _si = std::numeric_limits<uint32_t>::max() - 1; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
bool NodePL::isBlocker() const { return _si == &_blockerSI; }
|
||||
bool NodePL::isTurnCycle() const {
|
||||
return _si == (std::numeric_limits<uint32_t>::max() - 1);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void NodePL::setBlocker() { _si = std::numeric_limits<uint32_t>::max(); }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
bool NodePL::isBlocker() const {
|
||||
return _si == std::numeric_limits<uint32_t>::max();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "ad/cppgtfs/gtfs/Feed.h"
|
||||
#include "pfaedle/Def.h"
|
||||
#include "pfaedle/trgraph/StatInfo.h"
|
||||
|
|
@ -20,7 +21,7 @@ namespace pfaedle {
|
|||
namespace trgraph {
|
||||
|
||||
struct Component {
|
||||
uint8_t minEdgeLvl : 3;
|
||||
float maxSpeed;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -29,10 +30,8 @@ struct Component {
|
|||
class NodePL {
|
||||
public:
|
||||
NodePL();
|
||||
NodePL(const NodePL& pl); // NOLINT
|
||||
NodePL(const POINT& geom); // NOLINT
|
||||
NodePL(const POINT& geom, const StatInfo& si);
|
||||
~NodePL();
|
||||
|
||||
// Return the geometry of this node.
|
||||
const POINT* getGeom() const;
|
||||
|
|
@ -52,10 +51,13 @@ class NodePL {
|
|||
void setNoStat();
|
||||
|
||||
// Get the component of this node
|
||||
const Component* getComp() const;
|
||||
const Component& getComp() const;
|
||||
|
||||
// Get the component of this node
|
||||
uint32_t getCompId() const;
|
||||
|
||||
// Set the component of this node
|
||||
void setComp(const Component* c);
|
||||
void setComp(uint32_t c);
|
||||
|
||||
// Make this node a blocker
|
||||
void setBlocker();
|
||||
|
|
@ -63,21 +65,27 @@ class NodePL {
|
|||
// Check if this node is a blocker
|
||||
bool isBlocker() const;
|
||||
|
||||
// Make this node a turning cycle
|
||||
void setTurnCycle();
|
||||
|
||||
// Check if this node is a blocker
|
||||
bool isTurnCycle() const;
|
||||
|
||||
// Mark this node as visited (usefull for counting search space in Dijkstra)
|
||||
// (only works for DEBUG build type)
|
||||
void setVisited() const;
|
||||
|
||||
static std::vector<Component> comps;
|
||||
|
||||
private:
|
||||
POINT _geom;
|
||||
StatInfo* _si;
|
||||
const Component* _component;
|
||||
uint32_t _si;
|
||||
uint32_t _component;
|
||||
|
||||
#ifdef PFAEDLE_DBG
|
||||
mutable bool _vis;
|
||||
#endif
|
||||
|
||||
static StatInfo _blockerSI;
|
||||
static std::unordered_map<const Component*, size_t> _comps;
|
||||
static std::vector<StatInfo> _statInfos;
|
||||
};
|
||||
} // namespace trgraph
|
||||
} // namespace pfaedle
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
|
@ -37,17 +36,6 @@ Normalizer& Normalizer::operator=(Normalizer other) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
std::string Normalizer::operator()(std::string sn) const {
|
||||
return normTS(sn);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
std::string Normalizer::normTS(const std::string& sn) const {
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
return norm(sn);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
std::string Normalizer::norm(const std::string& sn) const {
|
||||
auto i = _cache.find(sn);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
|
||||
namespace pfaedle {
|
||||
namespace trgraph {
|
||||
|
|
@ -37,19 +36,13 @@ class Normalizer {
|
|||
|
||||
// Normalize sn, not thread safe
|
||||
std::string norm(const std::string& sn) const;
|
||||
// Normalize sn, thread safe
|
||||
std::string normTS(const std::string& sn) const;
|
||||
|
||||
// Normalize sn based on the rules of this normalizer, uses the thread safe
|
||||
// version of norm() internally
|
||||
std::string operator()(std::string sn) const;
|
||||
bool operator==(const Normalizer& b) const;
|
||||
|
||||
private:
|
||||
ReplRulesComp _rules;
|
||||
ReplRules _rulesOrig;
|
||||
mutable std::unordered_map<std::string, std::string> _cache;
|
||||
mutable std::mutex _mutex;
|
||||
|
||||
void buildRules(const ReplRules& rules);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,94 +0,0 @@
|
|||
// Copyright 2018, University of Freiburg,
|
||||
// Chair of Algorithms and Data Structures.
|
||||
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
|
||||
|
||||
#include <set>
|
||||
#include "pfaedle/trgraph/StatGroup.h"
|
||||
#include "util/geo/Geo.h"
|
||||
|
||||
using pfaedle::trgraph::StatGroup;
|
||||
using pfaedle::trgraph::Node;
|
||||
using pfaedle::router::NodeCandGroup;
|
||||
using ad::cppgtfs::gtfs::Stop;
|
||||
|
||||
// _____________________________________________________________________________
|
||||
StatGroup::StatGroup() {}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void StatGroup::addStop(const Stop* s) { _stops.insert(s); }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void StatGroup::addNode(trgraph::Node* n) { _nodes.insert(n); }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void StatGroup::merge(StatGroup* other) {
|
||||
if (other == this) return;
|
||||
|
||||
std::set<Node*> nds = other->getNodes();
|
||||
std::set<const Stop*> stops = other->getStops();
|
||||
|
||||
for (auto on : nds) {
|
||||
on->pl().getSI()->setGroup(this);
|
||||
addNode(on);
|
||||
}
|
||||
|
||||
for (auto* os : stops) {
|
||||
addStop(os);
|
||||
}
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const NodeCandGroup& StatGroup::getNodeCands(const Stop* s) const {
|
||||
return _stopNodePens.at(s);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const std::set<Node*>& StatGroup::getNodes() const { return _nodes; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void StatGroup::remNode(trgraph::Node* n) {
|
||||
auto it = _nodes.find(n);
|
||||
if (it != _nodes.end()) _nodes.erase(it);
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
std::set<Node*>& StatGroup::getNodes() { return _nodes; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const std::set<const Stop*>& StatGroup::getStops() const { return _stops; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
double StatGroup::getPen(const Stop* s, trgraph::Node* n,
|
||||
const trgraph::Normalizer& platformNorm,
|
||||
double trackPen, double distPenFac,
|
||||
double nonOsmPen) const {
|
||||
POINT p =
|
||||
util::geo::latLngToWebMerc<PFAEDLE_PRECISION>(s->getLat(), s->getLng());
|
||||
|
||||
double distPen = util::geo::webMercMeterDist(p, *n->pl().getGeom());
|
||||
distPen *= distPenFac;
|
||||
|
||||
std::string platform = platformNorm.norm(s->getPlatformCode());
|
||||
|
||||
if (!platform.empty() && !n->pl().getSI()->getTrack().empty() &&
|
||||
n->pl().getSI()->getTrack() == platform) {
|
||||
trackPen = 0;
|
||||
}
|
||||
|
||||
if (n->pl().getSI()->isFromOsm()) nonOsmPen = 0;
|
||||
|
||||
return distPen + trackPen + nonOsmPen;
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void StatGroup::writePens(const trgraph::Normalizer& platformNorm,
|
||||
double trackPen, double distPenFac,
|
||||
double nonOsmPen) {
|
||||
if (_stopNodePens.size()) return; // already written
|
||||
for (auto* s : _stops) {
|
||||
for (auto* n : _nodes) {
|
||||
_stopNodePens[s].push_back(router::NodeCand{
|
||||
n, getPen(s, n, platformNorm, trackPen, distPenFac, nonOsmPen)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
// Copyright 2018, University of Freiburg,
|
||||
// Chair of Algorithms and Data Structures.
|
||||
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
|
||||
|
||||
#ifndef PFAEDLE_TRGRAPH_STATGROUP_H_
|
||||
#define PFAEDLE_TRGRAPH_STATGROUP_H_
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <set>
|
||||
#include "ad/cppgtfs/gtfs/Feed.h"
|
||||
#include "pfaedle/router/Router.h"
|
||||
#include "pfaedle/trgraph/Graph.h"
|
||||
#include "pfaedle/trgraph/Normalizer.h"
|
||||
|
||||
namespace pfaedle {
|
||||
namespace trgraph {
|
||||
|
||||
using ad::cppgtfs::gtfs::Stop;
|
||||
|
||||
/*
|
||||
* A group of stations that belong together semantically (for example, multiple
|
||||
* stop points of a larger bus station)
|
||||
*/
|
||||
class StatGroup {
|
||||
public:
|
||||
StatGroup();
|
||||
StatGroup(const StatGroup& a) = delete;
|
||||
|
||||
// Add a stop s to this station group
|
||||
void addStop(const Stop* s);
|
||||
|
||||
// Add a node n to this station group
|
||||
void addNode(trgraph::Node* n);
|
||||
|
||||
// Return all nodes contained in this group
|
||||
const std::set<trgraph::Node*>& getNodes() const;
|
||||
std::set<trgraph::Node*>& getNodes();
|
||||
|
||||
// Return all stops contained in this group
|
||||
const std::set<const Stop*>& getStops() const;
|
||||
|
||||
// Remove a node from this group
|
||||
void remNode(trgraph::Node* n);
|
||||
|
||||
// All nodes in other will be in this group, their SI's updated, and the
|
||||
// "other" group deleted.
|
||||
void merge(StatGroup* other);
|
||||
|
||||
// Return node candidates for stop s from this group
|
||||
const router::NodeCandGroup& getNodeCands(const Stop* s) const;
|
||||
|
||||
// Write the penalties for all stops contained in this group so far.
|
||||
void writePens(const trgraph::Normalizer& platformNorm, double trackPen,
|
||||
double distPenFac, double nonOsmPen);
|
||||
|
||||
private:
|
||||
std::set<trgraph::Node*> _nodes;
|
||||
std::set<const Stop*> _stops;
|
||||
|
||||
// for each stop in this group, a penalty for each of the nodes here, based on
|
||||
// its distance and optionally the track number
|
||||
std::unordered_map<const Stop*, router::NodeCandGroup> _stopNodePens;
|
||||
|
||||
double getPen(const Stop* s, trgraph::Node* n,
|
||||
const trgraph::Normalizer& norm, double trackPen,
|
||||
double distPenFac, double nonOsmPen) const;
|
||||
};
|
||||
} // namespace trgraph
|
||||
} // namespace pfaedle
|
||||
|
||||
#endif // PFAEDLE_TRGRAPH_STATGROUP_H_
|
||||
|
|
@ -3,66 +3,24 @@
|
|||
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
|
||||
|
||||
#include "pfaedle/router/Comp.h"
|
||||
#include "pfaedle/trgraph/StatGroup.h"
|
||||
#include "pfaedle/trgraph/StatInfo.h"
|
||||
|
||||
using pfaedle::trgraph::StatInfo;
|
||||
using pfaedle::trgraph::StatGroup;
|
||||
|
||||
std::unordered_map<const StatGroup*, size_t> StatInfo::_groups;
|
||||
|
||||
// _____________________________________________________________________________
|
||||
StatInfo::StatInfo() : _name(""), _track(""), _fromOsm(false), _group(0) {}
|
||||
StatInfo::StatInfo() : _name(""), _track("") {}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
StatInfo::StatInfo(const StatInfo& si)
|
||||
: _name(si._name),
|
||||
_altNames(si._altNames),
|
||||
_track(si._track),
|
||||
_fromOsm(si._fromOsm),
|
||||
_group(0) {
|
||||
setGroup(si._group);
|
||||
: _name(si._name), _altNames(si._altNames), _track(si._track) {
|
||||
#ifdef PFAEDLE_STATION_IDS
|
||||
_id = si._id;
|
||||
#endif
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
StatInfo::StatInfo(const std::string& name, const std::string& track,
|
||||
bool fromOsm)
|
||||
: _name(name), _track(track), _fromOsm(fromOsm), _group(0) {}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
StatInfo::~StatInfo() { unRefGroup(_group); }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void StatInfo::unRefGroup(StatGroup* g) {
|
||||
if (g) {
|
||||
_groups[g]--;
|
||||
if (_groups[g] == 0) {
|
||||
// std::cout << "Deleting " << g << std::endl;
|
||||
delete g;
|
||||
_groups.erase(_groups.find(g));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void StatInfo::setGroup(StatGroup* g) {
|
||||
if (_group == g) return;
|
||||
unRefGroup(_group);
|
||||
|
||||
_group = g;
|
||||
|
||||
// NOT thread safe!
|
||||
if (!_groups.count(g))
|
||||
_groups[g] = 1;
|
||||
else
|
||||
_groups[g]++;
|
||||
}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
StatGroup* StatInfo::getGroup() const { return _group; }
|
||||
StatInfo::StatInfo(const std::string& name, const std::string& track)
|
||||
: _name(name), _track(track) {}
|
||||
|
||||
// _____________________________________________________________________________
|
||||
const std::string& StatInfo::getName() const { return _name; }
|
||||
|
|
@ -70,12 +28,6 @@ const std::string& StatInfo::getName() const { return _name; }
|
|||
// _____________________________________________________________________________
|
||||
const std::string& StatInfo::getTrack() const { return _track; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
bool StatInfo::isFromOsm() const { return _fromOsm; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
void StatInfo::setIsFromOsm(bool is) { _fromOsm = is; }
|
||||
|
||||
// _____________________________________________________________________________
|
||||
double StatInfo::simi(const StatInfo* other) const {
|
||||
if (!other) return 0;
|
||||
|
|
|
|||
|
|
@ -6,24 +6,20 @@
|
|||
#define PFAEDLE_TRGRAPH_STATINFO_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace pfaedle {
|
||||
namespace trgraph {
|
||||
|
||||
// forward declaration
|
||||
class StatGroup;
|
||||
|
||||
/*
|
||||
* Meta information (name, alternative names, track, group...) of a single stop
|
||||
* Meta information (name, alternative names, track, ...) of a single stop
|
||||
*/
|
||||
class StatInfo {
|
||||
public:
|
||||
StatInfo();
|
||||
StatInfo(const StatInfo& si);
|
||||
StatInfo(const std::string& name, const std::string& track, bool _fromOsm);
|
||||
~StatInfo();
|
||||
StatInfo(const std::string& name, const std::string& track);
|
||||
|
||||
// Return this stops names.
|
||||
const std::string& getName() const;
|
||||
|
|
@ -43,18 +39,6 @@ class StatInfo {
|
|||
// Return the similarity between this stop and other
|
||||
double simi(const StatInfo* other) const;
|
||||
|
||||
// Set this stations group.
|
||||
void setGroup(StatGroup* g);
|
||||
|
||||
// Return this stations group.
|
||||
StatGroup* getGroup() const;
|
||||
|
||||
// True if this stop was from osm
|
||||
bool isFromOsm() const;
|
||||
|
||||
// Set this stop as coming from osm
|
||||
void setIsFromOsm(bool is);
|
||||
|
||||
#ifdef PFAEDLE_STATION_IDS
|
||||
const std::string& getId() const { return _id; }
|
||||
void setId(const std::string& id) { _id = id; }
|
||||
|
|
@ -64,17 +48,12 @@ class StatInfo {
|
|||
std::string _name;
|
||||
std::vector<std::string> _altNames;
|
||||
std::string _track;
|
||||
bool _fromOsm;
|
||||
StatGroup* _group;
|
||||
|
||||
#ifdef PFAEDLE_STATION_IDS
|
||||
// debug feature to store station ids from both OSM
|
||||
// and GTFS
|
||||
std::string _id;
|
||||
#endif
|
||||
|
||||
static std::unordered_map<const StatGroup*, size_t> _groups;
|
||||
static void unRefGroup(StatGroup* g);
|
||||
};
|
||||
} // namespace trgraph
|
||||
} // namespace pfaedle
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue