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")
164 if (edges.front()->isTazConnector()) {
165 edges.erase(edges.begin());
167 if (edges.back()->isTazConnector()) {
198 const int initialSize = (int)oldEdges.size();
204 if (initialSize == 1) {
207 bool ok = router.
compute(oldEdges.front(),
nullptr, &veh, begin, newEdges);
213 if (oldEdges.front()->prohibits(&veh, hasRestrictions)) {
215 const std::string& frontID = oldEdges.front()->getID();
216 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
217 if ((*i)->prohibits(&veh, hasRestrictions) || (*i)->isInternal()) {
218 i = oldEdges.erase(i);
221 +
"' to '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
226 if (oldEdges.size() == 0) {
227 mh->
inform(
"Could not find new starting edge for vehicle '" + veh.
getID() +
"'.");
230 if (oldEdges.back()->prohibits(&veh, hasRestrictions)) {
232 const std::string& backID = oldEdges.back()->getID();
234 while (oldEdges.back()->prohibits(&veh, hasRestrictions) || oldEdges.back()->isInternal()) {
238 +
"' to edge '" + oldEdges.back()->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
240 std::vector<ROVehicle::Mandatory> mandatory = veh.
getMandatoryEdges(oldEdges.front(), oldEdges.back());
241 assert(mandatory.size() >= 2);
243 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
244 if ((*i)->prohibits(&veh, hasRestrictions) || (*i)->isInternal()) {
246 WRITE_MESSAGEF(
TL(
"Removing invalid edge '%' from route for vehicle '%'."), (*i)->getID(), veh.
getID());
247 i = oldEdges.erase(i);
253 if (mandatory.size() > oldEdges.size() && initialSize > 2) {
254 WRITE_MESSAGEF(
TL(
"There are stop edges which were not part of the original route for vehicle '%'."), veh.
getID());
257 bool checkPositions =
false;
258 if (mandatory.size() >= oldEdges.size()) {
259 for (
auto m : mandatory) {
260 targets.push_back(m.edge);
261 checkPositions |= m.pos >= 0;
266 newEdges.push_back(targets.front());
267 auto nextMandatory = mandatory.begin() + 1;
268 int lastMandatory = 0;
269 for (ConstROEdgeVector::const_iterator i = targets.begin() + 1;
270 i != targets.end() && nextMandatory != mandatory.end(); ++i) {
271 const ROEdge* prev = *(i - 1);
274 newEdges.push_back(cur);
276 if (initialSize > 2) {
280 const ROEdge* last = newEdges.back();
284 last = newEdges.back();
287 if (veh.
hasJumps() && (nextMandatory - 1)->isJump) {
288 while (*i != nextMandatory->edge) {
291 newEdges.push_back(last);
292 newEdges.push_back(*i);
296 int numEdgesBefore = (int)newEdges.size();
298 if (
myTryRepair && lastMandatory < (
int)newEdges.size() && last != newEdges[lastMandatory]) {
303 && mandatory[i - targets.begin() - 1].pos >= 0
304 && mandatory[i - targets.begin()].pos >= 0) {
306 last, mandatory[i - targets.begin() - 1].pos,
307 *i, mandatory[i - targets.begin()].pos,
308 &veh, begin, newEdges);
310 ok = router.
compute(last, *i, &veh, begin, newEdges);
319 if (lastMandatory >= (
int)newEdges.size() || last == newEdges[lastMandatory] || !
backTrack(router, i, lastMandatory, nextMandatory->edge, newEdges, veh, begin)) {
320 mh->
inform(
"Mandatory edge '" + (*i)->getID() +
"' not reachable by vehicle '" + veh.
getID() +
"'.");
325 (*i)->getFromJunction()->getPosition());
326 double repairDist = 0;
327 for (
auto it2 = (newEdges.begin() + numEdgesBefore + 1); it2 != newEdges.end() && it2 != newEdges.end() - 1; it2++) {
328 repairDist += (*it2)->getLength();
330 const double detourFactor = repairDist /
MAX2(airDist, 1.0);
331 const double detour =
MAX2(0.0, repairDist - airDist);
333 if (detourFactor > maxDetourFactor) {
334 WRITE_MESSAGEF(
" Backtracking to avoid detour of %m for gap of %m)", detour, airDist);
335 backTrack(router, i, lastMandatory, nextMandatory->edge, newEdges, veh, begin);
336 }
else if (detourFactor > 1.1) {
337 WRITE_MESSAGEF(
" Taking detour of %m to avoid gap of %m)", detour, airDist);
342 if (*i == nextMandatory->edge) {
344 lastMandatory = (int)newEdges.size() - 1;
349 auto it = newEdges.begin();
352 it = std::find(it, newEdges.end(), e);
353 if (it == newEdges.end()) {
354 mh->
inform(
"Stop edge '" + e->
getID() +
"' is inconsistent with via edges for vehicle '" + veh.
getID() +
"'.");
366 ConstROEdgeVector::const_iterator& i,
int lastMandatory,
const ROEdge* nextMandatory,
369 bool ok = router.
compute(newEdges[lastMandatory], nextMandatory, &veh, begin, edges,
true);
374 while (*i != nextMandatory) {
377 newEdges.erase(newEdges.begin() + lastMandatory + 1, newEdges.end());
378 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
422 const double newCosts = router.
recomputeCosts(alt->getEdgeVector(), veh, begin);
425 if (alt == current) {
428 alt->setCosts(newCosts);
431 alt->setProbability(alt->getProbability() * scale);
442 if ((*i)->getProbability() == 0) {
455 return a->getProbability() > b->getProbability();
477 newSum += alt->getProbability();
482 alt->setProbability(alt->getProbability() / newSum);
490 chosen -= alt->getProbability();
513 bool asAlternatives,
bool withExitTimes,
bool withCost,
bool withLength)
const {
514 if (asAlternatives) {
517 myAlternatives[i]->writeXMLDefinition(dev, veh,
true,
true, withExitTimes, withLength);
531 RGBColor* col = route->getColor() !=
nullptr ?
new RGBColor(*route->getColor()) :
nullptr;
532 RORoute* newRoute =
new RORoute(
id, route->getCosts(), route->getProbability(), route->getEdgeVector(), col, route->getStops());
544 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
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 & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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 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.
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
void addAlternative(SUMOAbstractRouter< ROEdge, ROVehicle > &router, const ROVehicle *const, RORoute *current, SUMOTime begin, MsgHandler *errorHandler)
Adds an alternative to the list of routes.
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 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