52 #ifdef CHECK_MEMORY_LEAKS
54 #endif // CHECK_MEMORY_LEAKS
61 const bool tryRepair) :
63 myPrecomputed(0), myLastUsed(lastUsed), myTryRepair(tryRepair)
106 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 '" +
124 std::vector<const ROEdge*> edges;
150 std::vector<const ROEdge*> oldEdges =
myAlternatives[0]->getEdgeVector();
151 std::vector<const ROEdge*> newEdges;
152 std::vector<const ROEdge*> mandatory;
153 if (oldEdges.size() == 1) {
155 router.
compute(oldEdges.front(), oldEdges.front(), &veh, begin, newEdges);
158 mandatory.push_back(oldEdges.front());
160 for (std::vector<const ROEdge*>::const_iterator i = stops.begin(); i != stops.end(); ++i) {
161 if (*i != mandatory.back()) {
162 mandatory.push_back(*i);
165 if (mandatory.size() < 2 || oldEdges.back() != mandatory.back()) {
166 mandatory.push_back(oldEdges.back());
168 assert(mandatory.size() >= 2);
170 for (std::vector<const ROEdge*>::iterator i = oldEdges.begin(); i != oldEdges.end();) {
171 if ((*i)->prohibits(&veh)) {
172 if (std::find(mandatory.begin(), mandatory.end(), *i) != mandatory.end()) {
173 mh->
inform(
"Mandatory edge '" + (*i)->getID() +
"' does not allow vehicle '" + veh.
getID() +
"'.");
176 i = oldEdges.erase(i);
182 newEdges.push_back(*(oldEdges.begin()));
183 std::vector<const ROEdge*>::iterator nextMandatory = mandatory.begin() + 1;
184 size_t lastMandatory = 0;
185 for (std::vector<const ROEdge*>::iterator i = oldEdges.begin() + 1;
186 i != oldEdges.end() && nextMandatory != mandatory.end(); ++i) {
187 if ((*(i - 1))->isConnectedTo(*i)) {
189 newEdges.push_back(*i);
191 std::vector<const ROEdge*> edges;
192 router.
compute(newEdges.back(), *i, &veh, begin, edges);
193 if (edges.size() == 0) {
199 router.
compute(newEdges[lastMandatory], *nextMandatory, &veh, begin, edges);
200 if (edges.size() == 0) {
201 mh->
inform(
"Mandatory edge '" + (*i)->getID() +
"' not reachable by vehicle '" + veh.getID() +
"'.");
204 while (*i != *nextMandatory) {
207 newEdges.erase(newEdges.begin() + lastMandatory + 1, newEdges.end());
210 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
212 if (*i == *nextMandatory) {
214 lastMandatory = newEdges.size() - 1;
276 if ((*i)->getProbability() == 0) {
294 newSum += (*i)->getProbability();
299 (*i)->setProbability((*i)->getProbability() / newSum);
307 chosen -= (*i)->getProbability();
325 bool asAlternatives,
bool withExitTimes)
const {
326 if (asAlternatives) {
329 myAlternatives[i]->writeXMLDefinition(dev, veh,
true, withExitTimes);
344 std::vector<const ROEdge*> edges;
346 edges.push_back(route->
getLast());
368 sum += (*i)->getProbability();
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
const std::string & getID() const
Returns the id of the vehicle.
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.
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)
void setProbability(SUMOReal prob)
Sets the probability of the route.
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 repairCurrentRoute(SUMOAbstractRouter< ROEdge, ROVehicle > &router, SUMOTime begin, const ROVehicle &veh) const
Builds the complete route (or chooses her from the list of alternatives, when existing) ...
static OptionsCont & getOptions()
Retrieves the options.
RORoute * myPrecomputed
precomputed route for out-of-order computation
const std::string & getID() const
Returns the id.
A vehicle as used by router.
Helper base for things that are referenced and have to be saved only once.
const ROEdge * getLast() const
Returns the last edge in the route.
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, bool asAlternatives, bool withExitTimes) const
Saves the built route / route alternatives.
const std::vector< const ROEdge * > & getStopEdges() const
virtual void calculateProbabilities(std::vector< RORoute * > alternatives, const ROVehicle *const veh, const SUMOTime time)=0
calculate the probabilities in the logit model
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.
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.
RORouteDef(const std::string &id, const unsigned int lastUsed, const bool tryRepair)
Constructor.
std::string myID
The name of the object.
const std::vector< const ROEdge * > & getEdgeVector() const
Returns the list of edges this route consists of.
unsigned int getMaxRouteNumber() const
RORouteDef * copy(const std::string &id) const
Returns a deep copy of the route definition.
void inform(std::string msg, bool addType=true)
adds a new error to the list
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.
virtual void 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...
static ROCostCalculator & getCalculator()
#define WRITE_MESSAGE(msg)
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.
virtual void setCosts(RORoute *route, const SUMOReal costs, const bool isActive=false) const =0
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
A complete router's route.