#include <config.h>
#include <router/RONet.h>
#include "ROJTRRouter.h"
#include "ROJTREdge.h"
#include <utils/common/MsgHandler.h>
ROJTRRouter::ROJTRRouter(bool unbuildIsWarningOnly, bool acceptAllDestinations,
int maxEdges, bool ignoreClasses,
bool allowLoops,
bool discountSources) :
SUMOAbstractRouter<ROEdge, ROVehicle>("JTRRouter", unbuildIsWarningOnly, &ROEdge::getTravelTimeStatic, nullptr, false, false),
myUnbuildIsWarningOnly(unbuildIsWarningOnly),
myAcceptAllDestination(acceptAllDestinations), myMaxEdges(maxEdges),
myIgnoreClasses(ignoreClasses),
myAllowLoops(allowLoops),
myDiscountSources(discountSources)
{ }
ROJTRRouter::~ROJTRRouter() {}
bool
ROJTRRouter::compute(const ROEdge* from, const ROEdge* to,
const ROVehicle* const vehicle,
SUMOTime time, ConstROEdgeVector& into, bool silent) {
const ROJTREdge* current = static_cast<const ROJTREdge*>(from);
if (myDiscountSources && current->getSourceFlow() <= 0) {
return true;
}
double timeS = STEPS2TIME(time);
std::set<const ROEdge*> avoidEdges;
while (current != nullptr && current != to &&
(!current->isSink() || current == from || current->getSourceFlow() > 0) &&
(int)into.size() < myMaxEdges) {
into.push_back(current);
const_cast<ROJTREdge*>(current)->changeSourceFlow(-1);
if (!myAllowLoops) {
avoidEdges.insert(current);
}
timeS += current->getTravelTime(vehicle, timeS);
current = current->chooseNext(myIgnoreClasses ? nullptr : vehicle, timeS, avoidEdges);
assert(myIgnoreClasses || current == 0 || !current->prohibits(vehicle));
}
if (current == nullptr || (int) into.size() >= myMaxEdges) {
if (myAcceptAllDestination) {
return true;
} else {
if (!silent) {
MsgHandler* mh = myUnbuildIsWarningOnly ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance();
mh->inform("The route starting at edge '" + from->getID() + "' could not be closed.");
}
return false;
}
}
if (current != nullptr) {
into.push_back(current);
}
return true;
}