52 const bool tryRepair,
const bool mayBeDisconnected) :
54 myPrecomputed(nullptr), myLastUsed(lastUsed), myTryRepair(tryRepair),
55 myMayBeDisconnected(mayBeDisconnected),
56 myDiscardSilent(false) {
118 const bool ignoreErrors = oc.
getBool(
"ignore-errors");
125 mh->
inform(
"Vehicle '" + veh.
getID() +
"' is not allowed to depart on edge '" +
128 }
else if (
myAlternatives[0]->getLast()->prohibits(&veh, hasRestrictions) && (!oc.
getBool(
"repair.to")
133 mh->
inform(
"Vehicle '" + veh.
getID() +
"' is not allowed to arrive on edge '" +
137 const bool skipTripRouting = (oc.
exists(
"write-trips") && oc.
getBool(
"write-trips")
165 if (edges.front()->isTazConnector()) {
166 edges.erase(edges.begin());
168 if (edges.back()->isTazConnector()) {
199 const int initialSize = (int)oldEdges.size();
207 if (initialSize == 1) {
210 bool ok = router.
compute(oldEdges.front(),
nullptr, &veh, begin, newEdges);
216 if (oldEdges.front()->prohibits(&veh, hasRestrictions)) {
218 const std::string& frontID = oldEdges.front()->getID();
219 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
220 if ((*i)->prohibits(&veh, hasRestrictions) || (*i)->isInternal()) {
221 i = oldEdges.erase(i);
224 +
"' to '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
229 if (oldEdges.size() == 0) {
230 mh->
inform(
"Could not find new starting edge for vehicle '" + veh.
getID() +
"'.");
233 if (oldEdges.back()->prohibits(&veh, hasRestrictions)) {
235 const std::string& backID = oldEdges.back()->getID();
237 while (oldEdges.back()->prohibits(&veh, hasRestrictions) || oldEdges.back()->isInternal()) {
241 +
"' to edge '" + oldEdges.back()->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
243 std::vector<ROVehicle::Mandatory> mandatory = veh.
getMandatoryEdges(oldEdges.front(), oldEdges.back());
244 assert(mandatory.size() >= 2);
246 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
247 if ((*i)->prohibits(&veh, hasRestrictions) || (*i)->isInternal()) {
249 WRITE_MESSAGEF(
TL(
"Removing invalid edge '%' from route for vehicle '%'."), (*i)->getID(), veh.
getID());
250 i = oldEdges.erase(i);
256 if (mandatory.size() > oldEdges.size() && initialSize > 2) {
257 WRITE_MESSAGEF(
TL(
"There are stop edges which were not part of the original route for vehicle '%'."), veh.
getID());
260 bool checkPositions =
false;
261 if (mandatory.size() >= oldEdges.size()) {
262 for (
auto m : mandatory) {
263 targets.push_back(m.edge);
264 checkPositions |= m.pos >= 0;
269 newEdges.push_back(targets.front());
270 auto nextMandatory = mandatory.begin() + 1;
271 int lastMandatory = 0;
272 for (ConstROEdgeVector::const_iterator i = targets.begin() + 1;
273 i != targets.end() && nextMandatory != mandatory.end(); ++i) {
274 const ROEdge* prev = *(i - 1);
277 newEdges.push_back(cur);
279 if (initialSize > 2) {
283 const ROEdge* last = newEdges.back();
287 last = newEdges.back();
290 if (veh.
hasJumps() && (nextMandatory - 1)->isJump) {
291 while (*i != nextMandatory->edge) {
294 newEdges.push_back(last);
295 newEdges.push_back(*i);
298 if (veh.
getID() ==
"10.T0.1-13-P-j26-1.2.H.0") {
299 std::cout <<
" beforeRepair newEdges=" <<
toString(newEdges) <<
" last=" << last->
getID() <<
"\n";
302 int numEdgesBefore = (int)newEdges.size();
304 if (
myTryRepair && lastMandatory < (
int)newEdges.size() && last != newEdges[lastMandatory]) {
309 && mandatory[i - targets.begin() - 1].pos >= 0
310 && mandatory[i - targets.begin()].pos >= 0) {
312 last, mandatory[i - targets.begin() - 1].pos,
313 *i, mandatory[i - targets.begin()].pos,
314 &veh, begin, newEdges);
316 ok = router.
compute(last, *i, &veh, begin, newEdges);
325 if (lastMandatory >= (
int)newEdges.size() || last == newEdges[lastMandatory] || !
backTrack(router, i, lastMandatory, nextMandatory->edge, newEdges, veh, begin)) {
326 mh->
inform(
"Mandatory edge '" + (*i)->getID() +
"' not reachable by vehicle '" + veh.
getID() +
"'.");
331 (*i)->getFromJunction()->getPosition());
332 double repairDist = 0;
333 for (
auto it2 = (newEdges.begin() + numEdgesBefore + 1); it2 != newEdges.end() && it2 != newEdges.end() - 1; it2++) {
334 repairDist += (*it2)->getLength();
336 const double detourFactor = repairDist /
MAX2(airDist, 1.0);
337 const double detour =
MAX2(0.0, repairDist - airDist);
339 if (detourFactor > maxDetourFactor) {
340 WRITE_MESSAGEF(
" Backtracking to avoid detour of %m for gap of %m)", detour, airDist);
341 backTrack(router, i, lastMandatory, nextMandatory->edge, newEdges, veh, begin);
342 }
else if (detourFactor > 1.1) {
343 WRITE_MESSAGEF(
" Taking detour of %m to avoid gap of %m)", detour, airDist);
346 if (veh.
getID() ==
"10.T0.1-13-P-j26-1.2.H.0") {
347 std::cout <<
" at=" << numEdgesBefore <<
" before=" << numEdgesBefore <<
" after=" << newEdges.size() <<
" new=" <<
toString(newEdges) <<
"\n";
351 if (*i == nextMandatory->edge) {
353 lastMandatory = (int)newEdges.size() - 1;
358 auto it = newEdges.begin();
361 it = std::find(it, newEdges.end(), e);
362 if (it == newEdges.end()) {
363 mh->
inform(
"Stop edge '" + e->
getID() +
"' is inconsistent with via edges for vehicle '" + veh.
getID() +
"'.");
375 ConstROEdgeVector::const_iterator& i,
int lastMandatory,
const ROEdge* nextMandatory,
378 bool ok = router.
compute(newEdges[lastMandatory], nextMandatory, &veh, begin, edges,
true);
383 while (*i != nextMandatory) {
386 newEdges.erase(newEdges.begin() + lastMandatory + 1, newEdges.end());
387 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
433 const double newCosts = router.
recomputeCosts(alt->getEdgeVector(), veh, begin);
436 if (alt == current) {
439 alt->setCosts(newCosts);
442 alt->setProbability(alt->getProbability() * scale);
453 if ((*i)->getProbability() == 0) {
466 return a->getProbability() > b->getProbability();
488 newSum += alt->getProbability();
493 alt->setProbability(alt->getProbability() / newSum);
501 chosen -= alt->getProbability();
525 bool asAlternatives,
bool withExitTimes,
bool withCost,
bool withLength)
const {
526 if (asAlternatives) {
529 myAlternatives[i]->writeXMLDefinition(dev, veh,
true,
true, withExitTimes, withLength);
543 RGBColor* col = route->getColor() !=
nullptr ?
new RGBColor(*route->getColor()) :
nullptr;
544 RORoute* newRoute =
new RORoute(
id, route->getCosts(), route->getProbability(), route->getEdgeVector(), col, route->getStops());
556 sum += (*i)->getProbability();
#define WRITE_WARNINGF(...)
#define WRITE_MESSAGEF(...)
#define WRITE_MESSAGE(msg)
std::vector< const ROEdge * > ConstROEdgeVector
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a (exclusive) railway edge.
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Base class for objects which have an id.
std::string myID
The name of the object.
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
A basic edge for routing applications.
const ROEdge * getBidiEdge() const
return opposite superposable/congruent edge, if it exist and 0 else
const RONode * getToJunction() const
bool isTazConnector() const
bool isConnectedTo(const ROEdge &e, const SUMOVehicleClass vClass, bool ignoreTransientPermissions=false) const
returns the information whether this edge is directly connected to the given
The router's network representation.
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
void updateLaneProhibitions(SUMOTime begin)
bool hasProhibitions() const
bool hasParamRestrictions() const
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
const Prohibitions & getProhibitions() const
const Position & getPosition() const
Returns the position of the node.
SUMOVehicleClass getVClass() const
const std::string & getID() const
Returns the id of the routable.
const SUMOVehicleParameter & getParameter() const
Returns the definition of the vehicle / person parameter.
Base class for a vehicle's route definition.
const ROEdge * getOrigin() const
bool repairCurrentRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime begin, const ROVehicle &veh, ConstROEdgeVector oldEdges, ConstROEdgeVector &newEdges, bool isTrip=false) const
Builds the complete route (or chooses her from the list of alternatives, when existing)
static bool backTrack(SUMOAbstractRouter< ROEdge, ROVehicle > &router, ConstROEdgeVector::const_iterator &i, int lastMandatory, const ROEdge *nextMandatory, ConstROEdgeVector &newEdges, const ROVehicle &veh, SUMOTime begin)
backtrack to last mandatory edge and route to next mandatory
RORoute * myPrecomputed
precomputed route for out-of-order computation
void addLoadedAlternative(RORoute *alternative)
Adds a single alternative loaded from the file An alternative may also be generated during DUA.
RORoute * addAlternative(SUMOAbstractRouter< ROEdge, ROVehicle > &router, const ROVehicle *const, RORoute *current, SUMOTime begin, MsgHandler *errorHandler)
Adds an alternative to the list of routes and returns the route that was replaced or nullptr.
RORouteDef(const std::string &id, const int lastUsed, const bool tryRepair, const bool mayBeDisconnected)
Constructor.
double getOverallProb() const
Returns the sum of the probablities of the contained routes.
std::vector< RORoute * > myAlternatives
The alternatives.
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, bool asAlternatives, bool withExitTimes, bool withCost, bool withLength) const
Saves the built route / route alternatives.
RORoute * buildCurrentRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime begin, const ROVehicle &veh) const
Triggers building of the complete route (via preComputeCurrentRoute) or returns precomputed route.
const bool myMayBeDisconnected
void addAlternativeDef(const RORouteDef *alternative)
Adds an alternative loaded from the file.
virtual ~RORouteDef()
Destructor.
bool myDiscardSilent
Whether this route should be silently discarded.
void preComputeCurrentRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime begin, const ROVehicle &veh) const
Builds the complete route (or chooses her from the list of alternatives, when existing)
bool myNewRoute
Information whether a new route was generated.
int myLastUsed
Index of the route used within the last step.
std::set< RORoute * > myRouteRefs
Routes which are deleted someplace else.
static bool mySkipNewRoutes
const ROEdge * getDestination() const
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
void validateAlternatives(const ROVehicle *veh, MsgHandler *errorHandler)
removes invalid alternatives and raise an error or warning
A complete router's route.
void addStopOffset(const SUMOTime offset)
Adapts the until time of all stops by the given offset.
const ConstROEdgeVector & getEdgeVector() const
Returns the list of edges this route consists of.
void setCosts(double costs)
Sets the costs of the route.
A vehicle as used by router.
SUMOTime getJumpTime() const
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
std::vector< Mandatory > getMandatoryEdges(const ROEdge *requiredStart, const ROEdge *requiredEnd) const
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Abstract base class providing static factory method.
static RouteCostCalculator< R, E, V > & getCalculator()
void setMsgHandler(MsgHandler *const errorMsgHandler)
bool hasProhibitions() const
virtual void prohibit(const Prohibitions &toProhibit)
virtual bool supportsProhibitions() const
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...
bool isValid(const std::vector< const E * > &edges, const V *const v, double t) const
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
std::vector< std::string > via
List of the via-edges the vehicle must visit.
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
Some static methods for string processing.
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects