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")
170 const int initialSize = (int)oldEdges.size();
171 if (initialSize == 1) {
174 bool ok = router.
compute(oldEdges.front(),
nullptr, &veh, begin, newEdges);
180 if (oldEdges.front()->prohibits(&veh)) {
182 const std::string& frontID = oldEdges.front()->getID();
183 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
184 if ((*i)->prohibits(&veh) || (*i)->isInternal()) {
185 i = oldEdges.erase(i);
188 +
"' to '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
193 if (oldEdges.size() == 0) {
194 mh->
inform(
"Could not find new starting edge for vehicle '" + veh.
getID() +
"'.");
197 if (oldEdges.back()->prohibits(&veh)) {
199 const std::string& backID = oldEdges.back()->getID();
201 while (oldEdges.back()->prohibits(&veh) || oldEdges.back()->isInternal()) {
205 +
"' to edge '" + oldEdges.back()->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
208 std::set<ConstROEdgeVector::const_iterator> jumpStarts;
210 assert(mandatory.size() >= 2);
212 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
213 if ((*i)->prohibits(&veh) || (*i)->isInternal()) {
215 i = oldEdges.erase(i);
221 if (mandatory.size() > oldEdges.size() && initialSize > 2) {
222 WRITE_MESSAGEF(
TL(
"There are stop edges which were not part of the original route for vehicle '%'."), veh.
getID());
224 const ConstROEdgeVector& targets = mandatory.size() > oldEdges.size() ? mandatory : oldEdges;
225 newEdges.push_back(targets.front());
226 ConstROEdgeVector::iterator nextMandatory = mandatory.begin() + 1;
227 int lastMandatory = 0;
228 for (ConstROEdgeVector::const_iterator i = targets.begin() + 1;
229 i != targets.end() && nextMandatory != mandatory.end(); ++i) {
230 const ROEdge* prev = *(i - 1);
233 newEdges.push_back(cur);
235 if (initialSize > 2) {
239 const ROEdge* last = newEdges.back();
243 last = newEdges.back();
246 if (veh.
hasJumps() && jumpStarts.count(nextMandatory - 1) != 0) {
247 while (*i != *nextMandatory) {
250 newEdges.push_back(last);
251 newEdges.push_back(*i);
256 if (!router.
compute(last, *i, &veh, begin, newEdges)) {
263 if (lastMandatory >= (
int)newEdges.size() || last == newEdges[lastMandatory] || !router.
compute(newEdges[lastMandatory], *nextMandatory, &veh, begin, edges)) {
264 mh->
inform(
"Mandatory edge '" + (*i)->getID() +
"' not reachable by vehicle '" + veh.
getID() +
"'.");
267 while (*i != *nextMandatory) {
270 newEdges.erase(newEdges.begin() + lastMandatory + 1, newEdges.end());
271 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
276 if (*i == *nextMandatory) {
278 lastMandatory = (int)newEdges.size() - 1;
313 if (!router.
isValid(alt->getEdgeVector(), veh)) {
317 const double newCosts = router.
recomputeCosts(alt->getEdgeVector(), veh, begin);
320 if (alt == current) {
323 alt->setCosts(newCosts);
326 alt->setProbability(alt->getProbability() * scale);
337 if ((*i)->getProbability() == 0) {
350 return a->getProbability() > b->getProbability();
372 newSum += alt->getProbability();
377 alt->setProbability(alt->getProbability() / newSum);
385 chosen -= alt->getProbability();
403 bool asAlternatives,
bool withExitTimes,
bool withCost,
bool withLength)
const {
404 if (asAlternatives) {
407 myAlternatives[i]->writeXMLDefinition(dev, veh,
true,
true, withExitTimes, withLength);
421 RGBColor* col = route->getColor() !=
nullptr ?
new RGBColor(*route->getColor()) :
nullptr;
422 RORoute* newRoute =
new RORoute(
id, route->getCosts(), route->getProbability(), route->getEdgeVector(), col, route->getStops());
434 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 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)
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.
A basic edge for routing applications.
const ROEdge * getBidiEdge() const
return opposite superposable/congruent edge, if it exist and 0 else
bool isTazConnector() const
bool isConnectedTo(const ROEdge &e, const SUMOVehicleClass vClass) const
returns the information whether this edge is directly connected to the given
SUMOVehicleClass getVClass() const
const std::string & getID() const
Returns the id of the routable.
Base class for a vehicle's route definition.
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.
bool repairCurrentRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime begin, const ROVehicle &veh, ConstROEdgeVector oldEdges, ConstROEdgeVector &newEdges) const
Builds the complete route (or chooses her from the list of alternatives, when existing)
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