59 const bool tryRepair,
const bool mayBeDisconnected) :
61 myPrecomputed(0), myLastUsed(lastUsed), myTryRepair(tryRepair), myMayBeDisconnected(mayBeDisconnected) {
110 mh->
inform(
"Vehicle '" + veh.
getID() +
"' is not allowed to depart on edge '" +
118 mh->
inform(
"Vehicle '" + veh.
getID() +
"' is not allowed to arrive on edge '" +
174 const int initialSize = (int)oldEdges.size();
175 if (initialSize == 1) {
178 router.
compute(oldEdges.front(), 0, &veh, begin, newEdges);
184 if (oldEdges.front()->prohibits(&veh)) {
186 const std::string& frontID = oldEdges.front()->getID();
187 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
188 if ((*i)->prohibits(&veh)) {
189 i = oldEdges.erase(i);
192 +
"' to '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
197 if (oldEdges.size() == 0) {
198 mh->
inform(
"Could not find new starting edge for vehicle '" + veh.
getID() +
"'.");
201 mandatory.push_back(oldEdges.front());
203 for (ConstROEdgeVector::const_iterator i = stops.begin(); i != stops.end(); ++i) {
204 if ((*i)->isInternal()) {
208 if (after != mandatory.back()) {
209 mandatory.push_back(before);
210 mandatory.push_back(after);
213 if (*i != mandatory.back()) {
214 mandatory.push_back(*i);
218 if (oldEdges.back()->prohibits(&veh)) {
220 const std::string& backID = oldEdges.back()->
getID();
222 while (oldEdges.back()->prohibits(&veh)) {
226 +
"' to edge '" + oldEdges.back()->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
228 if (mandatory.size() < 2 || oldEdges.back() != mandatory.back()) {
229 mandatory.push_back(oldEdges.back());
231 assert(mandatory.size() >= 2);
233 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
234 if ((*i)->prohibits(&veh)) {
236 i = oldEdges.erase(i);
242 if (mandatory.size() > oldEdges.size() && initialSize > 2) {
243 WRITE_MESSAGE(
"There are stop edges which were not part of the original route for vehicle '" + veh.
getID() +
"'.");
245 const ConstROEdgeVector& targets = mandatory.size() > oldEdges.size() ? mandatory : oldEdges;
246 newEdges.push_back(*(targets.begin()));
247 ConstROEdgeVector::iterator nextMandatory = mandatory.begin() + 1;
248 int lastMandatory = 0;
249 for (ConstROEdgeVector::const_iterator i = targets.begin() + 1;
250 i != targets.end() && nextMandatory != mandatory.end(); ++i) {
251 if ((*(i - 1))->isConnectedTo(*i, &veh)) {
252 newEdges.push_back(*i);
254 if (initialSize > 2) {
256 WRITE_MESSAGE(
"Edge '" + (*(i - 1))->
getID() +
"' not connected to edge '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
258 const ROEdge*
const last = newEdges.back();
260 if (!router.
compute(last, *i, &veh, begin, newEdges)) {
267 if (lastMandatory >= (
int)newEdges.size() || last == newEdges[lastMandatory] || !router.
compute(newEdges[lastMandatory], *nextMandatory, &veh, begin, edges)) {
268 mh->
inform(
"Mandatory edge '" + (*i)->getID() +
"' not reachable by vehicle '" + veh.
getID() +
"'.");
271 while (*i != *nextMandatory) {
274 newEdges.erase(newEdges.begin() + lastMandatory + 1, newEdges.end());
275 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
278 if (*i == *nextMandatory) {
280 lastMandatory = (int)newEdges.size() - 1;
334 if ((*i)->getProbability() == 0) {
352 newSum += (*i)->getProbability();
357 (*i)->setProbability((*i)->getProbability() / newSum);
365 chosen -= (*i)->getProbability();
383 bool asAlternatives,
bool withExitTimes)
const {
384 if (asAlternatives) {
387 myAlternatives[i]->writeXMLDefinition(dev, veh,
true, withExitTimes);
404 edges.push_back(route->
getLast());
428 sum += (*i)->getProbability();
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
int myLastUsed
Index of the route used within the last step.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
void setProbability(double prob)
Sets the probability of the route.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool myNewRoute
Information whether a new route was generated.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, bool asAlternatives, bool withExitTimes) const
Saves the built route / route alternatives.
virtual double recomputeCosts(const std::vector< const E *> &edges, const V *const v, SUMOTime msTime) const =0
const ROEdge * getDestination() const
Some static methods for string processing.
void addAlternative(SUMOAbstractRouter< ROEdge, ROVehicle > &router, const ROVehicle *const, RORoute *current, SUMOTime begin)
Adds an alternative to the list of routes.
void addAlternativeDef(const RORouteDef *alternative)
Adds an alternative loaded from the file.
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) ...
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
void addStopOffset(const SUMOTime offset)
Adapts the until time of all stops by the given offset.
const ROEdge * getFirst() const
Returns the first edge in the route.
RORouteDef * copyOrigDest(const std::string &id) const
Returns a origin-destination copy of the route definition.
std::vector< const ROEdge * > ConstROEdgeVector
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const std::string & getID() const
Returns the id.
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) ...
double getOverallProb() const
Returns the sum of the probablities of the contained routes.
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
RORoute * buildCurrentRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime begin, const ROVehicle &veh) const
Triggers building of the complete route (via preComputeCurrentRoute) or returns precomputed route...
RORoute * myPrecomputed
precomputed route for out-of-order computation
const bool myMayBeDisconnected
A vehicle as used by router.
std::set< RORoute * > myRouteRefs
Routes which are deleted someplace else.
const ROEdge * getNormalAfter() const
if this edge is an internal edge, return its first normal successor, otherwise the edge itself ...
double getProbability() const
Returns the probability the driver will take this route with.
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the list of stops this route contains.
const ConstROEdgeVector & getStopEdges() const
const ROEdge * getLast() const
Returns the last edge in the route.
RORouteDef(const std::string &id, const int lastUsed, const bool tryRepair, const bool mayBeDisconnected)
Constructor.
Abstract base class providing static factory method.
const std::string & getID() const
Returns the id of the routable.
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
const RGBColor * getColor() const
Returns this route's color.
A basic edge for routing applications.
Base class for objects which have an id.
virtual ~RORouteDef()
Destructor.
std::string myID
The name of the object.
void setCosts(double costs)
Sets the costs of the route.
const ConstROEdgeVector & getEdgeVector() const
Returns the list of edges this route consists of.
void inform(std::string msg, bool addType=true)
adds a new error to the list
A storage for options typed value containers)
Base class for a vehicle's route definition.
void addLoadedAlternative(RORoute *alternative)
Adds a single alternative loaded from the file An alternative may also be generated during DUA...
Static storage of an output device and its base (abstract) implementation.
bool closeTag()
Closes the most recently opened tag.
const ROEdge * getNormalBefore() const
if this edge is an internal edge, return its first normal predecessor, otherwise the edge itself ...
static RouteCostCalculator< R, E, V > & getCalculator()
#define WRITE_MESSAGE(msg)
std::vector< RORoute * > myAlternatives
The alternatives.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
A complete router's route.