48 #ifdef CHECK_MEMORY_LEAKS 50 #endif // CHECK_MEMORY_LEAKS 85 oc.
addSynonyme(
"device.rerouting.period",
"device.routing.period",
true);
86 oc.
addDescription(
"device.rerouting.period",
"Routing",
"The period with which the vehicle shall be rerouted");
89 oc.
addSynonyme(
"device.rerouting.pre-period",
"device.routing.pre-period",
true);
90 oc.
addDescription(
"device.rerouting.pre-period",
"Routing",
"The rerouting period before depart");
93 oc.
addSynonyme(
"device.rerouting.adaptation-weight",
"device.routing.adaptation-weight",
true);
94 oc.
addDescription(
"device.rerouting.adaptation-weight",
"Routing",
"The weight of prior edge weights for exponential moving average");
97 oc.
addSynonyme(
"device.rerouting.adaptation-steps",
"device.routing.adaptation-steps",
true);
98 oc.
addDescription(
"device.rerouting.adaptation-steps",
"Routing",
"The number of steps for moving average weight of prior edge weights");
101 oc.
addSynonyme(
"device.rerouting.adaptation-interval",
"device.routing.adaptation-interval",
true);
102 oc.
addDescription(
"device.rerouting.adaptation-interval",
"Routing",
"The interval for updating the edge weights");
105 oc.
addSynonyme(
"device.rerouting.with-taz",
"device.routing.with-taz",
true);
106 oc.
addSynonyme(
"device.rerouting.with-taz",
"with-taz");
107 oc.
addDescription(
"device.rerouting.with-taz",
"Routing",
"Use zones (districts) as routing start- and endpoints");
110 oc.
addDescription(
"device.rerouting.init-with-loaded-weights",
"Routing",
"Use weight files given with option --weight-files for initializing edge weights");
113 oc.
addDescription(
"device.rerouting.shortest-path-file",
"Routing",
"Initialize lookup table for astar from the given distance matrix");
116 oc.
addDescription(
"device.rerouting.threads",
"Routing",
"The number of parallel execution threads used for rerouting");
119 oc.
addDescription(
"device.rerouting.output",
"Routing",
"Save adapting weights to FILE");
132 if (oc.
getInt(
"device.rerouting.adaptation-steps") > 0 && !oc.
isDefault(
"device.rerouting.adaptation-weight")) {
133 WRITE_ERROR(
"Only one of the options 'device.rerouting.adaptation-steps' or 'device.rerouting.adaptation-weight' may be given.");
136 if (oc.
getFloat(
"weights.random-factor") < 1) {
137 WRITE_ERROR(
"weights.random-factor cannot be less than 1");
141 WRITE_ERROR(
"Negative value for device.rerouting.adaptation-interval!");
144 if (oc.
getFloat(
"device.rerouting.adaptation-weight") < 0. ||
145 oc.
getFloat(
"device.rerouting.adaptation-weight") > 1.) {
146 WRITE_ERROR(
"The value for device.rerouting.adaptation-weight must be between 0 and 1!");
150 if (oc.
getInt(
"device.rerouting.threads") > 1) {
151 WRITE_ERROR(
"Parallel routing is only possible when compiled with Fox.");
164 if (!needRerouting && oc.
getFloat(
"device.rerouting.probability") == 0 && !oc.
isSet(
"device.rerouting.explicit")) {
177 const bool useLoaded = oc.
getBool(
"device.rerouting.init-with-loaded-weights");
179 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
180 while ((*i)->getNumericalID() >= (int)
myEdgeSpeeds.size()) {
189 myEdgeSpeeds[(*i)->getNumericalID()] = (*i)->getMeanSpeed();
202 if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
206 }
else if (period > 0) {
207 WRITE_WARNING(
"Rerouting is useless if the edge weights do not get updated!");
271 const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
319 std::map<std::pair<const MSEdge*, const MSEdge*>,
const MSRoute*>::iterator it =
myCachedRoutes.begin();
321 it->second->release();
327 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
328 const int id = (*i)->getNumericalID();
329 const SUMOReal currSpeed = (*i)->getMeanSpeed();
337 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
338 const int id = (*i)->getNumericalID();
339 const SUMOReal currSpeed = (*i)->getMeanSpeed();
352 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
353 const int id = (*i)->getNumericalID();
373 const bool needThread = (
myRouter == 0 && myThreadPool.isFull());
375 const bool needThread =
true;
379 const std::string routingAlgorithm = oc.
getString(
"routing-algorithm");
381 if (routingAlgorithm ==
"dijkstra") {
382 if (mayHaveRestrictions) {
389 }
else if (routingAlgorithm ==
"astar") {
390 if (mayHaveRestrictions) {
392 const AStar::LookupTable* lookup = 0;
393 if (oc.
isSet(
"device.rerouting.shortest-path-file")) {
399 const AStar::LookupTable* lookup = 0;
400 if (oc.
isSet(
"device.rerouting.shortest-path-file")) {
405 }
else if (routingAlgorithm ==
"CH") {
407 if (mayHaveRestrictions) {
414 }
else if (routingAlgorithm ==
"CHWrapper") {
420 throw ProcessError(
"Unknown routing algorithm '" + routingAlgorithm +
"'!");
426 if (myThreadPool.size() < numThreads) {
427 new WorkerThread(myThreadPool,
myRouter);
429 if (myThreadPool.size() < numThreads) {
433 if (myThreadPool.size() > 0) {
434 myThreadPool.add(
new RoutingTask(
myHolder, currentTime, onInit));
459 if (myThreadPool.size() > 0) {
462 myThreadPool.clear();
475 MSDevice_Routing::waitForAll() {
476 if (myThreadPool.size() > 0) {
477 myThreadPool.waitAll();
487 myVehicle.reroute(myTime, static_cast<WorkerThread*>(context)->getRouter(), myOnInit,
myWithTaz);
488 const MSEdge* source = *myVehicle.getRoute().begin();
489 const MSEdge* dest = myVehicle.getRoute().getLastEdge();
491 const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
495 myVehicle.getRoute().addReference();
Computes the shortest path through a contracted network.
SUMOTime myPeriod
The period with which a vehicle shall be rerouted.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
virtual bool replaceRoute(const MSRoute *route, bool onInit=false, int offset=0, bool addStops=true)=0
Replaces the current route by the given one.
const int VEHPARS_FORCE_REROUTE
SUMOTime mySkipRouting
The time for which routing may be skipped because we cannot be inserted.
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
SUMOVehicle & myHolder
The vehicle that stores the device.
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
const MSEdge * getLastEdge() const
returns the destination edge
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
SUMOTime myLastRouting
The last time a routing took place.
MSDevice_Routing(SUMOVehicle &holder, const std::string &id, SUMOTime period, SUMOTime preInsertionPeriod)
Constructor.
Notification
Definition of a vehicle state.
static SUMOReal rand()
Returns a random real number in [0, 1)
Computes the shortest path through a network using the A* algorithm.
weights: time range begin
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
SUMOTime myPreInsertionPeriod
The period with which a vehicle shall be rerouted before insertion.
static int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime wrappedRerouteCommandExecute(SUMOTime currentTime)
Performs rerouting after a period.
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
Base (microsim) event class.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
#define WRITE_WARNING(msg)
Computes the shortest path through a network using the Dijkstra algorithm.
static OptionsCont & getOptions()
Retrieves the options.
virtual SUMOVehicleClass getVClass() const =0
Returns the vehicle's access class.
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
A road/street connecting two junctions.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Routing-options.
static bool myWithTaz
whether taz shall be used at initial rerouting
SUMOReal getLength() const
return the length of the edge
void reroute(const SUMOTime currentTime, const bool onInit=false)
initiate the rerouting, create router / thread pool on first use
The edge is a district edge.
Representation of a vehicle.
bool wasSet(int what) const
Returns whether the given parameter was set.
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
virtual void reroute(SUMOTime t, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false)=0
Performs a rerouting using the given router.
static SUMOReal getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the travel time to pass an edge.
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
SUMOTime depart
The vehicle's departure time.
A wrapper for a Command function.
SUMOTime string2time(const std::string &r)
WrappingCommand< MSDevice_Routing > * myRerouteCommand
The (optional) command responsible for rerouting.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc)
Adds common command options that allow to assign devices to vehicles.
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
virtual SUMOTime addEvent(Command *operation, SUMOTime execTimeStep, AdaptType type)
Adds an Event.
static SUMOReal getEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the effort to pass an edge.
begin/end of the description of an edge
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Abstract in-vehicle device.
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
static SUMOReal getAssumedSpeed(const MSEdge *edge)
return current travel speed assumption
A pool of worker threads which distributes the tasks and collects the results.
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
The vehicle has departed (was inserted into the network)
virtual const MSRoute & getRoute() const =0
Returns the current route.
int getNumericalID() const
Returns the numerical id of the edge.
void deschedule()
Marks this Command as being descheduled.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouter
The router to use.
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
A storage for options typed value containers)
virtual const std::string & getID() const =0
Get the vehicle's ID.
MSEventControl * getInsertionEvents()
Returns the event control for insertion events.
static std::vector< SUMOReal > myEdgeSpeeds
The container of edge speeds.
void prohibit(const std::vector< E * > &toProhibit)
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
an aggreagated-output interval
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Computes a new route on vehicle insertion.
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="")
Creates the device using the output definition stored in the named option.
~MSDevice_Routing()
Destructor.
Patch the time in a way that it is at least as high as the simulation begin time. ...
Static storage of an output device and its base (abstract) implementation.
static void cleanup()
deletes the router instance
static bool checkOptions(OptionsCont &oc)
checks MSDevice_Routing-options
bool closeTag()
Closes the most recently opened tag.
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
A thread repeatingly calculating incoming tasks.
MSEdgeControl & getEdgeControl()
Returns the edge control.
static AStarRouter< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
static SUMOReal myAdaptationWeight
Information which weight prior edge efforts have.
std::vector< MSEdge * > MSEdgeVector
static SUMOReal myRandomizeWeightsFactor
Whether to disturb edge weights dynamically.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occured.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static std::vector< std::vector< SUMOReal > > myPastEdgeSpeeds
The container of edge speeds.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
SUMOTime preInsertionReroute(const SUMOTime currentTime)
Performs rerouting before insertion into the network.
const MSEdgeVector & getEdges() const
Returns loaded edges.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
Computes the shortest path through a contracted network.