66 template<
class E,
class V>
81 const bool havePermissions =
false,
const bool haveRestrictions =
false,
double maxTrainLength = 5000) :
82 SUMOAbstractRouter<E, V>(
"RailwayRouter", unbuildIsWarning, effortOperation, ttOperation, havePermissions, haveRestrictions),
86 for (
const E*
const edge : edges) {
102 bool compute(
const E* from,
const E* to,
const V*
const vehicle,
SUMOTime msTime, std::vector<const E*>& into,
bool silent =
false) {
105 WRITE_WARNINGF(
"Vehicle '%' with length % exceeds configured value of --railway.max-train-length %",
109 std::vector<double> backLengths;
110 double backDist = vehicle->getLength() - from->getLength();
111 const E* start = from;
112 while (backDist > 0) {
114 if (prev ==
nullptr) {
118 backDist -= prev->getLength();
119 backLengths.push_back(prev->getLength() + (backLengths.empty() ? from->getLength() : backLengths.back()));
123 std::vector<const _RailEdge*> intoTmp;
124 bool success =
myInternalRouter->
compute(start->getRailwayRoutingEdge(), to->getRailwayRoutingEdge(), vehicle, msTime, intoTmp, silent);
125 #ifdef RailwayRouter_DEBUG_ROUTES
126 std::cout <<
"RailRouter veh=" << vehicle->getID() <<
" from=" << from->getID() <<
" to=" << to->getID() <<
" t=" <<
time2string(msTime) <<
" success=" << success <<
"\n";
129 const size_t intoSize = into.size();
130 const int backIndex = (int)backLengths.size() - 1;;
131 for (
const _RailEdge* railEdge : intoTmp) {
133 const double length = backIndex >= 0 ? backLengths[backIndex] : vehicle->getLength();
134 railEdge->insertOriginalEdges(length, into);
136 #ifdef RailwayRouter_DEBUG_ROUTES
137 std::cout <<
"RailRouter: internal result=" <<
toString(intoTmp) <<
"\n";
138 std::cout <<
"RailRouter: expanded result=" <<
toString(into) <<
"\n";
140 if (backLengths.size() > 0) {
142 into.erase(into.begin() + intoSize, into.begin() + intoSize + backLengths.size());
143 #ifdef RailwayRouter_DEBUG_ROUTES
144 std::cout <<
"RailRouter: backLengths=" <<
toString(backLengths) <<
" final result=" <<
toString(into) <<
"\n";
146 if (*(into.begin() + intoSize) != from) {
147 WRITE_WARNING(
"Railway routing failure due to turn-around on short edge '" + from->getID()
148 +
"' for vehicle '" + vehicle->getID() +
"' time=" +
time2string(msTime) +
".");
157 std::vector<_RailEdge*> railEdges;
158 for (E* edge : toProhibit) {
159 railEdges.push_back(edge->getRailwayRoutingEdge());
186 FXMutexLock locker(myLock);
205 std::vector<const E*> repl;
207 assert(repl.size() > 0);
211 for (
const E* e : repl) {
212 result += (*myStaticOperation)(e, veh, time + result);
213 seenDist += e->getLength();
215 const double lengthOnLastEdge =
MAX2(0.0, veh->getLength() - seenDist);
228 const E* result =
nullptr;
230 for (
const E* cand : edge->getPredecessors()) {
231 if (!cand->isInternal() && cand->getBidiEdge() != edge) {
233 if (result ==
nullptr) {
259 mutable FXMutex myLock;
274 template<
class E,
class V>
276 template<
class E,
class V>
278 template<
class E,
class V>
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t)
convert SUMOTime to string
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Computes the shortest path through a network using the Dijkstra algorithm.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
the edge type representing backward edges
void insertOriginalEdges(double length, std::vector< const E * > &into) const
const E * getOriginal() const
Returns the original edge.
SUMOAbstractRouter< _RailEdge, V > _InternalRouter
static double myReversalPenaltyFactor
RailwayRouter< E, V > *const myOriginal
RailwayRouter(RailwayRouter *other)
DijkstraRouter< _RailEdge, V > _InternalDijkstra
const std::vector< _RailEdge * > & getRailEdges()
std::vector< _RailEdge * > myInitialEdges
a RailEdge for every existing edge, filled on construction (but not in clones)
std::vector< _RailEdge * > myRailEdges
complete rail network filled on demand (but not in clones)
const bool mySilent
whether to suppress warning/error if no route was found
bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)
Builds the route between the given edges using the minimum effort at the given time The definition of...
RailwayRouter(const std::vector< E * > &edges, bool unbuildIsWarning, typename SUMOAbstractRouter< E, V >::Operation effortOperation, typename SUMOAbstractRouter< E, V >::Operation ttOperation=nullptr, bool silent=false, const bool havePermissions=false, const bool haveRestrictions=false, double maxTrainLength=5000)
Constructor.
static const E * getStraightPredecessor(const E *edge)
SUMOAbstractRouter< E, V > * clone()
_InternalRouter * myInternalRouter
static SUMOAbstractRouter< E, V >::Operation myStaticOperation
The object's operation to perform. (hack)
const double myMaxTrainLength
void ensureInternalRouter()
RailEdge< E, V > _RailEdge
static double myReversalPenalty
static double getTravelTimeStatic(const RailEdge< E, V > *const edge, const V *const veh, double time)
RailwayRouter & operator=(const RailwayRouter &s)
Invalidated assignment operator.
virtual ~RailwayRouter()
Destructor.
void prohibit(const std::vector< E * > &toProhibit)
MsgHandler *const myErrorMsgHandler
the handler for routing errors
const bool myHavePermissions
whether edge permissions need to be considered
virtual void prohibit(const std::vector< E * > &)
const bool myHaveRestrictions
whether edge restrictions need to be considered
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...