Eclipse SUMO - Simulation of Urban MObility
MSRoutingEngine.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2007-2022 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
22// A device that performs vehicle rerouting based on current edge speeds
23/****************************************************************************/
24#include <config.h>
25
26#include "MSRoutingEngine.h"
27#include <microsim/MSNet.h>
28#include <microsim/MSLane.h>
29#include <microsim/MSEdge.h>
32#include <microsim/MSGlobals.h>
43
44//#define DEBUG_SEPARATE_TURNS
45#define DEBUG_COND(obj) (obj->isSelected())
46
47// ===========================================================================
48// static member variables
49// ===========================================================================
50std::vector<double> MSRoutingEngine::myEdgeSpeeds;
51std::vector<double> MSRoutingEngine::myEdgeBikeSpeeds;
52std::vector<MSRoutingEngine::TimeAndCount> MSRoutingEngine::myEdgeTravelTimes;
53std::vector<std::vector<double> > MSRoutingEngine::myPastEdgeSpeeds;
54std::vector<std::vector<double> > MSRoutingEngine::myPastEdgeBikeSpeeds;
64std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> MSRoutingEngine::myCachedRoutes;
66double MSRoutingEngine::myMinEdgePriority(std::numeric_limits<double>::max());
68std::map<std::thread::id, SumoRNG*> MSRoutingEngine::myThreadRNGs;
69
71#ifdef HAVE_FOX
72FXMutex MSRoutingEngine::myRouteCacheMutex;
73#endif
74
75
76// ===========================================================================
77// method definitions
78// ===========================================================================
79void
81 if (myAdaptationInterval == -1) {
83 myEdgeSpeeds.clear();
84 myEdgeTravelTimes.clear();
88 myWithTaz = oc.getBool("device.rerouting.with-taz");
89 myAdaptationInterval = string2time(oc.getString("device.rerouting.adaptation-interval"));
90 myAdaptationWeight = oc.getFloat("device.rerouting.adaptation-weight");
91 const SUMOTime period = string2time(oc.getString("device.rerouting.period"));
92 if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
95 } else if (period > 0) {
96 WRITE_WARNING(TL("Rerouting is useless if the edge weights do not get updated!"));
97 }
98 OutputDevice::createDeviceByOption("device.rerouting.output", "weights", "meandata_file.xsd");
99 }
100}
101
102
103void
105 if (myBikeSpeeds && svc == SVC_BICYCLE) {
107 } else {
109 }
110}
111
112
113void
114MSRoutingEngine::_initEdgeWeights(std::vector<double>& edgeSpeeds, std::vector<std::vector<double> >& pastEdgeSpeeds) {
115 if (edgeSpeeds.empty()) {
117 if (myAdaptationWeight == 0 || !oc.isDefault("device.rerouting.adaptation-steps")) {
118 myAdaptationSteps = oc.getInt("device.rerouting.adaptation-steps");
119 }
120 const bool useLoaded = oc.getBool("device.rerouting.init-with-loaded-weights");
121 const double currentSecond = SIMTIME;
122 double maxEdgePriority = -std::numeric_limits<double>::max();
123 for (const MSEdge* const edge : MSNet::getInstance()->getEdgeControl().getEdges()) {
124 while (edge->getNumericalID() >= (int)edgeSpeeds.size()) {
125 edgeSpeeds.push_back(0);
126 if (myAdaptationSteps > 0) {
127 pastEdgeSpeeds.push_back(std::vector<double>());
128 }
129 if (MSGlobals::gWeightsSeparateTurns && edgeSpeeds == myEdgeSpeeds) {
130 myEdgeTravelTimes.push_back(TimeAndCount(0, 0));
131 }
132 }
133 if (useLoaded) {
134 edgeSpeeds[edge->getNumericalID()] = edge->getLength() / MSNet::getTravelTime(edge, nullptr, currentSecond);
135 } else {
136 edgeSpeeds[edge->getNumericalID()] = edge->getMeanSpeed();
137 }
138 if (myAdaptationSteps > 0) {
139 pastEdgeSpeeds[edge->getNumericalID()] = std::vector<double>(myAdaptationSteps, edgeSpeeds[edge->getNumericalID()]);
140 }
141 maxEdgePriority = MAX2(maxEdgePriority, (double)edge->getPriority());
142 myMinEdgePriority = MIN2(myMinEdgePriority, (double)edge->getPriority());
143 }
144 myEdgePriorityRange = maxEdgePriority - myMinEdgePriority;
146 myPriorityFactor = oc.getFloat("weights.priority-factor");
147 if (myPriorityFactor < 0) {
148 throw ProcessError("weights.priority-factor cannot be negative.");
149 }
150 if (myPriorityFactor > 0) {
151 if (myEdgePriorityRange == 0) {
152 WRITE_WARNING(TL("Option weights.priority-factor does not take effect because all edges have the same priority"));
154 }
155 }
156 }
157}
158
159
160double
161MSRoutingEngine::getEffort(const MSEdge* const e, const SUMOVehicle* const v, double) {
162 const int id = e->getNumericalID();
163 if (id < (int)myEdgeSpeeds.size()) {
164 return MAX2(e->getLength() / MAX2(myEdgeSpeeds[id], NUMERICAL_EPS), e->getMinimumTravelTime(v));
165 }
166 return e->getMinimumTravelTime(v);
167}
168
169
170double
171MSRoutingEngine::getEffortBike(const MSEdge* const e, const SUMOVehicle* const v, double) {
172 const int id = e->getNumericalID();
173 if (id < (int)myEdgeBikeSpeeds.size()) {
174 return MAX2(e->getLength() / MAX2(myEdgeBikeSpeeds[id], NUMERICAL_EPS), e->getMinimumTravelTime(v));
175 }
176 return e->getMinimumTravelTime(v);
177}
178
179SumoRNG*
181 if (myThreadRNGs.size() > 0) {
182 auto it = myThreadRNGs.find(std::this_thread::get_id());
183 if (it != myThreadRNGs.end()) {
184 return it->second;
185 }
186 std::cout << " something bad happended\n";
187 }
188 return nullptr;
189}
190
191
192double
193MSRoutingEngine::getEffortExtra(const MSEdge* const e, const SUMOVehicle* const v, double t) {
194 double effort = (!myBikeSpeeds || v == nullptr || v->getVClass() != SVC_BICYCLE
195 ? getEffort(e, v, t)
196 : getEffortBike(e, v, t));
197 if (gWeightsRandomFactor != 1.) {
199 }
200 if (myPriorityFactor != 0) {
201 // lower priority should result in higher effort (and the edge with
202 // minimum priority receives a factor of 1 + myPriorityFactor
203 const double relativeInversePrio = 1 - ((e->getPriority() - myMinEdgePriority) / myEdgePriorityRange);
204 effort *= 1 + relativeInversePrio * myPriorityFactor;
205 }
206 return effort;
207}
208
209
210double
212 return edge->getLength() / myEffortFunc(edge, veh, 0);
213}
214
215
219 if (myBikeSpeeds) {
221 }
222 if (MSNet::getInstance()->getVehicleControl().getDepartedVehicleNo() == 0) {
224 }
225 std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*>::iterator it = myCachedRoutes.begin();
226 for (; it != myCachedRoutes.end(); ++it) {
227 it->second->release();
228 }
229 myCachedRoutes.clear();
231 const double newWeightFactor = (double)(1. - myAdaptationWeight);
232 for (const MSEdge* const e : edges) {
233 if (e->isDelayed()) {
234 const int id = e->getNumericalID();
235 double currSpeed = e->getMeanSpeed();
236 if (MSGlobals::gWeightsSeparateTurns > 0 && e->getNumSuccessors() > 1) {
237 currSpeed = patchSpeedForTurns(e, currSpeed);
238 }
239#ifdef DEBUG_SEPARATE_TURNS
240 if (DEBUG_COND(e->getLanes()[0])) {
241 std::cout << SIMTIME << " edge=" << e->getID()
242 << " meanSpeed=" << e->getMeanSpeed()
243 << " currSpeed=" << currSpeed
244 << " oldestSpeed=" << myPastEdgeSpeeds[id][myAdaptationStepsIndex]
245 << " oldAvg=" << myEdgeSpeeds[id]
246 << "\n";
247 }
248#endif
249 if (myAdaptationSteps > 0) {
250 // moving average
253 if (myBikeSpeeds) {
254 const double currBikeSpeed = e->getMeanSpeedBike();
256 myPastEdgeBikeSpeeds[id][myAdaptationStepsIndex] = currBikeSpeed;
257 }
258 } else {
259 // exponential moving average
260 if (currSpeed != myEdgeSpeeds[id]) {
261 myEdgeSpeeds[id] = myEdgeSpeeds[id] * myAdaptationWeight + currSpeed * newWeightFactor;
262 }
263 if (myBikeSpeeds) {
264 const double currBikeSpeed = e->getMeanSpeedBike();
265 if (currBikeSpeed != myEdgeBikeSpeeds[id]) {
266 myEdgeBikeSpeeds[id] = myEdgeBikeSpeeds[id] * myAdaptationWeight + currBikeSpeed * newWeightFactor;
267 }
268 }
269 }
270 }
271 }
272 if (myAdaptationSteps > 0) {
274 }
275 myLastAdaptation = currentTime + DELTA_T; // because we run at the end of the time step
276 if (OptionsCont::getOptions().isSet("device.rerouting.output")) {
277 OutputDevice& dev = OutputDevice::getDeviceByOption("device.rerouting.output");
279 dev.writeAttr(SUMO_ATTR_ID, "device.rerouting");
280 dev.writeAttr(SUMO_ATTR_BEGIN, STEPS2TIME(currentTime));
282 for (const MSEdge* e : edges) {
284 dev.writeAttr(SUMO_ATTR_ID, e->getID());
285 dev.writeAttr("traveltime", myEffortFunc(e, nullptr, STEPS2TIME(currentTime)));
286 if (myBikeSpeeds) {
287 // @note edge-priority is not included here
288 dev.writeAttr("traveltimeBike", getEffortBike(e, nullptr, STEPS2TIME(currentTime)));
289 }
290 dev.closeTag();
291 }
292 dev.closeTag();
293 }
295}
296
297
298double
299MSRoutingEngine::patchSpeedForTurns(const MSEdge* edge, double currSpeed) {
300 const double length = edge->getLength();
301 double maxSpeed = 0;
302 for (const auto& pair : edge->getViaSuccessors()) {
303 if (pair.second == nullptr) {
304 continue;
305 }
306 TimeAndCount& tc = myEdgeTravelTimes[pair.second->getNumericalID()];
307 if (tc.second > 0) {
308 const double avgSpeed = length / STEPS2TIME(tc.first / tc.second);
309 maxSpeed = MAX2(avgSpeed, maxSpeed);
310 }
311 }
312 if (maxSpeed > 0) {
313 // perform correction
314 const double correctedSpeed = MSGlobals::gWeightsSeparateTurns * maxSpeed + (1 - MSGlobals::gWeightsSeparateTurns) * currSpeed;
315 for (const auto& pair : edge->getViaSuccessors()) {
316 if (pair.second == nullptr) {
317 continue;
318 }
319 const int iid = pair.second->getNumericalID();
321 if (tc.second > 0) {
322 const double avgSpeed = length / STEPS2TIME(tc.first / tc.second);
323 if (avgSpeed < correctedSpeed) {
324 double internalTT = pair.second->getLength() / pair.second->getSpeedLimit();
325 internalTT += (length / avgSpeed - length / correctedSpeed) * MSGlobals::gWeightsSeparateTurns;
326 const double origInternalSpeed = myEdgeSpeeds[iid];
327 const double newInternalSpeed = pair.second->getLength() / internalTT;
328 const double origCurrSpeed = myPastEdgeSpeeds[iid][myAdaptationStepsIndex];
329
330 myEdgeSpeeds[iid] = newInternalSpeed;
331 // to ensure myEdgeSpeed reverts to the speed limit
332 // when there are no updates, we also have to patch
333 // myPastEdgeSpeeds with a virtual value that is consistent
334 // with the updated speed
335 // note: internal edges were handled before the normal ones
336 const double virtualSpeed = (newInternalSpeed - (origInternalSpeed - origCurrSpeed / myAdaptationSteps)) * myAdaptationSteps;
337 myPastEdgeSpeeds[iid][myAdaptationStepsIndex] = virtualSpeed;
338
339#ifdef DEBUG_SEPARATE_TURNS
340 if (DEBUG_COND(pair.second->getLanes()[0])) {
341 std::cout << SIMTIME << " edge=" << edge->getID() << " to=" << pair.first->getID() << " via=" << pair.second->getID()
342 << " origSpeed=" << currSpeed
343 << " maxSpeed=" << maxSpeed
344 << " correctedSpeed=" << correctedSpeed
345 << " avgSpeed=" << avgSpeed
346 << " internalTT=" << internalTT
347 << " internalSpeed=" << origInternalSpeed
348 << " newInternalSpeed=" << newInternalSpeed
349 << " virtualSpeed=" << virtualSpeed
350 << "\n";
351 }
352#endif
353 }
354 if (myAdaptationStepsIndex == 0) {
355 tc.first = 0;
356 tc.second = 0;
357 }
358 }
359 }
360 return correctedSpeed;
361 }
362 return currSpeed;
363}
364
365
366const MSRoute*
367MSRoutingEngine::getCachedRoute(const std::pair<const MSEdge*, const MSEdge*>& key) {
368 auto routeIt = myCachedRoutes.find(key);
369 if (routeIt != myCachedRoutes.end()) {
370 return routeIt->second;
371 }
372 return nullptr;
373}
374
375
376void
379 const std::string routingAlgorithm = oc.getString("routing-algorithm");
380 const bool hasPermissions = MSNet::getInstance()->hasPermissions();
381 myBikeSpeeds = oc.getBool("device.rerouting.bike-speeds");
383
385 if (routingAlgorithm == "dijkstra") {
386 router = new DijkstraRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, myEffortFunc, nullptr, false, nullptr, true);
387 } else if (routingAlgorithm == "astar") {
389 std::shared_ptr<const AStar::LookupTable> lookup = nullptr;
390 if (oc.isSet("astar.all-distances")) {
391 lookup = std::make_shared<const AStar::FLT>(oc.getString("astar.all-distances"), (int)MSEdge::getAllEdges().size());
392 } else if (oc.isSet("astar.landmark-distances") && vehicle != nullptr) {
393 const double speedFactor = vehicle->getChosenSpeedFactor();
394 // we need an exemplary vehicle with speedFactor 1
395 vehicle->setChosenSpeedFactor(1);
398 string2time(oc.getString("begin")), string2time(oc.getString("end")), SUMOTime_MAX, hasPermissions, 1);
399 lookup = std::make_shared<const AStar::LMLT>(oc.getString("astar.landmark-distances"), MSEdge::getAllEdges(), &chrouter,
400 nullptr, vehicle, "", oc.getInt("device.rerouting.threads"));
401 vehicle->setChosenSpeedFactor(speedFactor);
402 }
403 router = new AStar(MSEdge::getAllEdges(), true, myEffortFunc, lookup, true);
404 } else if (routingAlgorithm == "CH" && !hasPermissions) {
407 MSEdge::getAllEdges(), true, myEffortFunc, vehicle == nullptr ? SVC_PASSENGER : vehicle->getVClass(), weightPeriod, true, false);
408 } else if (routingAlgorithm == "CHWrapper" || routingAlgorithm == "CH") {
409 // use CHWrapper instead of CH if the net has permissions
413 string2time(oc.getString("begin")), string2time(oc.getString("end")), weightPeriod, hasPermissions, oc.getInt("device.rerouting.threads"));
414 } else {
415 throw ProcessError("Unknown routing algorithm '" + routingAlgorithm + "'!");
416 }
417
418 RailwayRouter<MSEdge, SUMOVehicle>* railRouter = nullptr;
419 if (MSNet::getInstance()->hasBidiEdges()) {
420 railRouter = new RailwayRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, myEffortFunc, nullptr, false, true, false, oc.getFloat("railway.max-train-length"));
421 }
422 myRouterProvider = new MSRouterProvider(router, nullptr, nullptr, railRouter);
423#ifndef THREAD_POOL
424#ifdef HAVE_FOX
425 MFXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
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) {
430 static_cast<MSEdgeControl::WorkerThread*>(*t)->setRouterProvider(myRouterProvider->clone());
431 }
432 }
433#ifndef WIN32
434 /*
435 int i = 0;
436 for (MFXWorkerThread* t : threads) {
437 myThreadRNGs[(std::thread::id)t->id()] = new SumoRNG("routing_" + toString(i++));
438 }
439 */
440#endif
441 }
442#endif
443#endif
444}
445
446
447void
448MSRoutingEngine::reroute(SUMOVehicle& vehicle, const SUMOTime currentTime, const std::string& info,
449 const bool onInit, const bool silent, const MSEdgeVector& prohibited) {
450 if (myRouterProvider == nullptr) {
451 initRouter(&vehicle);
452 }
453 auto& router = myRouterProvider->getVehicleRouter(vehicle.getVClass());
454#ifndef THREAD_POOL
455#ifdef HAVE_FOX
456 MFXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
457 if (threadPool.size() > 0) {
458 threadPool.add(new RoutingTask(vehicle, currentTime, info, onInit, silent, prohibited));
459 return;
460 }
461#endif
462#endif
463 if (!prohibited.empty()) {
464 router.prohibit(prohibited);
465 }
466 try {
467 vehicle.reroute(currentTime, info, router, onInit, myWithTaz, silent);
468 } catch (ProcessError&) {
469 if (!silent) {
470 if (!prohibited.empty()) {
471 router.prohibit(MSEdgeVector());
472 }
473 throw;
474 }
475 }
476 if (!prohibited.empty()) {
477 router.prohibit(MSEdgeVector());
478 }
479}
480
481
482void
483MSRoutingEngine::setEdgeTravelTime(const MSEdge* const edge, const double travelTime) {
484 myEdgeSpeeds[edge->getNumericalID()] = edge->getLength() / travelTime;
485}
486
487void
488MSRoutingEngine::addEdgeTravelTime(const MSEdge& edge, const SUMOTime travelTime) {
490 tc.first += travelTime;
491 tc.second += 1;
492}
493
494
496MSRoutingEngine::getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector& prohibited) {
497 if (myRouterProvider == nullptr) {
499 initEdgeWeights(svc);
500 initRouter();
501 }
502#ifndef THREAD_POOL
503#ifdef HAVE_FOX
504 MFXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
505 if (threadPool.size() > 0) {
506 auto& router = static_cast<MSEdgeControl::WorkerThread*>(threadPool.getWorkers()[rngIndex % MSGlobals::gNumThreads])->getRouter(svc);
507 router.prohibit(prohibited);
508 return router;
509 }
510#else
511 UNUSED_PARAMETER(rngIndex);
512#endif
513#endif
514 myRouterProvider->getVehicleRouter(svc).prohibit(prohibited);
516}
517
518
519void
521 myAdaptationInterval = -1; // responsible for triggering initEdgeWeights
522 myPastEdgeSpeeds.clear();
523 myEdgeSpeeds.clear();
524 myEdgeTravelTimes.clear();
525 myPastEdgeBikeSpeeds.clear();
526 myEdgeBikeSpeeds.clear();
527 // @todo recheck. calling release crashes in parallel routing
528 //for (auto& item : myCachedRoutes) {
529 // item.second->release();
530 //}
531 myCachedRoutes.clear();
533#ifdef HAVE_FOX
534 if (MSGlobals::gNumThreads > 1) {
535 // router deletion is done in thread destructor
536 myRouterProvider = nullptr;
537 return;
538 }
539#endif
540 delete myRouterProvider;
541 myRouterProvider = nullptr;
542}
543
544
545#ifdef HAVE_FOX
546void
547MSRoutingEngine::waitForAll() {
548#ifndef THREAD_POOL
549 MFXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
550 if (threadPool.size() > 0) {
551 threadPool.waitAll();
552 }
553#endif
554}
555
556
557// ---------------------------------------------------------------------------
558// MSRoutingEngine::RoutingTask-methods
559// ---------------------------------------------------------------------------
560void
561MSRoutingEngine::RoutingTask::run(MFXWorkerThread* context) {
562 SUMOAbstractRouter<MSEdge, SUMOVehicle>& router = static_cast<MSEdgeControl::WorkerThread*>(context)->getRouter(myVehicle.getVClass());
563 if (!myProhibited.empty()) {
564 router.prohibit(myProhibited);
565 }
566 try {
567 myVehicle.reroute(myTime, myInfo, router, myOnInit, myWithTaz, mySilent);
568 } catch (ProcessError&) {
569 if (!mySilent) {
570 if (!myProhibited.empty()) {
571 router.prohibit(MSEdgeVector());
572 }
573 throw;
574 }
575 }
576 if (!myProhibited.empty()) {
577 router.prohibit(MSEdgeVector());
578 }
579 const MSEdge* source = *myVehicle.getRoute().begin();
580 const MSEdge* dest = myVehicle.getRoute().getLastEdge();
581 if (source->isTazConnector() && dest->isTazConnector()) {
582 const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
583 FXMutexLock lock(myRouteCacheMutex);
585 MSRoutingEngine::myCachedRoutes[key] = &myVehicle.getRoute();
586 myVehicle.getRoute().addReference();
587 }
588 }
589}
590#endif
591
592
593/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
#define DEBUG_COND(obj)
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:265
#define TL(string)
Definition: MsgHandler.h:282
SUMOTime DELTA_T
Definition: SUMOTime.cpp:37
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
#define SUMOTime_MAX
Definition: SUMOTime.h:33
#define SIMTIME
Definition: SUMOTime.h:61
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
@ SUMO_ATTR_ID
double gWeightsRandomFactor
Definition: StdDefs.cpp:30
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
T MIN2(T a, T b)
Definition: StdDefs.h:71
T MAX2(T a, T b)
Definition: StdDefs.h:77
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:76
Computes the shortest path through a contracted network.
Definition: CHRouter.h:59
Computes the shortest path through a contracted network.
Base (microsim) event class.
Definition: Command.h:50
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 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.
Definition: MSEdge.h:77
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:984
int getPriority() const
Returns the priority of the edge.
Definition: MSEdge.h:325
const MSConstEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges with internal vias, restricted by vClass.
Definition: MSEdge.cpp:1185
double getLength() const
return the length of the edge
Definition: MSEdge.h:658
bool isTazConnector() const
Definition: MSEdge.h:288
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:473
int getNumericalID() const
Returns the numerical id of the edge.
Definition: MSEdge.h:303
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static double gWeightsSeparateTurns
Whether turning specific weights are estimated (and how much)
Definition: MSGlobals.h:171
static int gNumThreads
how many threads to use
Definition: MSGlobals.h:145
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:183
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:482
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:321
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:163
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
Definition: MSNet.h:209
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:422
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 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
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.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
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.
Definition: OptionsCont.cpp:59
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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)
Definition: RandHelper.cpp:94
SUMOAbstractRouter< E, V > & getVehicleRouter(SUMOVehicleClass svc) const
RouterProvider * clone()
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.
Definition: SUMOVehicle.h:60
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.
Definition: StaticCommand.h:38
@ key
the parser read a key of a value in an object