86 if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
89 }
else if (period > 0) {
90 WRITE_WARNING(
"Rerouting is useless if the edge weights do not get updated!");
104 const bool useLoaded = oc.
getBool(
"device.rerouting.init-with-loaded-weights");
105 const double currentSecond =
SIMTIME;
107 while (edge->getNumericalID() >= (int)
myEdgeSpeeds.size()) {
116 myEdgeSpeeds[edge->getNumericalID()] = edge->getMeanSpeed();
154 std::map<std::pair<const MSEdge*, const MSEdge*>,
const MSRoute*>::iterator it =
myCachedRoutes.begin();
156 it->second->release();
162 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
163 if ((*i)->isDelayed()) {
164 const int id = (*i)->getNumericalID();
165 const double currSpeed = (*i)->getMeanSpeed();
174 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
175 if ((*i)->isDelayed()) {
176 const int id = (*i)->getNumericalID();
177 const double currSpeed = (*i)->getMeanSpeed();
191 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
192 const int id = (*i)->getNumericalID();
208 return routeIt->second;
217 const bool needThread = (
myRouter ==
nullptr && myThreadPool.isFull());
219 const bool needThread =
true;
221 if (needThread &&
myRouter ==
nullptr) {
223 const std::string routingAlgorithm = oc.
getString(
"routing-algorithm");
225 if (routingAlgorithm ==
"dijkstra") {
226 if (mayHaveRestrictions) {
233 }
else if (routingAlgorithm ==
"astar") {
234 if (mayHaveRestrictions) {
236 std::shared_ptr<const AStar::LookupTable> lookup;
237 if (oc.
isSet(
"astar.all-distances")) {
239 }
else if (oc.
isSet(
"astar.landmark-distances")) {
246 lookup = std::make_shared<const AStar::LMLT>(oc.
getString(
"astar.landmark-distances"),
MSEdge::getAllEdges(), &router, &vehicle,
"", oc.
getInt(
"device.rerouting.threads"));
247 vehicle.setChosenSpeedFactor(speedFactor);
252 std::shared_ptr<const AStar::LookupTable> lookup;
253 if (oc.
isSet(
"astar.all-distances")) {
254 lookup = std::shared_ptr<const AStar::LookupTable> (
new AStar::FLT(oc.
getString(
"astar.all-distances"), (int)
MSEdge::getAllEdges().size()));
255 }
else if (oc.
isSet(
"astar.landmark-distances")) {
262 lookup = std::make_shared<const AStar::LMLT>(oc.
getString(
"astar.landmark-distances"),
MSEdge::getAllEdges(), &router, &vehicle,
"", oc.
getInt(
"device.rerouting.threads"));
263 vehicle.setChosenSpeedFactor(speedFactor);
267 }
else if (routingAlgorithm ==
"CH") {
269 if (mayHaveRestrictions) {
276 }
else if (routingAlgorithm ==
"CHWrapper") {
282 throw ProcessError(
"Unknown routing algorithm '" + routingAlgorithm +
"'!");
288 if (myThreadPool.size() < numThreads) {
289 new WorkerThread(myThreadPool,
myRouter);
291 if (myThreadPool.size() < numThreads) {
295 if (myThreadPool.size() > 0) {
296 myThreadPool.add(
new RoutingTask(vehicle, currentTime, onInit));
337 if (myThreadPool.size() > 0) {
340 myThreadPool.clear();
353 MSRoutingEngine::waitForAll() {
354 if (myThreadPool.size() > 0) {
355 myThreadPool.waitAll();
365 myVehicle.reroute(myTime,
"device.rerouting", static_cast<WorkerThread*>(context)->getRouter(), myOnInit,
myWithTaz);
366 const MSEdge* source = *myVehicle.getRoute().begin();
367 const MSEdge* dest = myVehicle.getRoute().getLastEdge();
369 const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
373 myVehicle.getRoute().addReference();
Computes the shortest path through a contracted network.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
static void setEdgeTravelTime(const MSEdge *const edge, const double travelTime)
adapt the known travel time for an edge
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
static int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
static AStarRouter< MSEdge, SUMOVehicle, SUMOAbstractRouterPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
static void initWeightUpdate()
intialize period edge weight update
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Computes the shortest path through a network using the A* algorithm.
weights: time range begin
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
Base (microsim) event class.
double getLength() const
return the length of the edge
int getNumericalID() const
Returns the numerical id of the edge.
static void initEdgeWeights()
initialize the edge weights if not done before
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
#define WRITE_WARNING(msg)
static OptionsCont & getOptions()
Retrieves the options.
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.
virtual void setChosenSpeedFactor(const double factor)=0
static const MSRoute * getCachedRoute(const std::pair< const MSEdge *, const MSEdge *> &key)
return the cached route or nullptr on miss
Representation of a vehicle.
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.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static double myAdaptationWeight
Information which weight prior edge efforts have.
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
A wrapper for a Command function.
static void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const bool onInit)
initiate the rerouting, create router / thread pool on first use
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of edge speeds.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
SUMOTime string2time(const std::string &r)
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
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.
static double myRandomizeWeightsFactor
Whether to disturb edge weights dynamically.
static std::vector< double > myEdgeSpeeds
The container of edge speeds.
A pool of worker threads which distributes the tasks and collects the results.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouter
The router to use.
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
bool isTazConnector() const
static double getAssumedSpeed(const MSEdge *edge)
return current travel speed assumption
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.
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
static bool myWithTaz
whether taz shall be used at initial rerouting
A storage for options typed value containers)
const MSEdgeVector & getEdges() const
Returns loaded edges.
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.
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.
A thread repeatingly calculating incoming tasks.
MSEdgeControl & getEdgeControl()
Returns the edge control.
static void cleanup()
deletes the router instance
std::vector< MSEdge * > MSEdgeVector
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.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Computes the shortest path through a contracted network.