78 oc.
addSynonyme(
"device.rerouting.period",
"device.routing.period",
true);
79 oc.
addDescription(
"device.rerouting.period",
"Routing",
"The period with which the vehicle shall be rerouted");
82 oc.
addSynonyme(
"device.rerouting.pre-period",
"device.routing.pre-period",
true);
83 oc.
addDescription(
"device.rerouting.pre-period",
"Routing",
"The rerouting period before depart");
86 oc.
addSynonyme(
"device.rerouting.adaptation-weight",
"device.routing.adaptation-weight",
true);
87 oc.
addDescription(
"device.rerouting.adaptation-weight",
"Routing",
"The weight of prior edge weights for exponential moving average");
90 oc.
addSynonyme(
"device.rerouting.adaptation-steps",
"device.routing.adaptation-steps",
true);
91 oc.
addDescription(
"device.rerouting.adaptation-steps",
"Routing",
"The number of steps for moving average weight of prior edge weights");
94 oc.
addSynonyme(
"device.rerouting.adaptation-interval",
"device.routing.adaptation-interval",
true);
95 oc.
addDescription(
"device.rerouting.adaptation-interval",
"Routing",
"The interval for updating the edge weights");
98 oc.
addSynonyme(
"device.rerouting.with-taz",
"device.routing.with-taz",
true);
99 oc.
addSynonyme(
"device.rerouting.with-taz",
"with-taz");
100 oc.
addDescription(
"device.rerouting.with-taz",
"Routing",
"Use zones (districts) as routing start- and endpoints");
103 oc.
addDescription(
"device.rerouting.init-with-loaded-weights",
"Routing",
"Use weight files given with option --weight-files for initializing edge weights");
106 oc.
addDescription(
"device.rerouting.threads",
"Routing",
"The number of parallel execution threads used for rerouting");
109 oc.
addDescription(
"device.rerouting.output",
"Routing",
"Save adapting weights to FILE");
122 if (oc.
getInt(
"device.rerouting.adaptation-steps") > 0 && !oc.
isDefault(
"device.rerouting.adaptation-weight")) {
123 WRITE_ERROR(
"Only one of the options 'device.rerouting.adaptation-steps' or 'device.rerouting.adaptation-weight' may be given.");
126 if (oc.
getFloat(
"weights.random-factor") < 1) {
127 WRITE_ERROR(
"weights.random-factor cannot be less than 1");
131 WRITE_ERROR(
"Negative value for device.rerouting.adaptation-interval!");
134 if (oc.
getFloat(
"device.rerouting.adaptation-weight") < 0. ||
135 oc.
getFloat(
"device.rerouting.adaptation-weight") > 1.) {
136 WRITE_ERROR(
"The value for device.rerouting.adaptation-weight must be between 0 and 1!");
140 if (oc.
getInt(
"device.rerouting.threads") > 1) {
141 WRITE_ERROR(
"Parallel routing is only possible when compiled with Fox.");
170 if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
173 }
else if (period > 0) {
174 WRITE_WARNING(
"Rerouting is useless if the edge weights do not get updated!");
232 const bool useLoaded = oc.
getBool(
"device.rerouting.init-with-loaded-weights");
233 const double currentSecond =
SIMTIME;
235 while (edge->getNumericalID() >= (int)
myEdgeSpeeds.size()) {
244 myEdgeSpeeds[edge->getNumericalID()] = edge->getMeanSpeed();
264 const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
315 std::map<std::pair<const MSEdge*, const MSEdge*>,
const MSRoute*>::iterator it =
myCachedRoutes.begin();
317 it->second->release();
323 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
324 if ((*i)->isDelayed()) {
325 const int id = (*i)->getNumericalID();
326 const double currSpeed = (*i)->getMeanSpeed();
335 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
336 if ((*i)->isDelayed()) {
337 const int id = (*i)->getNumericalID();
338 const double currSpeed = (*i)->getMeanSpeed();
352 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
353 const int id = (*i)->getNumericalID();
374 const bool needThread = (
myRouter == 0 && myThreadPool.isFull());
376 const bool needThread =
true;
380 const std::string routingAlgorithm = oc.
getString(
"routing-algorithm");
382 if (routingAlgorithm ==
"dijkstra") {
383 if (mayHaveRestrictions) {
390 }
else if (routingAlgorithm ==
"astar") {
391 if (mayHaveRestrictions) {
393 const AStar::LookupTable* lookup = 0;
394 if (oc.
isSet(
"astar.all-distances")) {
396 }
else if (oc.
isSet(
"astar.landmark-distances")) {
404 myHolder.setChosenSpeedFactor(speedFactor);
409 const AStar::LookupTable* lookup = 0;
410 if (oc.
isSet(
"astar.all-distances")) {
412 }
else if (oc.
isSet(
"astar.landmark-distances")) {
420 myHolder.setChosenSpeedFactor(speedFactor);
424 }
else if (routingAlgorithm ==
"CH") {
426 if (mayHaveRestrictions) {
433 }
else if (routingAlgorithm ==
"CHWrapper") {
439 throw ProcessError(
"Unknown routing algorithm '" + routingAlgorithm +
"'!");
445 if (myThreadPool.size() < numThreads) {
446 new WorkerThread(myThreadPool,
myRouter);
448 if (myThreadPool.size() < numThreads) {
452 if (myThreadPool.size() > 0) {
453 myThreadPool.add(
new RoutingTask(
myHolder, currentTime, onInit));
477 const std::string edgeID = key.substr(5);
483 }
else if (key ==
"period") {
499 const std::string edgeID = key.substr(5);
505 }
else if (key ==
"period") {
510 }
else if (oldPeriod <= 0) {
524 std::vector<std::string> internals;
545 if (myThreadPool.size() > 0) {
548 myThreadPool.clear();
561 MSDevice_Routing::waitForAll() {
562 if (myThreadPool.size() > 0) {
563 myThreadPool.waitAll();
573 myVehicle.reroute(myTime,
"device.rerouting", static_cast<WorkerThread*>(context)->getRouter(), myOnInit,
myWithTaz);
574 const MSEdge* source = *myVehicle.getRoute().begin();
575 const MSEdge* dest = myVehicle.getRoute().getLastEdge();
577 const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
581 myVehicle.getRoute().addReference();
Computes the shortest path through a contracted network.
SUMOTime myPeriod
The period with which a vehicle shall be rerouted.
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key ...
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
const int VEHPARS_FORCE_REROUTE
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
static double myRandomizeWeightsFactor
Whether to disturb edge weights dynamically.
SUMOTime mySkipRouting
The time for which routing may be skipped because we cannot be inserted.
virtual const MSRoute & getRoute() const =0
Returns the current route.
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
SUMOVehicle & myHolder
The vehicle that stores the device.
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
SUMOTime myLastRouting
The last time a routing took place.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
MSDevice_Routing(SUMOVehicle &holder, const std::string &id, SUMOTime period, SUMOTime preInsertionPeriod)
Constructor.
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
Computes the shortest path through a network using the A* algorithm.
weights: time range begin
const std::string deviceName() const
return the name for this type of device
SUMOTime myPreInsertionPeriod
The period with which a vehicle shall be rerouted before insertion.
virtual bool replaceRoute(const MSRoute *route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true)=0
Replaces the current route by the given one.
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).
void saveState(OutputDevice &out) const
Saves the state of the device.
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary...
const MSEdge * getLastEdge() const
returns the destination edge
SUMOTime wrappedRerouteCommandExecute(SUMOTime currentTime)
Performs rerouting after a period.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
const std::string & getID() const
Returns the id.
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
Base (microsim) event class.
static AStarRouter< MSEdge, SUMOVehicle, SUMOAbstractRouterPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
double getLength() const
return the length of the edge
int getNumericalID() const
Returns the numerical id of the edge.
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of edge speeds.
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
static double myAdaptationWeight
Information which weight prior edge efforts have.
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
void prohibit(const std::vector< E *> &toProhibit)
A road/street connecting two junctions.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
virtual SUMOVehicleClass getVClass() const =0
Returns the vehicle's access class.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Routing-options.
static bool myWithTaz
whether taz shall be used at initial rerouting
void reroute(const SUMOTime currentTime, const bool onInit=false)
initiate the rerouting, create router / thread pool on first use
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
virtual void setChosenSpeedFactor(const double factor)=0
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Representation of a vehicle.
Encapsulated SAX-Attributes.
Computes the shortest path through a network using the Dijkstra algorithm.
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
static void initEdgeWeights()
initialize the edge weights if not done before
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
SUMOTime depart
The vehicle's departure time.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
A wrapper for a Command function.
static void initWeightUpdate()
intialize period edge weight update
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
SUMOTime string2time(const std::string &r)
static std::vector< double > myEdgeSpeeds
The container of edge speeds.
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.
virtual double getChosenSpeedFactor() const =0
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
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.
A pool of worker threads which distributes the tasks and collects the results.
The vehicle has departed (was inserted into the network)
bool isTazConnector() const
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.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
A storage for options typed value containers)
static double _2double(const E *const data)
converts a char-type array into the double value described by it
MSEventControl * getInsertionEvents()
Returns the event control for insertion events.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes a new route on vehicle insertion.
const MSEdgeVector & getEdges() const
Returns loaded edges.
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v, bool outputOptionSet)
Determines whether a vehicle should get a certain device.
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
bool wasSet(int what) const
Returns whether the given parameter was set.
an aggreagated-output interval
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.
Static storage of an output device and its base (abstract) implementation.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static void cleanup()
deletes the router instance
static bool checkOptions(OptionsCont &oc)
checks MSDevice_Routing-options
A thread repeatingly calculating incoming tasks.
MSEdgeControl & getEdgeControl()
Returns the edge control.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
std::vector< MSEdge * > MSEdgeVector
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
static double getAssumedSpeed(const MSEdge *edge)
return current travel speed assumption
virtual void reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false)=0
Performs a rerouting using the given router.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
Representation of a lane in the micro simulation.
virtual const std::string & getID() const =0
Get the vehicle's ID.
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key ...
SUMOTime preInsertionReroute(const SUMOTime currentTime)
Performs rerouting before insertion into the network.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
Computes the shortest path through a contracted network.