51 #ifdef CHECK_MEMORY_LEAKS
53 #endif // CHECK_MEMORY_LEAKS
60 const bool tryRepair) :
62 myPrecomputed(0), myLastUsed(lastUsed), myTryRepair(tryRepair)
105 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 '" +
123 std::vector<const ROEdge*> edges;
149 std::vector<const ROEdge*> oldEdges =
myAlternatives[0]->getEdgeVector();
150 std::vector<const ROEdge*> newEdges;
151 std::vector<const ROEdge*> mandatory;
152 if (oldEdges.size() == 1) {
154 router.
compute(oldEdges.front(), oldEdges.front(), &veh, begin, newEdges);
157 mandatory.push_back(oldEdges.front());
166 if (mandatory.size() < 2 || oldEdges.back() != mandatory.back()) {
167 mandatory.push_back(oldEdges.back());
169 assert(mandatory.size() >= 2);
171 for (std::vector<const ROEdge*>::iterator i = oldEdges.begin(); i != oldEdges.end();) {
172 if ((*i)->prohibits(&veh)) {
173 if (std::find(mandatory.begin(), mandatory.end(), *i) != mandatory.end()) {
174 mh->
inform(
"Stop edge '" + (*i)->getID() +
"' does not allow vehicle '" + veh.
getID() +
"'.");
177 i = oldEdges.erase(i);
183 newEdges.push_back(*(oldEdges.begin()));
184 std::vector<const ROEdge*>::iterator nextMandatory = mandatory.begin() + 1;
185 std::vector<const ROEdge*>::iterator lastMandatory = newEdges.begin();
186 for (std::vector<const ROEdge*>::iterator i = oldEdges.begin() + 1; i != oldEdges.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) {
194 if (*i == *nextMandatory) {
196 if (newEdges.back() != *lastMandatory) {
197 router.
compute(*lastMandatory, *nextMandatory, &veh, begin, edges);
199 if (edges.size() == 0) {
200 mh->
inform(
"Mandatory edge '" + (*i)->getID() +
"' not reachable by vehicle '" + veh.getID() +
"'.");
203 newEdges.erase(lastMandatory + 1, newEdges.end());
204 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
208 std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
210 if (*i == *nextMandatory) {
275 if ((*i)->getProbability() == 0) {
293 newSum += (*i)->getProbability();
298 (*i)->setProbability((*i)->getProbability() / newSum);
306 chosen -= (*i)->getProbability();
324 bool asAlternatives,
bool withExitTimes)
const {
325 if (asAlternatives) {
328 myAlternatives[i]->writeXMLDefinition(dev, veh,
true, withExitTimes);
343 std::vector<const ROEdge*> edges;
345 edges.push_back(route->
getLast());
367 sum += (*i)->getProbability();
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.
virtual void calculateProbabilities(const ROVehicle *const veh, std::vector< RORoute * > alternatives)=0
calculate the probabilities in the logit model
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 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.
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.