51 #ifdef CHECK_MEMORY_LEAKS 53 #endif // CHECK_MEMORY_LEAKS 64 const bool tryRepair,
const bool mayBeDisconnected) :
66 myPrecomputed(0), myLastUsed(lastUsed), myTryRepair(tryRepair), myMayBeDisconnected(mayBeDisconnected) {
115 mh->
inform(
"Vehicle '" + veh.
getID() +
"' is not allowed to depart on edge '" +
123 mh->
inform(
"Vehicle '" + veh.
getID() +
"' is not allowed to arrive on edge '" +
179 const size_t initialSize = oldEdges.size();
180 if (initialSize == 1) {
183 router.
compute(oldEdges.front(), 0, &veh, begin, newEdges);
189 if (oldEdges.front()->prohibits(&veh)) {
191 const std::string& frontID = oldEdges.front()->getID();
192 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
193 if ((*i)->prohibits(&veh)) {
194 i = oldEdges.erase(i);
197 +
"' to '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
202 if (oldEdges.size() == 0) {
203 mh->
inform(
"Could not find new starting edge for vehicle '" + veh.
getID() +
"'.");
206 mandatory.push_back(oldEdges.front());
208 for (ConstROEdgeVector::const_iterator i = stops.begin(); i != stops.end(); ++i) {
209 if (*i != mandatory.back()) {
210 mandatory.push_back(*i);
213 if (oldEdges.back()->prohibits(&veh)) {
215 const std::string& backID = oldEdges.back()->getID();
216 for (ConstROEdgeVector::reverse_iterator i = oldEdges.rbegin(); i != oldEdges.rend();) {
217 if ((*i)->prohibits(&veh)) {
219 oldEdges.erase(i.base());
222 +
"' to edge '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
227 if (mandatory.size() < 2 || oldEdges.back() != mandatory.back()) {
228 mandatory.push_back(oldEdges.back());
230 assert(mandatory.size() >= 2);
232 for (ConstROEdgeVector::iterator i = oldEdges.begin(); i != oldEdges.end();) {
233 if ((*i)->prohibits(&veh)) {
235 i = oldEdges.erase(i);
241 if (mandatory.size() > oldEdges.size() && initialSize > 2) {
242 WRITE_MESSAGE(
"There are stop edges which were not part of the original route for vehicle '" + veh.
getID() +
"'.");
244 const ConstROEdgeVector& targets = mandatory.size() > oldEdges.size() ? mandatory : oldEdges;
245 newEdges.push_back(*(targets.begin()));
246 ConstROEdgeVector::iterator nextMandatory = mandatory.begin() + 1;
247 size_t lastMandatory = 0;
248 for (ConstROEdgeVector::const_iterator i = targets.begin() + 1;
249 i != targets.end() && nextMandatory != mandatory.end(); ++i) {
250 if ((*(i - 1))->isConnectedTo(*i, &veh)) {
251 newEdges.push_back(*i);
253 if (initialSize > 2) {
255 WRITE_MESSAGE(
"Edge '" + (*(i - 1))->
getID() +
"' not connected to edge '" + (*i)->getID() +
"' for vehicle '" + veh.
getID() +
"'.");
257 const ROEdge*
const last = newEdges.back();
259 if (!router.
compute(last, *i, &veh, begin, newEdges)) {
266 if (last == newEdges[lastMandatory] || !router.
compute(newEdges[lastMandatory], *nextMandatory, &veh, begin, edges)) {
267 mh->
inform(
"Mandatory edge '" + (*i)->getID() +
"' not reachable by vehicle '" + veh.
getID() +
"'.");
270 while (*i != *nextMandatory) {
273 newEdges.erase(newEdges.begin() + lastMandatory + 1, newEdges.end());
274 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
277 if (*i == *nextMandatory) {
279 lastMandatory = newEdges.size() - 1;
333 if ((*i)->getProbability() == 0) {
351 newSum += (*i)->getProbability();
356 (*i)->setProbability((*i)->getProbability() / newSum);
364 chosen -= (*i)->getProbability();
382 bool asAlternatives,
bool withExitTimes)
const {
383 if (asAlternatives) {
386 myAlternatives[i]->writeXMLDefinition(dev, veh,
true, withExitTimes);
403 edges.push_back(route->
getLast());
427 sum += (*i)->getProbability();
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
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.
RORouteDef * copyOrigDest(const std::string &id) const
Returns a origin-destination 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) ...
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.
RORoute * buildCurrentRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime begin, const ROVehicle &veh) const
Triggers building of the complete route (via preComputeCurrentRoute) or returns precomputed route...
void addAlternativeDef(const RORouteDef *alternative)
Adds an alternative loaded from the file.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static SUMOReal rand()
Returns a random real number in [0, 1)
const ConstROEdgeVector & getEdgeVector() const
Returns the list of edges this route consists of.
void setProbability(SUMOReal prob)
Sets the probability of the route.
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 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) ...
void addStopOffset(const SUMOTime offset)
Adapts the until time of all stops by the given offset.
std::vector< const ROEdge * > ConstROEdgeVector
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
RORoute * myPrecomputed
precomputed route for out-of-order computation
const std::string & getID() const
Returns the id.
const bool myMayBeDisconnected
A vehicle as used by router.
const ROEdge * getLast() const
Returns the last edge in the route.
std::set< RORoute * > myRouteRefs
Routes which are deleted someplace else.
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, bool asAlternatives, bool withExitTimes) const
Saves the built route / route alternatives.
const RGBColor * getColor() const
Returns this route's color.
SUMOReal getProbability() const
Returns the probability the driver will take this route with.
void setCosts(SUMOReal costs)
Sets the costs of the route.
Abstract base class providing static factory method.
const ROEdge * getDestination() const
const ROEdge * getFirst() const
Returns the first edge in the route.
A basic edge for routing applications.
Base class for objects which have an id.
virtual ~RORouteDef()
Destructor.
unsigned int myLastUsed
Index of the route used within the last step.
std::string myID
The name of the object.
const ConstROEdgeVector & getStopEdges() const
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
const std::string & getID() const
Returns the id of the vehicle.
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.
virtual SUMOReal recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime) const =0
bool closeTag()
Closes the most recently opened tag.
static RouteCostCalculator< R, E, V > & getCalculator()
#define WRITE_MESSAGE(msg)
RORouteDef(const std::string &id, const unsigned int lastUsed, const bool tryRepair, const bool mayBeDisconnected)
Constructor.
std::vector< RORoute * > myAlternatives
The alternatives.
SUMOReal getOverallProb() const
Returns the sum of the probablities of the contained routes.
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the list of stops this route contains.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
A complete router's route.