51 const bool tryRepair,
const bool mayBeDisconnected) :
53 myPrecomputed(nullptr), myLastUsed(lastUsed), myTryRepair(tryRepair),
54 myMayBeDisconnected(mayBeDisconnected),
55 myDiscardSilent(false) {
98 const bool ignoreErrors = oc.
getBool(
"ignore-errors");
104 mh->
inform(
"Vehicle '" + veh.
getID() +
"' is not allowed to depart on edge '" +
112 mh->
inform(
"Vehicle '" + veh.
getID() +
"' is not allowed to arrive on edge '" +
116 const bool skipTripRouting = (oc.
exists(
"write-trips") && oc.
getBool(
"write-trips")
143 if (edges.front()->isTazConnector()) {
144 edges.erase(edges.begin());
146 if (edges.back()->isTazConnector()) {
176 const int initialSize = (int)oldEdges.size();
177 if (initialSize == 1) {
180 bool ok = router.
compute(oldEdges.front(),
nullptr, &veh, begin, newEdges);
186 if (oldEdges.front()->prohibits(&veh)) {
188 const std::string& frontID = oldEdges.front()->getID();
189 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
190 if ((*i)->prohibits(&veh) || (*i)->isInternal()) {
191 i = oldEdges.erase(i);
194 +
"' to '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
199 if (oldEdges.size() == 0) {
200 mh->
inform(
"Could not find new starting edge for vehicle '" + veh.
getID() +
"'.");
203 if (oldEdges.back()->prohibits(&veh)) {
205 const std::string& backID = oldEdges.back()->getID();
207 while (oldEdges.back()->prohibits(&veh) || oldEdges.back()->isInternal()) {
211 +
"' to edge '" + oldEdges.back()->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
214 std::set<ConstROEdgeVector::const_iterator> jumpStarts;
216 assert(mandatory.size() >= 2);
218 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
219 if ((*i)->prohibits(&veh) || (*i)->isInternal()) {
221 WRITE_MESSAGEF(
TL(
"Removing invalid edge '%' for from route for vehicle '%'."), (*i)->getID(), veh.
getID());
222 i = oldEdges.erase(i);
228 if (mandatory.size() > oldEdges.size() && initialSize > 2) {
229 WRITE_MESSAGEF(
TL(
"There are stop edges which were not part of the original route for vehicle '%'."), veh.
getID());
231 const ConstROEdgeVector& targets = mandatory.size() > oldEdges.size() ? mandatory : oldEdges;
232 newEdges.push_back(targets.front());
233 ConstROEdgeVector::iterator nextMandatory = mandatory.begin() + 1;
234 int lastMandatory = 0;
235 for (ConstROEdgeVector::const_iterator i = targets.begin() + 1;
236 i != targets.end() && nextMandatory != mandatory.end(); ++i) {
237 const ROEdge* prev = *(i - 1);
240 newEdges.push_back(cur);
242 if (initialSize > 2) {
246 const ROEdge* last = newEdges.back();
250 last = newEdges.back();
253 if (veh.
hasJumps() && jumpStarts.count(nextMandatory - 1) != 0) {
254 while (*i != *nextMandatory) {
257 newEdges.push_back(last);
258 newEdges.push_back(*i);
262 int numEdgesBefore = (int)newEdges.size();
264 if (!router.
compute(last, *i, &veh, begin, newEdges)) {
270 if (lastMandatory >= (
int)newEdges.size() || last == newEdges[lastMandatory] || !
backTrack(router, i, lastMandatory, nextMandatory, newEdges, veh, begin)) {
271 mh->
inform(
"Mandatory edge '" + (*i)->getID() +
"' not reachable by vehicle '" + veh.
getID() +
"'.");
276 (*i)->getFromJunction()->getPosition());
277 double repairDist = 0;
278 for (
auto it2 = (newEdges.begin() + numEdgesBefore + 1); it2 != newEdges.end() && it2 != newEdges.end() - 1; it2++) {
279 repairDist += (*it2)->getLength();
281 const double detourFactor = repairDist /
MAX2(airDist, 1.0);
282 const double detour =
MAX2(0.0, repairDist - airDist);
284 if (detourFactor > maxDetourFactor) {
285 WRITE_MESSAGEF(
" Backtracking to avoid detour of %m for gap of %m)", detour, airDist);
286 backTrack(router, i, lastMandatory, nextMandatory, newEdges, veh, begin);
287 }
else if (detourFactor > 1.1) {
288 WRITE_MESSAGEF(
" Taking detour of %m to avoid gap of %m)", detour, airDist);
293 if (*i == *nextMandatory) {
295 lastMandatory = (int)newEdges.size() - 1;
305 ConstROEdgeVector::const_iterator& i,
int lastMandatory, ConstROEdgeVector::iterator nextMandatory,
308 bool ok = router.
compute(newEdges[lastMandatory], *nextMandatory, &veh, begin, edges);
313 while (*i != *nextMandatory) {
316 newEdges.erase(newEdges.begin() + lastMandatory + 1, newEdges.end());
317 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
353 if (!router.
isValid(alt->getEdgeVector(), veh)) {
357 const double newCosts = router.
recomputeCosts(alt->getEdgeVector(), veh, begin);
360 if (alt == current) {
363 alt->setCosts(newCosts);
366 alt->setProbability(alt->getProbability() * scale);
377 if ((*i)->getProbability() == 0) {
390 return a->getProbability() > b->getProbability();
412 newSum += alt->getProbability();
417 alt->setProbability(alt->getProbability() / newSum);
425 chosen -= alt->getProbability();
448 bool asAlternatives,
bool withExitTimes,
bool withCost,
bool withLength)
const {
449 if (asAlternatives) {
452 myAlternatives[i]->writeXMLDefinition(dev, veh,
true,
true, withExitTimes, withLength);
466 RGBColor* col = route->getColor() !=
nullptr ?
new RGBColor(*route->getColor()) :
nullptr;
467 RORoute* newRoute =
new RORoute(
id, route->getCosts(), route->getProbability(), route->getEdgeVector(), col, route->getStops());
479 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) const
returns the information whether this edge is directly connected to the given
const Position & getPosition() const
Returns the position of the node.
SUMOVehicleClass getVClass() const
const std::string & getID() const
Returns the id of the routable.
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)
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.
void addAlternative(SUMOAbstractRouter< ROEdge, ROVehicle > &router, const ROVehicle *const, RORoute *current, SUMOTime begin)
Adds an alternative to the list of routes.
int myLastUsed
Index of the route used within the last step.
std::set< RORoute * > myRouteRefs
Routes which are deleted someplace else.
const ROEdge * getDestination() const
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
static bool backTrack(SUMOAbstractRouter< ROEdge, ROVehicle > &router, ConstROEdgeVector::const_iterator &i, int lastMandatory, ConstROEdgeVector::iterator nextMandatory, ConstROEdgeVector &newEdges, const ROVehicle &veh, SUMOTime begin)
backtrack to last mandatory edge and route to next mandatory
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.
void collectJumps(const ConstROEdgeVector &mandatory, std::set< ConstROEdgeVector::const_iterator > &jumpStarts) const
collect mandatory-edge iterators that define jumps in the route
SUMOTime getJumpTime() const
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
ConstROEdgeVector getMandatoryEdges(const ROEdge *requiredStart, const ROEdge *requiredEnd) const
compute mandatory edges
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()
bool isValid(const std::vector< const E * > &edges, const V *const v) 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...
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
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