46#define DEBUG_COND(obj) (obj->isSelected())
74FXMutex MSRoutingEngine::myRouteCacheMutex;
94 if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
97 }
else if (period > 0) {
98 WRITE_WARNING(
TL(
"Rerouting is useless if the edge weights do not get updated!"));
117 if (edgeSpeeds.empty()) {
122 const bool useLoaded = oc.
getBool(
"device.rerouting.init-with-loaded-weights");
123 const double currentSecond =
SIMTIME;
124 double maxEdgePriority = -std::numeric_limits<double>::max();
126 while (edge->getNumericalID() >= (int)edgeSpeeds.size()) {
127 edgeSpeeds.push_back(0);
129 pastEdgeSpeeds.push_back(std::vector<double>());
136 edgeSpeeds[edge->getNumericalID()] = edge->getLength() /
MSNet::getTravelTime(edge,
nullptr, currentSecond);
138 edgeSpeeds[edge->getNumericalID()] = edge->getMeanSpeed();
141 pastEdgeSpeeds[edge->getNumericalID()] = std::vector<double>(
myAdaptationSteps, edgeSpeeds[edge->getNumericalID()]);
143 maxEdgePriority =
MAX2(maxEdgePriority, (
double)edge->getPriority());
150 throw ProcessError(
TL(
"weights.priority-factor cannot be negative."));
154 WRITE_WARNING(
TL(
"Option weights.priority-factor does not take effect because all edges have the same priority"));
184 auto it =
myThreadRNGs.find(std::this_thread::get_id());
229 for (
const MSEdge*
const e : edges) {
230 if (e->isDelayed()) {
231 const int id = e->getNumericalID();
232 double currSpeed = e->getMeanSpeed();
236#ifdef DEBUG_SEPARATE_TURNS
238 std::cout <<
SIMTIME <<
" edge=" << e->getID()
239 <<
" meanSpeed=" << e->getMeanSpeed()
240 <<
" currSpeed=" << currSpeed
251 const double currBikeSpeed = e->getMeanSpeedBike();
261 const double currBikeSpeed = e->getMeanSpeedBike();
279 for (
const MSEdge* e : edges) {
300 if (pair.second ==
nullptr) {
305 const double avgSpeed = length /
STEPS2TIME(tc.first / tc.second);
306 maxSpeed =
MAX2(avgSpeed, maxSpeed);
313 if (pair.second ==
nullptr) {
316 const int iid = pair.second->getNumericalID();
319 const double avgSpeed = length /
STEPS2TIME(tc.first / tc.second);
320 if (avgSpeed < correctedSpeed) {
321 double internalTT = pair.second->getLength() / pair.second->getSpeedLimit();
324 const double newInternalSpeed = pair.second->getLength() / internalTT;
336#ifdef DEBUG_SEPARATE_TURNS
338 std::cout <<
SIMTIME <<
" edge=" << edge->
getID() <<
" to=" << pair.first->getID() <<
" via=" << pair.second->getID()
339 <<
" origSpeed=" << currSpeed
340 <<
" maxSpeed=" << maxSpeed
341 <<
" correctedSpeed=" << correctedSpeed
342 <<
" avgSpeed=" << avgSpeed
343 <<
" internalTT=" << internalTT
344 <<
" internalSpeed=" << origInternalSpeed
345 <<
" newInternalSpeed=" << newInternalSpeed
346 <<
" virtualSpeed=" << virtualSpeed
357 return correctedSpeed;
367 return routeIt->second;
376 const std::string routingAlgorithm = oc.
getString(
"routing-algorithm");
382 if (routingAlgorithm ==
"dijkstra") {
384 }
else if (routingAlgorithm ==
"astar") {
386 std::shared_ptr<const AStar::LookupTable> lookup =
nullptr;
387 if (oc.
isSet(
"astar.all-distances")) {
389 }
else if (oc.
isSet(
"astar.landmark-distances") && vehicle !=
nullptr) {
401 }
else if (routingAlgorithm ==
"CH" && !hasPermissions) {
405 }
else if (routingAlgorithm ==
"CHWrapper" || routingAlgorithm ==
"CH") {
412 throw ProcessError(
TLF(
"Unknown routing algorithm '%'!", routingAlgorithm));
426 if (threadPool.
size() > 0) {
427 const std::vector<MFXWorkerThread*>& threads = threadPool.
getWorkers();
428 if (
static_cast<MSEdgeControl::WorkerThread*
>(threads.front())->setRouterProvider(
myRouterProvider)) {
429 for (std::vector<MFXWorkerThread*>::const_iterator t = threads.begin() + 1; t != threads.end(); ++t) {
434 for (
int i = 0; i < threadPool.
size(); i++) {
435 threadPool.
add(
new InitTask(), i);
448 const bool onInit,
const bool silent,
const MSEdgeVector& prohibited) {
456 if (threadPool.
size() > 0) {
457 threadPool.
add(
new RoutingTask(vehicle, currentTime, info, onInit, silent, prohibited));
462 if (!prohibited.empty()) {
463 router.prohibit(prohibited);
469 if (!prohibited.empty()) {
475 if (!prohibited.empty()) {
483 const bool onInit,
const bool silent,
const MSEdgeVector& prohibited) {
488 if (threadPool.
size() > 0) {
494 if (!prohibited.empty()) {
501 if (!prohibited.empty()) {
507 if (!prohibited.empty()) {
521 tc.first += travelTime;
536 if (threadPool.
size() > 0) {
538 router.prohibit(prohibited);
560 if (threadPool.
size() > 0) {
562 router.prohibit(prohibited);
602MSRoutingEngine::waitForAll() {
605 if (threadPool.
size() > 0) {
618 if (!myProhibited.empty()) {
622 myVehicle.reroute(myTime, myInfo, router, myOnInit, myWithTaz, mySilent);
625 if (!myProhibited.empty()) {
631 if (!myProhibited.empty()) {
634 const MSEdge* source = *myVehicle.getRoute().begin();
635 const MSEdge* dest = myVehicle.getRoute().getLastEdge();
637 const std::pair<const MSEdge*, const MSEdge*>
key = std::make_pair(source, dest);
638 FXMutexLock lock(myRouteCacheMutex);
650 FXMutexLock lock(myRouteCacheMutex);
652 myThreadRNGs[std::this_thread::get_id()] = rng;
std::vector< MSEdge * > MSEdgeVector
RouterProvider< MSEdge, MSLane, MSJunction, SUMOVehicle > MSRouterProvider
IntermodalRouter< MSEdge, MSLane, MSJunction, SUMOVehicle > MSTransportableRouter
#define WRITE_WARNING(msg)
std::shared_ptr< const MSRoute > ConstMSRoutePtr
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
@ SVC_PEDESTRIAN
pedestrian
@ 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
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
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.
void prohibit(const std::vector< E * > &toProhibit)
A pool of worker threads which distributes the tasks and collects the results.
void waitAll(const bool deleteFinished=true)
waits for all tasks to be finished
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< MFXWorkerThread * > & getWorkers()
int size() const
Returns the number of threads in the pool.
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, bool ignoreTransientPermissions=false) 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
MSMapMatcher * getMapMatcher() const
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
MSEdgeControl & getEdgeControl()
Returns the edge control.
static void adaptIntermodalRouter(MSTransportableRouter &router)
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 std::map< std::pair< const MSEdge *, const MSEdge * >, ConstMSRoutePtr > myCachedRoutes
The container of pre-calculated routes.
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
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 SumoRNG * getThreadRNG()
returns RNG associated with the current thread
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 std::map< std::thread::id, SumoRNG * > myThreadRNGs
static void addEdgeTravelTime(const MSEdge &edge, const SUMOTime travelTime)
record actual travel time for an edge
static void initWeightUpdate()
intialize period edge weight update
static void initEdgeWeights(SUMOVehicleClass svc)
initialize the edge weights if not done before
static MSVehicleRouter & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector &prohibited=MSEdgeVector())
return the vehicle router instance
static bool myHaveRoutingThreads
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 ConstMSRoutePtr getCachedRoute(const std::pair< const MSEdge *, const MSEdge * > &key)
return the cached route or nullptr on miss
static int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
static MSRouterProvider * myRouterProvider
The router to use.
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
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 MSTransportableRouter & getIntermodalRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector())
return the person router instance
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
int getRNGIndex() const
returns the index of the associated RNG
bool reroute(SUMOTime t, const std::string &info, MSTransportableRouter &router, const bool onInit=false, const bool withTaz=false, const bool silent=false, const MSEdge *sink=nullptr)
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 & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
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.
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
IntermodalRouter< E, L, N, V > & getIntermodalRouter() 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 bool reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false, const bool silent=false, const MSEdge *sink=nullptr)=0
Performs a rerouting using the given router.
virtual void setChosenSpeedFactor(const double factor)=0
static int parseCarWalkTransfer(const OptionsCont &oc, const bool hasTaxi=false)
A wrapper for a Command function.
#define UNUSED_PARAMETER(x)
@ key
the parser read a key of a value in an object