45 #define DEBUG_COND(obj) (obj->isSelected())
71 FXMutex MSRoutingEngine::myRouteCacheMutex;
91 if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
94 }
else if (period > 0) {
95 WRITE_WARNING(
"Rerouting is useless if the edge weights do not get updated!");
114 if (edgeSpeeds.empty()) {
119 const bool useLoaded = oc.
getBool(
"device.rerouting.init-with-loaded-weights");
120 const double currentSecond =
SIMTIME;
121 double maxEdgePriority = -std::numeric_limits<double>::max();
123 while (edge->getNumericalID() >= (
int)edgeSpeeds.size()) {
124 edgeSpeeds.push_back(0);
126 pastEdgeSpeeds.push_back(std::vector<double>());
133 edgeSpeeds[edge->getNumericalID()] = edge->getLength() /
MSNet::getTravelTime(edge,
nullptr, currentSecond);
135 edgeSpeeds[edge->getNumericalID()] = edge->getMeanSpeed();
138 pastEdgeSpeeds[edge->getNumericalID()] = std::vector<double>(
myAdaptationSteps, edgeSpeeds[edge->getNumericalID()]);
140 maxEdgePriority =
MAX2(maxEdgePriority, (
double)edge->getPriority());
147 throw ProcessError(
"weights.priority-factor cannot be negative.");
151 WRITE_WARNING(
"Option weights.priority-factor does not take effect because all edges have the same priority");
213 std::map<std::pair<const MSEdge*, const MSEdge*>,
const MSRoute*>::iterator it =
myCachedRoutes.begin();
215 it->second->release();
221 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
222 if ((*i)->isDelayed()) {
223 const int id = (*i)->getNumericalID();
224 double currSpeed = (*i)->getMeanSpeed();
228 #ifdef DEBUG_SEPARATE_TURNS
230 std::cout <<
SIMTIME <<
" edge=" << (*i)->getID()
231 <<
" meanSpeed=" << (*i)->getMeanSpeed()
232 <<
" currSpeed=" << currSpeed
243 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
244 if ((*i)->isDelayed()) {
245 const int id = (*i)->getNumericalID();
246 const double currSpeed = (*i)->getMeanSpeedBike();
256 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
257 if ((*i)->isDelayed()) {
258 const int id = (*i)->getNumericalID();
259 const double currSpeed = (*i)->getMeanSpeed();
266 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
267 if ((*i)->isDelayed()) {
268 const int id = (*i)->getNumericalID();
269 const double currSpeed = (*i)->getMeanSpeedBike();
284 for (
const MSEdge* e : edges) {
307 const double avgSpeed = length /
STEPS2TIME(tc.first / tc.second);
308 maxSpeed =
MAX2(avgSpeed, maxSpeed);
315 const int iid = pair.second->getNumericalID();
318 const double avgSpeed = length /
STEPS2TIME(tc.first / tc.second);
319 if (avgSpeed < correctedSpeed) {
320 double internalTT = pair.second->getLength() / pair.second->getSpeedLimit();
323 const double newInternalSpeed = pair.second->getLength() / internalTT;
335 #ifdef DEBUG_SEPARATE_TURNS
337 std::cout <<
SIMTIME <<
" edge=" << edge->
getID() <<
" to=" << pair.first->getID() <<
" via=" << pair.second->getID()
338 <<
" origSpeed=" << currSpeed
339 <<
" maxSpeed=" << maxSpeed
340 <<
" correctedSpeed=" << correctedSpeed
341 <<
" avgSpeed=" << avgSpeed
342 <<
" internalTT=" << internalTT
343 <<
" internalSpeed=" << origInternalSpeed
344 <<
" newInternalSpeed=" << newInternalSpeed
345 <<
" virtualSpeed=" << virtualSpeed
356 return correctedSpeed;
366 return routeIt->second;
375 const std::string routingAlgorithm = oc.
getString(
"routing-algorithm");
381 if (routingAlgorithm ==
"dijkstra") {
383 }
else if (routingAlgorithm ==
"astar") {
385 std::shared_ptr<const AStar::LookupTable> lookup =
nullptr;
386 if (oc.
isSet(
"astar.all-distances")) {
388 }
else if (oc.
isSet(
"astar.landmark-distances") && vehicle !=
nullptr) {
396 nullptr, vehicle,
"", oc.
getInt(
"device.rerouting.threads"));
400 }
else if (routingAlgorithm ==
"CH" && !hasPermissions) {
404 }
else if (routingAlgorithm ==
"CHWrapper" || routingAlgorithm ==
"CH") {
411 throw ProcessError(
"Unknown routing algorithm '" + routingAlgorithm +
"'!");
422 if (threadPool.
size() > 0) {
423 const std::vector<FXWorkerThread*>& threads = threadPool.
getWorkers();
424 if (
static_cast<MSEdgeControl::WorkerThread*
>(threads.front())->setRouterProvider(
myRouterProvider)) {
425 for (std::vector<FXWorkerThread*>::const_iterator t = threads.begin() + 1; t != threads.end(); ++t) {
437 const bool onInit,
const bool silent,
const MSEdgeVector& prohibited) {
445 if (threadPool.
size() > 0) {
446 threadPool.
add(
new RoutingTask(vehicle, currentTime, info, onInit, silent, prohibited));
451 if (!prohibited.empty()) {
452 router.prohibit(prohibited);
458 if (!prohibited.empty()) {
464 if (!prohibited.empty()) {
478 tc.first += travelTime;
493 if (threadPool.
size() > 0) {
495 router.prohibit(prohibited);
533 MSRoutingEngine::waitForAll() {
536 if (threadPool.
size() > 0) {
549 if (!myProhibited.empty()) {
553 myVehicle.reroute(myTime, myInfo, router, myOnInit, myWithTaz, mySilent);
556 if (!myProhibited.empty()) {
562 if (!myProhibited.empty()) {
565 const MSEdge* source = *myVehicle.getRoute().begin();
566 const MSEdge* dest = myVehicle.getRoute().getLastEdge();
568 const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
569 FXMutexLock lock(myRouteCacheMutex);
572 myVehicle.getRoute().addReference();
std::vector< MSEdge * > MSEdgeVector
#define WRITE_WARNING(msg)
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_EDGE
begin/end of the description of an edge
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
double gWeightsRandomFactor
Computes the shortest path through a network using the A* algorithm.
Computes the shortest path through a contracted network.
Computes the shortest path through a contracted network.
Base (microsim) event class.
Computes the shortest path through a network using the Dijkstra algorithm.
A pool of worker threads which distributes the tasks and collects the results.
void add(Task *const t, int index=-1)
Gives a number to the given task and assigns it to the worker with the given index....
const std::vector< FXWorkerThread * > & getWorkers()
int size() const
Returns the number of threads in the pool.
void waitAll(const bool deleteFinished=true)
waits for all tasks to be finished
A thread repeatingly calculating incoming tasks.
const MSEdgeVector & getEdges() const
Returns loaded edges.
A road/street connecting two junctions.
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
int getPriority() const
Returns the priority of the edge.
const MSConstEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges with internal vias, restricted by vClass.
double getLength() const
return the length of the edge
bool isTazConnector() const
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
int getNumericalID() const
Returns the numerical id of the edge.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static double gWeightsSeparateTurns
Whether turning specific weights are estimated (and how much)
static int gNumThreads
how many threads to use
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
MSEdgeControl & getEdgeControl()
Returns the edge control.
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
static double myAdaptationWeight
Information which weight prior edge efforts have.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
static double myMinEdgePriority
Minimum priority for all edges.
static std::vector< TimeAndCount > myEdgeTravelTimes
Sum of travel times experienced by equipped vehicles for each edge.
static double getEffortBike(const MSEdge *const e, const SUMOVehicle *const v, double t)
static void setEdgeTravelTime(const MSEdge *const edge, const double travelTime)
adapt the known travel time for an edge
static void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const std::string &info, const bool onInit=false, const bool silent=false, const MSEdgeVector &prohibited=MSEdgeVector())
initiate the rerouting, create router / thread pool on first use
static double myEdgePriorityRange
the difference between maximum and minimum priority for all edges
static double myPriorityFactor
Coefficient for factoring edge priority into routing weight.
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
static const MSRoute * getCachedRoute(const std::pair< const MSEdge *, const MSEdge * > &key)
return the cached route or nullptr on miss
static bool myBikeSpeeds
whether separate speeds for bicycles shall be tracked
static void _initEdgeWeights(std::vector< double > &edgeSpeeds, std::vector< std::vector< double > > &pastEdgeSpeeds)
initialized edge speed storage into the given containers
static MSRouterProvider * myRouterProvider
The router to use.
static bool myWithTaz
whether taz shall be used at initial rerouting
static std::vector< std::vector< double > > myPastEdgeBikeSpeeds
static std::vector< double > myEdgeSpeeds
The container of edge speeds.
std::pair< SUMOTime, int > TimeAndCount
static void addEdgeTravelTime(const MSEdge &edge, const SUMOTime travelTime)
record actual travel time for an edge
static void initWeightUpdate()
intialize period edge weight update
RouterProvider< MSEdge, MSLane, MSJunction, SUMOVehicle > MSRouterProvider
static void initEdgeWeights(SUMOVehicleClass svc)
initialize the edge weights if not done before
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
static void cleanup()
deletes the router instance
static void initRouter(SUMOVehicle *vehicle=nullptr)
static SUMOAbstractRouter< MSEdge, SUMOVehicle >::Operation myEffortFunc
static int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of past edge speeds (when using a simple moving average)
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
static double getAssumedSpeed(const MSEdge *edge, const SUMOVehicle *veh)
return current travel speed assumption
static double patchSpeedForTurns(const MSEdge *edge, double currSpeed)
static double getEffortExtra(const MSEdge *const e, const SUMOVehicle *const v, double t)
static std::vector< double > myEdgeBikeSpeeds
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
SUMOAbstractRouter< E, V > & getVehicleRouter(SUMOVehicleClass svc) const
virtual void prohibit(const std::vector< E * > &toProhibit)
virtual double getChosenSpeedFactor() const =0
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
Representation of a vehicle.
virtual void reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false, const bool silent=false)=0
Performs a rerouting using the given router.
virtual void setChosenSpeedFactor(const double factor)=0
A wrapper for a Command function.