51 const bool tryRepair,
const bool mayBeDisconnected) :
53 myPrecomputed(nullptr), myLastUsed(lastUsed), myTryRepair(tryRepair),
54 myMayBeDisconnected(mayBeDisconnected),
55 myDiscardSilent(false) {
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")
169 const int initialSize = (int)oldEdges.size();
170 if (initialSize == 1) {
173 bool ok = router.
compute(oldEdges.front(),
nullptr, &veh, begin, newEdges);
179 if (oldEdges.front()->prohibits(&veh)) {
181 const std::string& frontID = oldEdges.front()->getID();
182 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
183 if ((*i)->prohibits(&veh) || (*i)->isInternal()) {
184 i = oldEdges.erase(i);
187 +
"' to '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
192 if (oldEdges.size() == 0) {
193 mh->
inform(
"Could not find new starting edge for vehicle '" + veh.
getID() +
"'.");
196 if (oldEdges.back()->prohibits(&veh)) {
198 const std::string& backID = oldEdges.back()->getID();
200 while (oldEdges.back()->prohibits(&veh) || oldEdges.back()->isInternal()) {
204 +
"' to edge '" + oldEdges.back()->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
207 assert(mandatory.size() >= 2);
209 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
210 if ((*i)->prohibits(&veh) || (*i)->isInternal()) {
212 i = oldEdges.erase(i);
218 if (mandatory.size() > oldEdges.size() && initialSize > 2) {
219 WRITE_MESSAGE(
"There are stop edges which were not part of the original route for vehicle '" + veh.
getID() +
"'.");
221 const ConstROEdgeVector& targets = mandatory.size() > oldEdges.size() ? mandatory : oldEdges;
222 newEdges.push_back(*(targets.begin()));
223 ConstROEdgeVector::iterator nextMandatory = mandatory.begin() + 1;
224 int lastMandatory = 0;
225 for (ConstROEdgeVector::const_iterator i = targets.begin() + 1;
226 i != targets.end() && nextMandatory != mandatory.end(); ++i) {
227 if ((*(i - 1))->isConnectedTo(**i, veh.
getVClass())) {
228 newEdges.push_back(*i);
230 if (initialSize > 2) {
232 WRITE_MESSAGE(
"Edge '" + (*(i - 1))->
getID() +
"' not connected to edge '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
234 const ROEdge* last = newEdges.back();
238 last = newEdges.back();
241 if (!router.
compute(last, *i, &veh, begin, newEdges)) {
248 if (lastMandatory >= (
int)newEdges.size() || last == newEdges[lastMandatory] || !router.
compute(newEdges[lastMandatory], *nextMandatory, &veh, begin, edges)) {
249 mh->
inform(
"Mandatory edge '" + (*i)->getID() +
"' not reachable by vehicle '" + veh.
getID() +
"'.");
252 while (*i != *nextMandatory) {
255 newEdges.erase(newEdges.begin() + lastMandatory + 1, newEdges.end());
256 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
259 if (*i == *nextMandatory) {
261 lastMandatory = (int)newEdges.size() - 1;
315 if ((*i)->getProbability() == 0) {
333 newSum += (*i)->getProbability();
338 (*i)->setProbability((*i)->getProbability() / newSum);
346 chosen -= (*i)->getProbability();
364 bool asAlternatives,
bool withExitTimes)
const {
365 if (asAlternatives) {
368 myAlternatives[i]->writeXMLDefinition(dev, veh,
true, withExitTimes);
385 edges.push_back(route->
getLast());
409 sum += (*i)->getProbability();
#define WRITE_MESSAGE(msg)
#define WRITE_WARNING(msg)
std::vector< const ROEdge * > ConstROEdgeVector
@ 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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A basic edge for routing applications.
bool isTazConnector() const
const std::string & getID() const
Returns the id of the routable.
SUMOVehicleClass getVClass() const
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.
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.
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, bool asAlternatives, bool withExitTimes) const
Saves the built route / route alternatives.
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.
RORouteDef * copyOrigDest(const std::string &id) const
Returns a origin-destination copy of the route definition.
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.
const ROEdge * getFirst() const
Returns the first edge in the route.
void setProbability(double prob)
Sets the probability of the route.
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the list of stops this route contains.
double getProbability() const
Returns the probability the driver will take this route with.
void addStopOffset(const SUMOTime offset)
Adapts the until time of all stops by the given offset.
const RGBColor * getColor() const
Returns this route's color.
const ConstROEdgeVector & getEdgeVector() const
Returns the list of edges this route consists of.
const ROEdge * getLast() const
Returns the last edge in the route.
void setCosts(double costs)
Sets the costs of the route.
A vehicle as used by router.
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(std::mt19937 *rng=nullptr)
Returns a random real number in [0, 1)
Abstract base class providing static factory method.
int getMaxRouteNumber() const
static RouteCostCalculator< R, E, V > & getCalculator()
double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) 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...
Some static methods for string processing.