2018-06-09 17:14:08 +02:00
|
|
|
// Copyright 2018, University of Freiburg,
|
|
|
|
|
// Chair of Algorithms and Data Structures.
|
|
|
|
|
// Authors: Patrick Brosi <brosi@informatik.uni-freiburg.de>
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include "pfaedle/trgraph/EdgePL.h"
|
2018-08-10 15:21:27 +02:00
|
|
|
#include "util/geo/Geo.h"
|
2018-06-09 17:14:08 +02:00
|
|
|
|
|
|
|
|
using pfaedle::trgraph::EdgePL;
|
|
|
|
|
using pfaedle::trgraph::TransitEdgeLine;
|
|
|
|
|
|
2018-08-10 16:42:38 +02:00
|
|
|
|
|
|
|
|
std::map<LINE*, size_t> EdgePL::_flines;
|
2018-06-09 17:14:08 +02:00
|
|
|
std::map<const TransitEdgeLine*, size_t> EdgePL::_tlines;
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
EdgePL::EdgePL()
|
|
|
|
|
: _length(0), _oneWay(0), _hasRestr(false), _rev(false), _lvl(0) {
|
2018-08-10 16:42:38 +02:00
|
|
|
_l = new LINE();
|
2018-06-09 17:14:08 +02:00
|
|
|
_flines[_l] = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
EdgePL::EdgePL(const EdgePL& pl) : EdgePL(pl, false) {}
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
EdgePL::EdgePL(const EdgePL& pl, bool geoflat)
|
|
|
|
|
: _length(pl._length),
|
|
|
|
|
_oneWay(pl._oneWay),
|
|
|
|
|
_hasRestr(pl._hasRestr),
|
|
|
|
|
_rev(pl._rev),
|
|
|
|
|
_lvl(pl._lvl) {
|
|
|
|
|
if (geoflat) {
|
|
|
|
|
_l = pl._l;
|
|
|
|
|
} else {
|
2018-08-10 16:42:38 +02:00
|
|
|
_l = new LINE(*pl._l);
|
2018-06-09 17:14:08 +02:00
|
|
|
}
|
|
|
|
|
_flines[_l]++;
|
|
|
|
|
|
2019-01-10 16:52:59 +01:00
|
|
|
for (auto l : pl._lines) addLine(l);
|
2018-06-09 17:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
EdgePL::~EdgePL() {
|
|
|
|
|
if (_l) {
|
|
|
|
|
_flines[_l]--;
|
|
|
|
|
if (_flines[_l] == 0) delete _l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto l : _lines) unRefTLine(l);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
void EdgePL::unRefTLine(const TransitEdgeLine* l) {
|
|
|
|
|
if (l) {
|
|
|
|
|
_tlines[l]--;
|
|
|
|
|
if (_tlines[l] == 0) {
|
|
|
|
|
delete l;
|
|
|
|
|
_tlines.erase(_tlines.find(l));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
EdgePL EdgePL::revCopy() const {
|
|
|
|
|
EdgePL ret(*this);
|
|
|
|
|
ret.setRev();
|
|
|
|
|
if (ret.oneWay() == 1)
|
|
|
|
|
ret.setOneWay(2);
|
|
|
|
|
else if (ret.oneWay() == 2)
|
|
|
|
|
ret.setOneWay(1);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
void EdgePL::setLength(double d) { _length = d; }
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
double EdgePL::getLength() const { return _length; }
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
void EdgePL::addLine(const TransitEdgeLine* l) {
|
2019-01-10 16:52:59 +01:00
|
|
|
if (std::find(_lines.begin(), _lines.end(), l) == _lines.end()) {
|
|
|
|
|
_lines.reserve(_lines.size() + 1);
|
|
|
|
|
_lines.push_back(l);
|
2018-06-09 17:14:08 +02:00
|
|
|
if (_tlines.count(l))
|
|
|
|
|
_tlines[l]++;
|
|
|
|
|
else
|
|
|
|
|
_tlines[l] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
void EdgePL::addLines(const std::vector<TransitEdgeLine*>& l) {
|
|
|
|
|
for (auto line : l) addLine(line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
2019-01-10 16:52:59 +01:00
|
|
|
const std::vector<const TransitEdgeLine*>& EdgePL::getLines() const {
|
2018-06-09 17:14:08 +02:00
|
|
|
return _lines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
2018-08-10 16:42:38 +02:00
|
|
|
void EdgePL::addPoint(const POINT& p) { _l->push_back(p); }
|
2018-06-09 17:14:08 +02:00
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
2018-08-10 16:42:38 +02:00
|
|
|
const LINE* EdgePL::getGeom() const { return _l; }
|
2018-06-09 17:14:08 +02:00
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
2018-08-10 16:42:38 +02:00
|
|
|
LINE* EdgePL::getGeom() { return _l; }
|
2018-06-09 17:14:08 +02:00
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
2018-08-01 14:25:54 +02:00
|
|
|
util::json::Dict EdgePL::getAttrs() const {
|
|
|
|
|
util::json::Dict obj;
|
|
|
|
|
obj["m_length"] = std::to_string(_length);
|
|
|
|
|
obj["oneway"] = std::to_string(static_cast<int>(_oneWay));
|
|
|
|
|
obj["level"] = std::to_string(_lvl);
|
|
|
|
|
obj["restriction"] = isRestricted() ? "yes" : "no";
|
2018-06-09 17:14:08 +02:00
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
bool first = false;
|
|
|
|
|
|
|
|
|
|
for (auto* l : _lines) {
|
|
|
|
|
if (first) ss << ",";
|
|
|
|
|
ss << l->shortName;
|
|
|
|
|
if (l->fromStr.size() || l->toStr.size()) {
|
|
|
|
|
ss << "(" << l->fromStr;
|
|
|
|
|
ss << "->" << l->toStr << ")";
|
|
|
|
|
}
|
|
|
|
|
first = true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-01 14:25:54 +02:00
|
|
|
obj["lines"] = ss.str();
|
|
|
|
|
return obj;
|
2018-06-09 17:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
void EdgePL::setRestricted() { _hasRestr = true; }
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
bool EdgePL::isRestricted() const { return _hasRestr; }
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
uint8_t EdgePL::oneWay() const { return _oneWay; }
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
void EdgePL::setOneWay(uint8_t dir) { _oneWay = dir; }
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
void EdgePL::setOneWay() { _oneWay = 1; }
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
void EdgePL::setLvl(uint8_t lvl) { _lvl = lvl; }
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
uint8_t EdgePL::lvl() const { return _lvl; }
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
void EdgePL::setRev() { _rev = true; }
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
|
|
|
|
bool EdgePL::isRev() const { return _rev; }
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
2018-08-10 16:42:38 +02:00
|
|
|
const POINT& EdgePL::backHop() const {
|
2018-06-09 17:14:08 +02:00
|
|
|
if (isRev()) {
|
|
|
|
|
return *(++(getGeom()->cbegin()));
|
|
|
|
|
}
|
|
|
|
|
return *(++(getGeom()->crbegin()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _____________________________________________________________________________
|
2018-08-10 16:42:38 +02:00
|
|
|
const POINT& EdgePL::frontHop() const {
|
2018-06-09 17:14:08 +02:00
|
|
|
if (isRev()) {
|
|
|
|
|
return *(++(getGeom()->crbegin()));
|
|
|
|
|
}
|
|
|
|
|
return *(++(getGeom()->cbegin()));
|
|
|
|
|
}
|