 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
52 const bool tryRepair,
const bool mayBeDisconnected) :
54 myPrecomputed(nullptr), myLastUsed(lastUsed), myTryRepair(tryRepair), myMayBeDisconnected(mayBeDisconnected) {
103 mh->
inform(
"Vehicle '" + veh.
getID() +
"' is not allowed to depart on edge '" +
111 mh->
inform(
"Vehicle '" + veh.
getID() +
"' is not allowed to arrive on edge '" +
115 const bool skipTripRouting = (oc.
exists(
"write-trips") && oc.
getBool(
"write-trips")
168 const int initialSize = (int)oldEdges.size();
169 if (initialSize == 1) {
172 router.
compute(oldEdges.front(),
nullptr, &veh, begin, newEdges);
177 if (oldEdges.front()->prohibits(&veh)) {
179 const std::string& frontID = oldEdges.front()->getID();
180 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
181 if ((*i)->prohibits(&veh) || (*i)->isInternal()) {
182 i = oldEdges.erase(i);
185 +
"' to '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
190 if (oldEdges.size() == 0) {
191 mh->
inform(
"Could not find new starting edge for vehicle '" + veh.
getID() +
"'.");
194 if (oldEdges.back()->prohibits(&veh)) {
196 const std::string& backID = oldEdges.back()->getID();
198 while (oldEdges.back()->prohibits(&veh) || oldEdges.back()->isInternal()) {
202 +
"' to edge '" + oldEdges.back()->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
205 assert(mandatory.size() >= 2);
207 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
208 if ((*i)->prohibits(&veh) || (*i)->isInternal()) {
210 i = oldEdges.erase(i);
216 if (mandatory.size() > oldEdges.size() && initialSize > 2) {
217 WRITE_MESSAGE(
"There are stop edges which were not part of the original route for vehicle '" + veh.
getID() +
"'.");
219 const ConstROEdgeVector& targets = mandatory.size() > oldEdges.size() ? mandatory : oldEdges;
220 newEdges.push_back(*(targets.begin()));
221 ConstROEdgeVector::iterator nextMandatory = mandatory.begin() + 1;
222 int lastMandatory = 0;
223 for (ConstROEdgeVector::const_iterator i = targets.begin() + 1;
224 i != targets.end() && nextMandatory != mandatory.end(); ++i) {
225 if ((*(i - 1))->isConnectedTo(*i, &veh)) {
226 newEdges.push_back(*i);
228 if (initialSize > 2) {
230 WRITE_MESSAGE(
"Edge '" + (*(i - 1))->
getID() +
"' not connected to edge '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
232 const ROEdge*
const last = newEdges.back();
234 if (!router.
compute(last, *i, &veh, begin, newEdges)) {
241 if (lastMandatory >= (
int)newEdges.size() || last == newEdges[lastMandatory] || !router.
compute(newEdges[lastMandatory], *nextMandatory, &veh, begin, edges)) {
242 mh->
inform(
"Mandatory edge '" + (*i)->getID() +
"' not reachable by vehicle '" + veh.
getID() +
"'.");
245 while (*i != *nextMandatory) {
248 newEdges.erase(newEdges.begin() + lastMandatory + 1, newEdges.end());
249 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
252 if (*i == *nextMandatory) {
254 lastMandatory = (int)newEdges.size() - 1;
308 if ((*i)->getProbability() == 0) {
326 newSum += (*i)->getProbability();
331 (*i)->setProbability((*i)->getProbability() / newSum);
339 chosen -= (*i)->getProbability();
357 bool asAlternatives,
bool withExitTimes)
const {
358 if (asAlternatives) {
361 myAlternatives[i]->writeXMLDefinition(dev, veh,
true, withExitTimes);
378 edges.push_back(route->
getLast());
402 sum += (*i)->getProbability();
void addAlternative(SUMOAbstractRouter< ROEdge, ROVehicle > &router, const ROVehicle *const, RORoute *current, SUMOTime begin)
Adds an alternative to the list of routes.
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...
const ROEdge * getLast() const
Returns the last edge in the route.
double getProbability() const
Returns the probability the driver will take this route with.
#define WRITE_WARNING(msg)
RORoute * buildCurrentRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime begin, const ROVehicle &veh) const
Triggers building of the complete route (via preComputeCurrentRoute) or returns precomputed route.
Base class for objects which have an id.
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
Static storage of an output device and its base (abstract) implementation.
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
void addAlternativeDef(const RORouteDef *alternative)
Adds an alternative loaded from the file.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
const ConstROEdgeVector & getEdgeVector() const
Returns the list of edges this route consists of.
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.
Base class for a vehicle's route definition.
void setCosts(double costs)
Sets the costs of the route.
static RouteCostCalculator< R, E, V > & getCalculator()
A vehicle as used by router.
const RGBColor * getColor() const
Returns this route's color.
double getOverallProb() const
Returns the sum of the probablities of the contained routes.
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 closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Abstract base class providing static factory method.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
ConstROEdgeVector getMandatoryEdges(const ROEdge *requiredStart, const ROEdge *requiredEnd) const
compute mandatory edges
const std::string & getID() const
Returns the id of the routable.
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, bool asAlternatives, bool withExitTimes) const
Saves the built route / route alternatives.
std::set< RORoute * > myRouteRefs
Routes which are deleted someplace else.
A complete router's route.
bool myNewRoute
Information whether a new route was generated.
A storage for options typed value containers)
const bool myMayBeDisconnected
int getMaxRouteNumber() const
int myLastUsed
Index of the route used within the last step.
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.
void addStopOffset(const SUMOTime offset)
Adapts the until time of all stops by the given offset.
void setProbability(double prob)
Sets the probability of the route.
Some static methods for string processing.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
const ROEdge * getDestination() const
double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
const ROEdge * getFirst() const
Returns the first edge in the route.
A basic edge for routing applications.
virtual ~RORouteDef()
Destructor.
RORouteDef * copyOrigDest(const std::string &id) const
Returns a origin-destination copy of the route definition.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
std::string myID
The name of the object.
const std::string & getID() const
Returns the id.
#define WRITE_MESSAGE(msg)
RORouteDef(const std::string &id, const int lastUsed, const bool tryRepair, const bool mayBeDisconnected)
Constructor.
std::vector< const ROEdge * > ConstROEdgeVector
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)
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the list of stops this route contains.
std::vector< RORoute * > myAlternatives
The alternatives.