generate-shapes/src/pfaedle/trgraph/NodePL.cpp

143 lines
4.1 KiB
C++
Raw Normal View History

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 <string>
#include <vector>
#include <limits>
2018-06-09 17:14:08 +02:00
#include <unordered_map>
#include "pfaedle/trgraph/NodePL.h"
#include "pfaedle/trgraph/StatInfo.h"
#include "util/String.h"
using pfaedle::trgraph::Component;
using pfaedle::trgraph::NodePL;
using pfaedle::trgraph::StatInfo;
2018-06-09 17:14:08 +02:00
std::vector<Component> NodePL::comps;
std::vector<StatInfo> NodePL::_statInfos;
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
2018-07-24 19:33:18 +02:00
NodePL::NodePL()
: _geom(0, 0),
_si(0),
_component(0)
#ifdef PFAEDLE_DBG
,
_vis(0)
#endif
{
}
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
NodePL::NodePL(const POINT& geom)
2018-07-24 19:33:18 +02:00
: _geom(geom),
_si(0),
_component(0)
#ifdef PFAEDLE_DBG
,
_vis(0)
#endif
{
}
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
NodePL::NodePL(const POINT& geom, const StatInfo& si)
2018-07-24 19:33:18 +02:00
: _geom(geom),
_si(0),
_component(0)
#ifdef PFAEDLE_DBG
,
_vis(0)
#endif
{
2018-06-09 17:14:08 +02:00
setSI(si);
}
// _____________________________________________________________________________
2018-07-24 19:33:18 +02:00
void NodePL::setVisited() const {
#ifdef PFAEDLE_DBG
_vis = true;
#endif
}
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
void NodePL::setNoStat() { _si = 0; }
// _____________________________________________________________________________
const Component& NodePL::getComp() const { return comps[_component - 1]; }
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
uint32_t NodePL::getCompId() const { return _component; }
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
void NodePL::setComp(uint32_t id) {
_component = id;
2018-06-09 17:14:08 +02:00
}
// _____________________________________________________________________________
const POINT* NodePL::getGeom() const { return &_geom; }
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
void NodePL::setGeom(const POINT& geom) { _geom = geom; }
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
2018-08-01 14:25:54 +02:00
util::json::Dict NodePL::getAttrs() const {
util::json::Dict obj;
obj["component"] = std::to_string(_component);
2018-07-24 19:33:18 +02:00
#ifdef PFAEDLE_DBG
2018-08-01 14:25:54 +02:00
obj["dijkstra_vis"] = _vis ? "yes" : "no";
2018-07-24 19:33:18 +02:00
#endif
2018-06-09 17:14:08 +02:00
if (getSI()) {
2018-08-01 14:25:54 +02:00
obj["station_info_ptr"] = util::toString(_si);
obj["station_name"] = getSI()->getName();
obj["station_alt_names"] =
util::implode(getSI()->getAltNames(), ",");
obj["station_platform"] = getSI()->getTrack();
2018-06-09 17:14:08 +02:00
2019-02-03 12:48:48 +01:00
#ifdef PFAEDLE_STATION_IDS
// only print this in debug mode
obj["station_id"] = getSI()->getId();
2019-02-03 12:48:48 +01:00
#endif
2018-06-09 17:14:08 +02:00
}
2018-08-01 14:25:54 +02:00
return obj;
2018-06-09 17:14:08 +02:00
}
// _____________________________________________________________________________
void NodePL::setSI(const StatInfo& si) {
_statInfos.emplace_back(si);
_si = _statInfos.size();
}
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
const StatInfo* NodePL::getSI() const {
if (isBlocker()) return 0;
if (isTurnCycle()) return 0;
if (_si == 0) return 0;
return &_statInfos[_si - 1];
2018-06-09 17:14:08 +02:00
}
// _____________________________________________________________________________
StatInfo* NodePL::getSI() {
if (isBlocker()) return 0;
if (isTurnCycle()) return 0;
if (_si == 0) return 0;
return &_statInfos[_si - 1];
2018-06-09 17:14:08 +02:00
}
// _____________________________________________________________________________
void NodePL::setTurnCycle() { _si = std::numeric_limits<uint32_t>::max() - 1; }
// _____________________________________________________________________________
bool NodePL::isTurnCycle() const {
return _si == (std::numeric_limits<uint32_t>::max() - 1);
}
2018-06-09 17:14:08 +02:00
// _____________________________________________________________________________
void NodePL::setBlocker() { _si = std::numeric_limits<uint32_t>::max(); }
// _____________________________________________________________________________
bool NodePL::isBlocker() const {
return _si == std::numeric_limits<uint32_t>::max();
}