Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSRoutingEngine.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2007-2026 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/MSJunction.h>
30#include <microsim/MSEdge.h>
33#include <microsim/MSGlobals.h>
36#include <microsim/MSVehicle.h>
37#include <microsim/MSRoute.h>
39#include <mesosim/MEVehicle.h>
42#include <set>
59
60//#define DEBUG_SEPARATE_TURNS
61#define DEBUG_COND(obj) (obj->isSelected())
62
63// ===========================================================================
64// static member variables
65// ===========================================================================
66std::vector<double> MSRoutingEngine::myEdgeSpeeds;
67std::vector<double> MSRoutingEngine::myEdgeBikeSpeeds;
68std::vector<MSRoutingEngine::TimeAndCount> MSRoutingEngine::myEdgeTravelTimes;
69std::vector<std::vector<double> > MSRoutingEngine::myPastEdgeSpeeds;
70std::vector<std::vector<double> > MSRoutingEngine::myPastEdgeBikeSpeeds;
80std::atomic<bool> MSRoutingEngine::myRouterReady(false);
82std::map<std::pair<const MSEdge*, const MSEdge*>, ConstMSRoutePtr> MSRoutingEngine::myCachedRoutes;
84double MSRoutingEngine::myMinEdgePriority(std::numeric_limits<double>::max());
88
90#ifdef HAVE_FOX
91FXMutex MSRoutingEngine::myRouteCacheMutex;
92#endif
96
97
98// ===========================================================================
99// method definitions
100// ===========================================================================
101void
103 if (myAdaptationInterval == -1) {
105 myLastAdaptation = lastAdaptation;
107 myWithTaz = oc.getBool("device.rerouting.with-taz");
108 myAdaptationInterval = string2time(oc.getString("device.rerouting.adaptation-interval"));
109 myAdaptationWeight = oc.getFloat("device.rerouting.adaptation-weight");
110 const SUMOTime period = string2time(oc.getString("device.rerouting.period"));
111 if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
112 SUMOTime nextAdaptation = -1;
113 if (lastAdaptation >= 0) {
114 nextAdaptation = lastAdaptation + myAdaptationInterval;
115 }
118 } else if (period > 0) {
119 WRITE_WARNING(TL("Rerouting is useless if the edge weights do not get updated!"));
120 }
121 OptionsCont::createDeviceByOption("device.rerouting.output", "weights", "meandata_file.xsd");
122 }
123}
124
125
126void
129 if (myAdaptationWeight == 0 || !oc.isDefault("device.rerouting.adaptation-steps")) {
130 myAdaptationSteps = oc.getInt("device.rerouting.adaptation-steps");
131 }
132 if (myBikeSpeeds && svc == SVC_BICYCLE) {
134 } else {
136 }
137 if (lastAdaption >= 0) {
138 myLastAdaptation = lastAdaption;
139 }
140 if (index >= 0 && myAdaptationSteps > 0) {
141 assert(index < myAdaptationSteps);
143 }
144}
145
146
147void
149 if (oc.getFloat("weights.priority-factor") != 0) {
150 myPriorityFactor = oc.getFloat("weights.priority-factor");
151 if (myPriorityFactor < 0) {
152 throw ProcessError(TL("weights.priority-factor cannot be negative."));
153 }
154 myMinEdgePriority = std::numeric_limits<double>::max();
155 double maxEdgePriority = -std::numeric_limits<double>::max();
156 for (const MSEdge* const edge : MSNet::getInstance()->getEdgeControl().getEdges()) {
157 maxEdgePriority = MAX2(maxEdgePriority, (double)edge->getPriority());
158 myMinEdgePriority = MIN2(myMinEdgePriority, (double)edge->getPriority());
159 }
160 myEdgePriorityRange = maxEdgePriority - myMinEdgePriority;
161 if (myEdgePriorityRange == 0) {
162 WRITE_WARNING(TL("Option weights.priority-factor does not take effect because all edges have the same priority"));
164 }
165 }
166 myDynamicRandomness = oc.getBool("weights.random-factor.dynamic");
168}
169
170
171void
172MSRoutingEngine::_initEdgeWeights(std::vector<double>& edgeSpeeds, std::vector<std::vector<double> >& pastEdgeSpeeds) {
173 if (edgeSpeeds.empty()) {
175 const bool useLoaded = oc.getBool("device.rerouting.init-with-loaded-weights");
176 const double currentSecond = SIMTIME;
177 for (const MSEdge* const edge : MSNet::getInstance()->getEdgeControl().getEdges()) {
178 while (edge->getNumericalID() >= (int)edgeSpeeds.size()) {
179 edgeSpeeds.push_back(0);
180 if (myAdaptationSteps > 0) {
181 pastEdgeSpeeds.push_back(std::vector<double>());
182 }
183 if (MSGlobals::gWeightsSeparateTurns && edgeSpeeds == myEdgeSpeeds) {
184 myEdgeTravelTimes.push_back(TimeAndCount(0, 0));
185 }
186 }
187 if (useLoaded) {
188 edgeSpeeds[edge->getNumericalID()] = edge->getLength() / MSNet::getTravelTime(edge, nullptr, currentSecond);
189 } else {
190 edgeSpeeds[edge->getNumericalID()] = edge->getMeanSpeed();
191 }
192 if (myAdaptationSteps > 0) {
193 pastEdgeSpeeds[edge->getNumericalID()] = std::vector<double>(myAdaptationSteps, edgeSpeeds[edge->getNumericalID()]);
194 }
195 }
197 }
198}
199
200
201double
202MSRoutingEngine::getEffort(const MSEdge* const e, const SUMOVehicle* const v, double) {
203 const int id = e->getNumericalID();
204 if (id < (int)myEdgeSpeeds.size()) {
205 return MAX2(e->getLength() / MAX2(myEdgeSpeeds[id], NUMERICAL_EPS), e->getMinimumTravelTime(v));
206 }
207 return e->getMinimumTravelTime(v);
208}
209
210
211double
212MSRoutingEngine::getEffortBike(const MSEdge* const e, const SUMOVehicle* const v, double) {
213 const int id = e->getNumericalID();
214 if (id < (int)myEdgeBikeSpeeds.size()) {
215 return MAX2(e->getLength() / MAX2(myEdgeBikeSpeeds[id], NUMERICAL_EPS), e->getMinimumTravelTime(v));
216 }
217 return e->getMinimumTravelTime(v);
218}
219
220
221double
222MSRoutingEngine::getEffortExtra(const MSEdge* const e, const SUMOVehicle* const v, double t) {
223 double effort = (!myBikeSpeeds || v == nullptr || v->getVClass() != SVC_BICYCLE
224 ? getEffort(e, v, t)
225 : getEffortBike(e, v, t));
226 applyExtras(e, v, SIMSTEP, effort);
227 return effort;
228}
229
230
231double
233 return edge->getLength() / myEffortFunc(edge, veh, 0);
234}
235
236
240 if (myBikeSpeeds) {
242 }
243 if (MSNet::getInstance()->getVehicleControl().getDepartedVehicleNo() == 0) {
245 }
246 {
247#ifdef HAVE_FOX
248 FXMutexLock lock(myRouteCacheMutex);
249#endif
250 myCachedRoutes.clear();
251 }
253 const double newWeightFactor = (double)(1. - myAdaptationWeight);
254 bool cchEdgeMoved = false;
255 for (const MSEdge* const e : edges) {
256 if (e->isDelayed()) {
257 const int id = e->getNumericalID();
258 double currSpeed = e->getMeanSpeed();
259 if (MSGlobals::gWeightsSeparateTurns > 0 && e->getNumSuccessors() > 1) {
260 currSpeed = patchSpeedForTurns(e, currSpeed);
261 }
262#ifdef DEBUG_SEPARATE_TURNS
263 if (DEBUG_COND(e->getLanes()[0])) {
264 std::cout << SIMTIME << " edge=" << e->getID()
265 << " meanSpeed=" << e->getMeanSpeed()
266 << " currSpeed=" << currSpeed
267 << " oldestSpeed=" << myPastEdgeSpeeds[id][myAdaptationStepsIndex]
268 << " oldAvg=" << myEdgeSpeeds[id]
269 << "\n";
270 }
271#endif
272 const double oldSmoothedSpeed = myEdgeSpeeds[id];
273 if (myAdaptationSteps > 0) {
274 // moving average
277 if (myBikeSpeeds) {
278 const double currBikeSpeed = e->getMeanSpeedBike();
280 myPastEdgeBikeSpeeds[id][myAdaptationStepsIndex] = currBikeSpeed;
281 }
282 } else {
283 // exponential moving average
284 if (currSpeed != myEdgeSpeeds[id]) {
285 myEdgeSpeeds[id] = myEdgeSpeeds[id] * myAdaptationWeight + currSpeed * newWeightFactor;
286 }
287 if (myBikeSpeeds) {
288 const double currBikeSpeed = e->getMeanSpeedBike();
289 if (currBikeSpeed != myEdgeBikeSpeeds[id]) {
290 myEdgeBikeSpeeds[id] = myEdgeBikeSpeeds[id] * myAdaptationWeight + currBikeSpeed * newWeightFactor;
291 }
292 }
293 }
294 // sparse CCH re-customization: remember which edges actually
295 // moved; the update deadband is applied at the customize barrier
296 if (myCCHLive != nullptr && myEdgeSpeeds[id] != oldSmoothedSpeed) {
298 cchEdgeMoved = true;
299 }
300 }
301 }
302 if (myAdaptationSteps > 0) {
304 }
305 myLastAdaptation = currentTime;
306 // The device's CCH customization barrier: re-customize the metrics from
307 // the freshly updated speed tables and publish (double-buffered). Runs
308 // on the main thread after the speed update; no worker query is in
309 // flight at this point. The family skips quiet barriers and runs that
310 // never route (see CCHMetricFamily::atBarrier: measured on Lausanne, the
311 // unconditional per-tick customize was 80% of meso wall time at
312 // adaptation-interval 2, and ran even with rerouting probability 0).
313 if (myCCHLive != nullptr) {
314 myCCHLive->atBarrier(STEPS2TIME(currentTime), cchEdgeMoved);
315 }
316 if (OptionsCont::getOptions().isSet("device.rerouting.output")) {
317 OutputDevice& dev = OptionsCont::getDeviceByOption("device.rerouting.output");
319 dev.writeAttr(SUMO_ATTR_ID, "device.rerouting");
320 dev.writeAttr(SUMO_ATTR_BEGIN, STEPS2TIME(currentTime));
322 for (const MSEdge* e : edges) {
324 dev.writeAttr(SUMO_ATTR_ID, e->getID());
325 dev.writeAttr("traveltime", myEffortFunc(e, nullptr, STEPS2TIME(currentTime)));
326 if (myBikeSpeeds) {
327 // @note edge-priority is not included here
328 dev.writeAttr("traveltimeBike", getEffortBike(e, nullptr, STEPS2TIME(currentTime)));
329 }
330 dev.closeTag();
331 }
332 dev.closeTag();
333 }
335}
336
337
340 if (myCCHGraph == nullptr) {
341 myCCHGraph = new MSCCHGraph(MSEdge::getAllEdges()); // union topology; class masks prime at first fill
342 }
343 return myCCHGraph;
344}
345
346
347void
349 if (myCCHLive != nullptr) {
350 return; // device-side state built once (the graph alone may already
351 // exist for MSNet's free-flow router)
352 }
353 // One LIVE metric per vehicle TYPE known when routing starts (see
354 // utils/router/CCHMetricFamily.h for the keying and buffer semantics).
355 // All types share ONE CCH topology (the union); route files stream, so
356 // types appearing later register through the family's wanted list and
357 // get their metric at the next customization barrier.
358 buildCCHLive();
359 std::vector<std::string> vtypeIDs;
361 for (const std::string& id : vtypeIDs) {
363 // the members are in the list as well, resolving the distribution would draw from the default RNG
364 continue;
365 }
366 const MSVehicleType* vt = MSNet::getInstance()->getVehicleControl().getVType(id, nullptr, true);
367 if (vt != nullptr && !vt->isVehicleSpecific()) {
368 myCCHLive->seedKey(vt);
369 }
370 }
371 // publish initial metrics so the first queries succeed
372 myCCHLive->customize(STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()));
373}
374
375
376void
382 oc.getFloat("device.rerouting.cch-update-threshold.factor"),
383 STEPS2TIME(string2time(oc.getString("device.rerouting.cch-update-threshold.constant"))),
385 oc.getInt("device.rerouting.cch-ensemble"));
386}
387
388
392 if (myCCHLive == nullptr && oc.getString("routing-algorithm") == "CCH") {
393 // restored before the first routing: fill with the effort initRouter will choose
394 myEffortFunc = ((myHaveExtras || oc.getBool("device.rerouting.bike-speeds")) ? &MSRoutingEngine::getEffortExtra : &MSRoutingEngine::getEffort);
395 buildCCHLive();
396 }
397 return myCCHLive;
398}
399
400
403 // The effort-reference vehicle: constructed DIRECTLY (what buildVehicle
404 // does minus initVehicle), so it is never counted in the vehicle
405 // statistics, never given devices and never inserted -- it exists only
406 // so every metric fill evaluates the same reference. The mean speed
407 // factor makes it deterministic (the findRoute precedent) and the fixed
408 // id makes the frozen weights.random-factor realization reproducible
409 // (the random seed is a hash of the id).
411 // slot 0 keeps the historical id (and with it the frozen random-factor
412 // realization); ensemble slots differ only in the id, which seeds their
413 // own realization -- see CCHMetricFamily::RefVehicleFactory
414 pars->id = "cchRef:" + type->getID() + (slot == 0 ? "" : ":" + toString(slot));
415 const MSEdge* refEdge = nullptr;
416 for (const MSEdge* e : MSEdge::getAllEdges()) {
417 if (!e->isInternal() && !e->isTazConnector()) {
418 refEdge = e;
419 break;
420 }
421 }
422 ConstMSRoutePtr route = std::make_shared<MSRoute>(pars->id, ConstMSEdgeVector({refEdge}), false, nullptr, StopParVector());
424 return new MEVehicle(pars, route, const_cast<MSVehicleType*>(type),
425 type->getSpeedFactor().getParameter(0));
426 }
427 return new MSVehicle(pars, route, const_cast<MSVehicleType*>(type),
428 type->getSpeedFactor().getParameter(0));
429}
430
431
432void
434 if (myCCHGraph == nullptr) {
435 return;
436 }
437 // the primed connection masks reflect the OLD successor lists; the next
438 // fill of either family re-primes from the live ones. Safe to do right
439 // here: masks are only read at fill time, and every fill runs on the
440 // main thread (the device barrier, the free-flow repair) -- never on a
441 // query thread.
443 if (myCCHFreeflow != nullptr) {
445 }
446 if (myCCHLive != nullptr) {
448 }
449}
450
451
454 // the published metrics always track the live speeds; the query time
455 // only matters for duarouter's per-weight-period metrics. Lookup is by
456 // vehicle TYPE (the metric's exactness key); a vehicle-specific type
457 // (TraCI-modified singular copy) routes on the exact fallback rather
458 // than on another type's metric.
459 if (veh == nullptr || myCCHLive == nullptr) {
460 return nullptr;
461 }
462 const MSVehicleType* type = &veh->getVehicleType();
463 if (type->isVehicleSpecific()) {
464 return nullptr;
465 }
466 return myCCHLive->published(type, veh->getID());
467}
468
469
472 // MAIN-THREAD ONLY (see header): MSNet's routers serve TraCI, triggers
473 // and the GUI, never the rerouting worker threads, so the family's lazy
474 // creation and stale repair may run synchronously right here.
475 if (veh == nullptr) {
476 return nullptr;
477 }
478 // Everything MSNet::getTravelTime reads ahead of the free-flow layer is
479 // per-vehicle and cannot live in a shared metric -> exact fallback:
480 // individual TraCI edge weights, global TraCI edge weights, a routing
481 // mode other than DEFAULT (the AGGREGATED modes belong to the device
482 // metrics; the transient-permission modes already fall back inside
483 // CCHRouter::compute).
486 return nullptr;
487 }
488 const MSVehicle* const msVeh = dynamic_cast<const MSVehicle*>(veh);
489 if (msVeh != nullptr && !msVeh->getWeightsStorage().empty()) {
490 return nullptr;
491 }
492 const MSVehicleType* type = &veh->getVehicleType();
493 if (type->isVehicleSpecific()) {
494 return nullptr;
495 }
496 if (myCCHFreeflow == nullptr) {
497 // free-flow efforts are static: a STATIC family with a single weight
498 // period, lazily customized per type on first query
502 }
503 return myCCHFreeflow->get(type, type->getVehicleClass(),
505}
506
507
508double
509MSRoutingEngine::patchSpeedForTurns(const MSEdge* edge, double currSpeed) {
510 const double length = edge->getLength();
511 double maxSpeed = 0;
512 for (const auto& pair : edge->getViaSuccessors()) {
513 if (pair.second == nullptr) {
514 continue;
515 }
516 TimeAndCount& tc = myEdgeTravelTimes[pair.second->getNumericalID()];
517 if (tc.second > 0) {
518 const double avgSpeed = length / STEPS2TIME(tc.first / tc.second);
519 maxSpeed = MAX2(avgSpeed, maxSpeed);
520 }
521 }
522 if (maxSpeed > 0) {
523 // perform correction
524 const double correctedSpeed = MSGlobals::gWeightsSeparateTurns * maxSpeed + (1 - MSGlobals::gWeightsSeparateTurns) * currSpeed;
525 for (const auto& pair : edge->getViaSuccessors()) {
526 if (pair.second == nullptr) {
527 continue;
528 }
529 const int iid = pair.second->getNumericalID();
531 if (tc.second > 0) {
532 const double avgSpeed = length / STEPS2TIME(tc.first / tc.second);
533 if (avgSpeed < correctedSpeed) {
534 double internalTT = pair.second->getLength() / pair.second->getSpeedLimit();
535 internalTT += (length / avgSpeed - length / correctedSpeed) * MSGlobals::gWeightsSeparateTurns;
536 const double origInternalSpeed = myEdgeSpeeds[iid];
537 const double newInternalSpeed = pair.second->getLength() / internalTT;
538 const double origCurrSpeed = myPastEdgeSpeeds[iid][myAdaptationStepsIndex];
539
540 myEdgeSpeeds[iid] = newInternalSpeed;
541 // to ensure myEdgeSpeed reverts to the speed limit
542 // when there are no updates, we also have to patch
543 // myPastEdgeSpeeds with a virtual value that is consistent
544 // with the updated speed
545 // note: internal edges were handled before the normal ones
546 const double virtualSpeed = (newInternalSpeed - (origInternalSpeed - origCurrSpeed / myAdaptationSteps)) * myAdaptationSteps;
547 myPastEdgeSpeeds[iid][myAdaptationStepsIndex] = virtualSpeed;
548
549#ifdef DEBUG_SEPARATE_TURNS
550 if (DEBUG_COND(pair.second->getLanes()[0])) {
551 std::cout << SIMTIME << " edge=" << edge->getID() << " to=" << pair.first->getID() << " via=" << pair.second->getID()
552 << " origSpeed=" << currSpeed
553 << " maxSpeed=" << maxSpeed
554 << " correctedSpeed=" << correctedSpeed
555 << " avgSpeed=" << avgSpeed
556 << " internalTT=" << internalTT
557 << " internalSpeed=" << origInternalSpeed
558 << " newInternalSpeed=" << newInternalSpeed
559 << " virtualSpeed=" << virtualSpeed
560 << "\n";
561 }
562#endif
563 }
564 if (myAdaptationStepsIndex == 0) {
565 tc.first = 0;
566 tc.second = 0;
567 }
568 }
569 }
570 return correctedSpeed;
571 }
572 return currSpeed;
573}
574
575
577MSRoutingEngine::getCachedRoute(const std::pair<const MSEdge*, const MSEdge*>& key) {
578#ifdef HAVE_FOX
579 // worker threads insert into the cache concurrently (RoutingTask::run)
580 FXMutexLock lock(myRouteCacheMutex);
581#endif
582 auto routeIt = myCachedRoutes.find(key);
583 if (routeIt != myCachedRoutes.end()) {
584 return routeIt->second;
585 }
586 return nullptr;
587}
588
589
590void
593 const std::string routingAlgorithm = oc.getString("routing-algorithm");
594 const bool hasPermissions = MSNet::getInstance()->hasPermissions();
595 myBikeSpeeds = oc.getBool("device.rerouting.bike-speeds");
597
599 if (routingAlgorithm == "dijkstra") {
600 router = new DijkstraRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, myEffortFunc, nullptr, false, nullptr, true);
601 } else if (routingAlgorithm == "astar") {
603 std::shared_ptr<const AStar::LookupTable> lookup = nullptr;
604 if (oc.isSet("astar.all-distances")) {
605 lookup = std::make_shared<const AStar::FLT>(oc.getString("astar.all-distances"), (int)MSEdge::getAllEdges().size());
606 } else if (oc.isSet("astar.landmark-distances") && vehicle != nullptr) {
607 const double speedFactor = vehicle->getChosenSpeedFactor();
608 // we need an exemplary vehicle with speedFactor 1
609 vehicle->setChosenSpeedFactor(1);
612 string2time(oc.getString("begin")), string2time(oc.getString("end")), SUMOTime_MAX, hasPermissions, 1);
613 lookup = std::make_shared<const AStar::LMLT>(oc.getString("astar.landmark-distances"), MSEdge::getAllEdges(), &chrouter,
614 nullptr, vehicle, "", oc.getInt("device.rerouting.threads"), MSNet::getInstance()->getMapMatcher());
615 vehicle->setChosenSpeedFactor(speedFactor);
616 }
617 router = new AStar(MSEdge::getAllEdges(), true, myEffortFunc, lookup, true);
618 } else if (routingAlgorithm == "CH" && !hasPermissions) {
621 MSEdge::getAllEdges(), true, myEffortFunc, vehicle == nullptr ? SVC_PASSENGER : vehicle->getVClass(), weightPeriod, true, false);
622 } else if (routingAlgorithm == "CHWrapper" || routingAlgorithm == "CH") {
623 // use CHWrapper instead of CH if the net has permissions
627 string2time(oc.getString("begin")), string2time(oc.getString("end")), weightPeriod, hasPermissions, oc.getInt("device.rerouting.threads"));
628 } else if (routingAlgorithm == "CCH") {
629 // CCH metrics are keyed by vehicle TYPE and filled with a reference
630 // vehicle of the type (customizeCCH), mirroring duarouter's
631 // RODUACCHMetrics: type/class-specific routing preferences, the
632 // bicycle speed table, the type's maximum speed and the static
633 // priority multiplier are captured exactly per metric.
634 // weights.random-factor freezes one realization per metric -- the
635 // same approximation CHRouterWrapper makes when building its
636 // hierarchies; exact per-vehicle randomization remains the domain of
637 // dijkstra and astar.
638 initCCH(); // build the immutable topology + publish an initial metric (once)
639 // embedded fallback for non-passenger / prohibited / unreachable queries
644 } else {
645 throw ProcessError(TLF("Unknown routing algorithm '%'!", routingAlgorithm));
646 }
647
648 RailwayRouter<MSEdge, SUMOVehicle>* railRouter = nullptr;
649 if (MSNet::getInstance()->hasBidiEdges()) {
650 railRouter = new RailwayRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, myEffortFunc, nullptr, false, true, false,
651 oc.getFloat("railway.max-train-length"),
652 oc.getFloat("weights.reversal-penalty"));
653 }
654 const int carWalk = SUMOVehicleParserHelper::parseCarWalkTransfer(oc, MSDevice_Taxi::hasFleet() || MSNet::getInstance()->getInsertionControl().hasTaxiFlow());
655 const double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
656 MSTransportableRouter* transRouter = new MSTransportableRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, 0);
657 myRouterProvider = new MSRouterProvider(router, nullptr, transRouter, railRouter);
658#ifndef THREAD_POOL
659#ifdef HAVE_FOX
660 MFXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
661 if (threadPool.size() > 0) {
662 const std::vector<MFXWorkerThread*>& threads = threadPool.getWorkers();
663 if (static_cast<MSEdgeControl::WorkerThread*>(threads.front())->setRouterProvider(myRouterProvider)) {
664 for (std::vector<MFXWorkerThread*>::const_iterator t = threads.begin() + 1; t != threads.end(); ++t) {
665 static_cast<MSEdgeControl::WorkerThread*>(*t)->setRouterProvider(myRouterProvider->clone());
666 }
667 }
668 }
669#endif
670#endif
671}
672
673
674void
675MSRoutingEngine::reroute(SUMOVehicle& vehicle, const SUMOTime currentTime, const std::string& info,
676 const bool onInit, const bool silent, const Prohibitions& prohibited) {
677 if (!myRouterReady.load(std::memory_order_acquire)) {
678 std::lock_guard<std::mutex> lock(myRouterInitLock);
679 if (myRouterProvider == nullptr) {
680 initRouter(&vehicle);
681 }
682 myRouterReady.store(true, std::memory_order_release);
683 }
684 auto& router = myRouterProvider->getVehicleRouter(vehicle.getVClass());
685#ifndef THREAD_POOL
686#ifdef HAVE_FOX
687 MFXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
688 if (threadPool.size() > 0) {
689 threadPool.add(new RoutingTask(vehicle, currentTime, info, onInit, silent, prohibited));
690 return;
691 }
692#endif
693#endif
694 if (!prohibited.empty()) {
695 router.prohibit(prohibited);
696 }
697 try {
698 vehicle.reroute(currentTime, info, router, onInit, myWithTaz, silent);
699 } catch (ProcessError&) {
700 if (!silent) {
701 if (!prohibited.empty()) {
702 router.prohibit(Prohibitions());
703 }
704 throw;
705 }
706 }
707 if (!prohibited.empty()) {
708 router.prohibit(Prohibitions());
709 }
710}
711
712
713void
714MSRoutingEngine::reroute(MSTransportable& t, const SUMOTime currentTime, const std::string& info,
715 const bool onInit, const bool silent, const Prohibitions& prohibited) {
717#ifndef THREAD_POOL
718#ifdef HAVE_FOX
719 MFXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
720 if (threadPool.size() > 0) {
721 // threadPool.add(new RoutingTask(t, currentTime, info, onInit, silent, prohibited));
722 return;
723 }
724#endif
725#endif
726 if (!prohibited.empty()) {
727 router.prohibit(prohibited);
728 }
729 try {
730 t.reroute(currentTime, info, router, onInit, myWithTaz, silent);
731 } catch (ProcessError&) {
732 if (!silent) {
733 if (!prohibited.empty()) {
734 router.prohibit(Prohibitions());
735 }
736 throw;
737 }
738 }
739 if (!prohibited.empty()) {
740 router.prohibit(Prohibitions());
741 }
742}
743
744
745void
746MSRoutingEngine::setEdgeTravelTime(const MSEdge* const edge, const double travelTime) {
747 myEdgeSpeeds[edge->getNumericalID()] = edge->getLength() / travelTime;
748}
749
750void
751MSRoutingEngine::addEdgeTravelTime(const MSEdge& edge, const SUMOTime travelTime) {
753 tc.first += travelTime;
754 tc.second += 1;
755}
756
757
759MSRoutingEngine::getRouterTT(const int rngIndex, SUMOVehicleClass svc, const Prohibitions& prohibited) {
760 if (!myRouterReady.load(std::memory_order_acquire)) {
761 // rerouters may query from several simulation threads at once
762 std::lock_guard<std::mutex> lock(myRouterInitLock);
763 if (myRouterProvider == nullptr) {
765 initEdgeWeights(svc);
766 initRouter();
767 }
768 myRouterReady.store(true, std::memory_order_release);
769 }
770#ifndef THREAD_POOL
771#ifdef HAVE_FOX
772 MFXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
773 if (threadPool.size() > 0) {
774 auto& router = static_cast<MSEdgeControl::WorkerThread*>(threadPool.getWorkers()[rngIndex % MSGlobals::gNumThreads])->getRouter(svc);
775 router.prohibit(prohibited);
776 return router;
777 }
778#else
779 UNUSED_PARAMETER(rngIndex);
780#endif
781#endif
782 myRouterProvider->getVehicleRouter(svc).prohibit(prohibited);
784}
785
786
788MSRoutingEngine::getIntermodalRouterTT(const int rngIndex, const Prohibitions& prohibited) {
789 if (!myRouterReady.load(std::memory_order_acquire)) {
790 std::lock_guard<std::mutex> lock(myRouterInitLock);
791 if (myRouterProvider == nullptr) {
794 initRouter();
795 }
796 myRouterReady.store(true, std::memory_order_release);
797 }
798#ifndef THREAD_POOL
799#ifdef HAVE_FOX
800 MFXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
801 if (threadPool.size() > 0) {
802 auto& router = static_cast<MSEdgeControl::WorkerThread*>(threadPool.getWorkers()[rngIndex % MSGlobals::gNumThreads])->getIntermodalRouter();
803 router.prohibit(prohibited);
804 return router;
805 }
806#else
807 UNUSED_PARAMETER(rngIndex);
808#endif
809#endif
810 myRouterProvider->getIntermodalRouter().prohibit(prohibited);
812}
813
814
815void
817 // free the CCH state so a subsequent load (libsumo / GUI reload) rebuilds
818 // it against the new network; the router clones referencing it were
819 // deleted together with the worker threads / router provider.
820 // Deleting the metric families' owned ref vehicles dereferences their
821 // MSVehicleType*, so this must run BEFORE MSNet deletes its
822 // MSVehicleControl (see the call in ~MSNet); the nullptr checks below
823 // make a second call from cleanup() a safe no-op.
824 delete myCCHLive;
825 myCCHLive = nullptr;
826 delete myCCHFreeflow;
827 myCCHFreeflow = nullptr;
828 delete myCCHGraph;
829 myCCHGraph = nullptr;
830}
831
832
833void
835 myAdaptationInterval = -1; // responsible for triggering initEdgeWeights
836 myPastEdgeSpeeds.clear();
837 myEdgeSpeeds.clear();
838 myEdgeTravelTimes.clear();
839 myPastEdgeBikeSpeeds.clear();
840 myEdgeBikeSpeeds.clear();
841 // @todo recheck. calling release crashes in parallel routing
842 //for (auto& item : myCachedRoutes) {
843 // item.second->release();
844 //}
845 {
846#ifdef HAVE_FOX
847 FXMutexLock lock(myRouteCacheMutex);
848#endif
849 myCachedRoutes.clear();
850 }
852 cleanupCCH();
853#ifdef HAVE_FOX
854 if (MSGlobals::gNumThreads > 1) {
855 // router deletion is done in thread destructor
856 myRouterProvider = nullptr;
857 myRouterReady.store(false, std::memory_order_release);
858 return;
859 }
860#endif
861 delete myRouterProvider;
862 myRouterProvider = nullptr;
863 myRouterReady.store(false, std::memory_order_release);
864}
865
866
867void
869 if (myEdgeSpeeds.size() == 0) {
870 return;
871 }
872 // with a deadband the CCH metrics are not a function of the speeds
873 const bool cch = myCCHLive != nullptr && myCCHLive->hasDeadband();
878 for (const MSEdge* const e : edges) {
879 if (e->isDelayed()) {
880 const int id = e->getNumericalID();
882 out.writeAttr(SUMO_ATTR_ID, e->getID());
884 if (myAdaptationSteps > 0) {
886 }
887 if (myBikeSpeeds) {
889 if (myAdaptationSteps > 0) {
891 }
892 }
893 if (cch) {
894 const double applied = myCCHLive->getAppliedEffort(e);
895 if (!std::isnan(applied)) {
896 out.writeAttr(SUMO_ATTR_CCH_EFFORT, applied);
897 }
898 if (myCCHLive->isPending(e)) {
900 }
901 }
902 out.closeTag();
903 }
904 }
905 if (cch) {
906 std::vector<const MSVehicleType*> types = myCCHLive->getKeys();
907 std::sort(types.begin(), types.end(), [](const MSVehicleType * a, const MSVehicleType * b) {
908 return a->getID() < b->getID();
909 });
910 for (const MSVehicleType* const type : types) {
911 for (int slot = 0; slot < myCCHLive->getEnsembleSize(); slot++) {
912 std::vector<int> arcs;
913 std::vector<int> weights;
914 myCCHLive->getLaggingArcs(type, slot, SIMTIME, arcs, weights);
916 out.writeAttr(SUMO_ATTR_TYPE, type->getID());
917 out.writeAttr(SUMO_ATTR_INDEX, slot);
918 if (!arcs.empty()) {
919 out.writeAttr(SUMO_ATTR_ARCS, arcs);
920 out.writeAttr(SUMO_ATTR_WEIGHTS, weights);
921 }
922 out.closeTag();
923 }
924 }
925 }
926 out.closeTag();
927}
928
929
930void
932 const MSEdge* const e = MSEdge::dictionary(attrs.getString(SUMO_ATTR_ID));
933 e->markDelayed();
934 const int id = e->getNumericalID();
935 bool checkedSteps = false;
936 bool checkedBikeSpeeds = false;
937 bool ok = true;
938 if ((int)myEdgeSpeeds.size() > id) {
939 myEdgeSpeeds[id] = attrs.get<double>(SUMO_ATTR_SPEED, nullptr, ok);
940 if (myBikeSpeeds) {
942 myEdgeBikeSpeeds[id] = attrs.get<double>(SUMO_ATTR_BIKESPEED, nullptr, ok);
943 } else if (!checkedBikeSpeeds) {
944 checkedBikeSpeeds = true;
945 WRITE_WARNING("Bike speeds missing in loaded state");
946 }
947 }
948 if (myAdaptationSteps > 0) {
949 const std::vector<double> speeds = attrs.getOpt<std::vector<double> >(SUMO_ATTR_PASTSPEED, nullptr, ok);
950 if ((int)speeds.size() == myAdaptationSteps) {
951 myPastEdgeSpeeds[id] = speeds;
953 myPastEdgeBikeSpeeds[id] = attrs.getOpt<std::vector<double> >(SUMO_ATTR_PASTBIKESPEED, nullptr, ok);
954 }
955 } else if (!checkedSteps) {
956 checkedSteps = true;
957 WRITE_WARNING("Number of adaptation speeds in loaded state doesn't match option --device.rerouting.adaptation-steps");
958 }
959 }
960 }
962 myCCHLive->loadEdge(e, attrs.getOpt<double>(SUMO_ATTR_CCH_EFFORT, nullptr, ok, std::numeric_limits<double>::quiet_NaN()),
963 attrs.getOpt<bool>(SUMO_ATTR_CCH_PENDING, nullptr, ok, false));
964 }
965}
966
967
968void
970 bool ok = true;
971 const MSVehicleType* type = MSNet::getInstance()->getVehicleControl().getVType(attrs.getString(SUMO_ATTR_TYPE), nullptr, true);
972 if (type != nullptr && getLoadedCCH() != nullptr) {
974 attrs.getOpt<std::vector<int> >(SUMO_ATTR_ARCS, nullptr, ok, std::vector<int>()),
975 attrs.getOpt<std::vector<int> >(SUMO_ATTR_WEIGHTS, nullptr, ok, std::vector<int>()));
976 }
977}
978
979
980#ifdef HAVE_FOX
981void
982MSRoutingEngine::waitForAll() {
983#ifndef THREAD_POOL
984 MFXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
985 if (threadPool.size() > 0) {
986 threadPool.waitAll();
987 }
988#endif
989}
990
991
992// ---------------------------------------------------------------------------
993// MSRoutingEngine::RoutingTask-methods
994// ---------------------------------------------------------------------------
995void
996MSRoutingEngine::RoutingTask::run(MFXWorkerThread* context) {
997 SUMOAbstractRouter<MSEdge, SUMOVehicle>& router = static_cast<MSEdgeControl::WorkerThread*>(context)->getRouter(myVehicle.getVClass());
998 if (!myProhibited.empty()) {
999 router.prohibit(myProhibited);
1000 }
1001 try {
1002 myVehicle.reroute(myTime, myInfo, router, myOnInit, myWithTaz, mySilent);
1003 } catch (ProcessError&) {
1004 if (!mySilent) {
1005 if (!myProhibited.empty()) {
1006 router.prohibit(Prohibitions());
1007 }
1008 throw;
1009 }
1010 }
1011 if (!myProhibited.empty()) {
1012 router.prohibit(Prohibitions());
1013 }
1014 const MSEdge* source = *myVehicle.getRoute().begin();
1015 const MSEdge* dest = myVehicle.getRoute().getLastEdge();
1016 if (source->isTazConnector() && dest->isTazConnector()) {
1017 const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
1018 FXMutexLock lock(myRouteCacheMutex);
1020 MSRoutingEngine::myCachedRoutes[key] = myVehicle.getRoutePtr();
1021 }
1022 }
1023}
1024
1025
1026#endif
1027
1028
1029/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:75
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:74
CCHMetricFamily< MSEdge, SUMOVehicle, MSVehicleType > MSCCHMetricFamily
the per-vehicle-type CCH metric store (utils/router/CCHMetricFamily.h)
RouterProvider< MSEdge, MSLane, MSJunction, SUMOVehicle > MSRouterProvider
IntermodalRouter< MSEdge, MSLane, MSJunction, SUMOVehicle > MSTransportableRouter
CCHGraph< MSEdge, SUMOVehicle > MSCCHGraph
the MSEdge instantiation of the CCH graph mapping (utils/router/CCHGraph.h)
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define TL(string)
Definition MsgHandler.h:316
#define TLF(string,...)
Definition MsgHandler.h:318
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:47
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SIMSTEP
Definition SUMOTime.h:69
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SIMTIME
Definition SUMOTime.h:70
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
std::vector< SUMOVehicleParameter::Stop > StopParVector
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_CCH_METRIC
the arcs of a CCH metric that lag behind the edge speeds
@ SUMO_TAG_ROUTINGENGINE
the internal state for MSRoutingEngine
@ SUMO_TAG_EDGE
begin/end of the description of an edge
@ SUMO_ATTR_LAST
@ SUMO_ATTR_CCH_PENDING
@ SUMO_ATTR_PASTSPEED
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_WEIGHTS
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_PASTBIKESPEED
@ SUMO_ATTR_CCH_EFFORT
@ SUMO_ATTR_INDEX
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
@ SUMO_ATTR_ARCS
@ SUMO_ATTR_BIKESPEED
bool gRoutingPreferences
Definition StdDefs.cpp:37
double gWeightsRandomFactor
Definition StdDefs.cpp:35
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
Computes the shortest path through a network using the A* algorithm.
Definition AStarRouter.h:76
Metric-independent RoutingKit CCH topology over the PURE road graph.
Definition CCHGraph.h:97
void invalidateClassMasks() const
Drop every primed connection mask so the next fill re-primes from the CURRENT successor lists.
Definition CCHGraph.h:365
per-vehicle-type CCH metric store over a shared CCHGraph
MetricPtr get(const K *key, SUMOVehicleClass vClass, SUMOTime time, const V *veh)
the metric for (type key, period of time), built on the first query of the pair; nullptr before init....
void seedKey(const K *key)
allocate the metric state (all ensemble slots) for one type; call only while no query is in flight (s...
bool hasDeadband() const
whether the deadband can keep the metrics behind the efforts (then its state and the lagging arcs bel...
void loadMetric(const K *key, int slot, double now, const std::vector< int > &arcs, const std::vector< int > &weights)
publish the metric of a type and ensemble slot as a fresh fill at now with the given arcs overwritten...
void atBarrier(double now, bool effortsMoved)
the owner's customization barrier: bump the speed epoch when an effort moved and re-customize when it...
void customize(double now)
refill + customize + publish every type's metric from the live efforts and permissions....
void getLaggingArcs(const K *key, int slot, double now, std::vector< int > &arcs, std::vector< int > &weights) const
the arcs of the published metric of a type and ensemble slot whose weight differs from a fresh fill a...
int getEnsembleSize() const
the number of metrics per type
void invalidateEdge(const E *e)
a runtime permission change (closure / re-opening) hit this edge: queue it bypassing the deadband and...
double getAppliedEffort(const E *e) const
the gate effort the edge was last applied with (NaN = never)
std::vector< const K * > getKeys() const
the type keys with metric state
bool isPending(const E *e) const
whether the edge waits for the deadband
void loadEdge(const E *e, double appliedEffort, bool pending)
restore the deadband state of an edge (state loading)
MetricPtr published(const K *key, const std::string &vehID)
the published metric for a type key and querying vehicle id (the id picks the ensemble slot – see the...
void flagPermissionsStale()
flagStale() under the simulation's name for the permission case
void markDirty(const E *e)
queue an edge whose gate effort changed (the deadband applies later, at the customize barrier)
Contraction-hierarchy router over the edge graph mapped by GRAPH.
Definition CCHRouter.h:83
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.
double getParameter(const int index) const
Returns the nth parameter of this distribution.
void prohibit(const _Prohibitions &toProhibit)
A vehicle from the mesoscopic point of view.
Definition MEVehicle.h:42
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 MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle's internal edge travel times/efforts container.
static bool hasFleet()
returns whether taxis have been loaded
const MSEdgeVector & getEdges() const
Returns loaded edges.
A road/street connecting two junctions.
Definition MSEdge.h:78
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition MSEdge.cpp:1157
const MSConstEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING, bool ignoreTransientPermissions=false) const
Returns the following edges with internal vias, restricted by vClass.
Definition MSEdge.cpp:1372
double getLength() const
return the length of the edge
Definition MSEdge.h:695
bool isTazConnector() const
Definition MSEdge.h:293
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition MSEdge.h:486
int getNumericalID() const
Returns the numerical id of the edge.
Definition MSEdge.h:308
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....
Definition MSEdge.cpp:1117
void markDelayed() const
Definition MSEdge.h:751
bool empty() const
Returns whether neither travel times nor efforts are stored.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static bool gUseMesoSim
Definition MSGlobals.h:106
static double gWeightsSeparateTurns
Whether turning specific weights are estimated (and how much)
Definition MSGlobals.h:180
static int gNumThreads
how many threads to use
Definition MSGlobals.h:152
MSMapMatcher * getMapMatcher() const
Definition MSNet.cpp:1853
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition MSNet.h:506
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:335
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
Definition MSNet.cpp:169
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net's internal edge travel times/efforts container.
Definition MSNet.cpp:1340
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
Definition MSNet.h:214
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:403
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition MSNet.h:446
static void adaptIntermodalRouter(MSTransportableRouter &router)
Definition MSNet.cpp:1772
static void saveState(OutputDevice &out)
Saves the state (i.e. recorded speeds)
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
static void initEdgeWeights(SUMOVehicleClass svc, SUMOTime lastAdaption=-1, int index=-1)
initialize the edge weights if not done before
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 SUMOVehicle * buildCCHRefVehicle(const MSVehicleType *type, int slot)
construct the unregistered effort-reference vehicle for a type: never counted, inserted or given devi...
static MSCCHGraph * myCCHGraph
the immutable shared CCH topology (built once), or nullptr if inactive
static MSCCHGraph * ensureCCHGraph()
the shared CCH topology, built on first demand (used by MSNet::getRouterTT to construct its CCH route...
static void setEdgeTravelTime(const MSEdge *const edge, const double travelTime)
adapt the known travel time for an edge
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 void cleanupCCH()
tears down the CCH state (myCCHLive/myCCHFreeflow/myCCHGraph) only – the ref vehicles owned by the CC...
static std::map< std::pair< const MSEdge *, const MSEdge * >, ConstMSRoutePtr > myCachedRoutes
The container of pre-calculated routes.
static MSCCHMetricFamily * getLoadedCCH()
the live family restored from a state, built on first use
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 MSCCHMetricFamily * myCCHLive
the rerouting device's LIVE metric family over the adaptive speed tables (see utils/router/CCHMetricF...
static void _initEdgeWeights(std::vector< double > &edgeSpeeds, std::vector< std::vector< double > > &pastEdgeSpeeds)
initialized edge speed storage into the given containers
static void initCCH()
build the shared CCH + the live family with one metric per loaded type, publish initial metrics
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 const RoutingKit::CustomizableContractionHierarchyMetric * getPublishedCCHMetric(SUMOVehicleClass vClass, SUMOTime time, const SUMOVehicle *veh)
the currently published (customized) CCH metric FOR A GIVEN vehicle class, or nullptr if that class h...
static bool myHaveExtras
whether extra routing cost modifications are configured
SUMOAbstractRouter< MSEdge, SUMOVehicle >::Prohibitions Prohibitions
static void addEdgeTravelTime(const MSEdge &edge, const SUMOTime travelTime)
record actual travel time for an edge
static void applyExtras(const MSEdge *const e, const SUMOVehicle *const v, SUMOTime step, double &effort)
apply cost modifications from randomness, priorityFactor and preferences
static bool myDynamicRandomness
whether randomness varies over time
static std::mutex myRouterInitLock
serialises building the routers when the first queries come from several threads
static std::atomic< bool > myRouterReady
whether the routers of all threads are built
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
static void buildCCHLive()
build the live family without metrics
static void cleanup()
deletes the router instance
static MSCCHMetricFamily * myCCHFreeflow
the STATIC free-flow metric family behind MSNet's routers (TraCI / triggers / GUI,...
static void initRouter(SUMOVehicle *vehicle=nullptr)
static SUMOAbstractRouter< MSEdge, SUMOVehicle >::Operation myEffortFunc
static void invalidateCCHEdge(const MSEdge *e)
a runtime permission change (closure / re-opening) hit this edge: invalidate the graph's primed conne...
static void loadCCHMetric(const SUMOSAXAttributes &attrs)
Loads the arcs of a CCH metric that lag behind the speeds.
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 void initWeightUpdate(SUMOTime lastAdaption=- 1)
intialize period edge weight update
static void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const std::string &info, const bool onInit=false, const bool silent=false, const Prohibitions &prohibited={})
initiate the rerouting, create router / thread pool on first use
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 void loadState(const SUMOSAXAttributes &attrs)
Loads the state.
static const RoutingKit::CustomizableContractionHierarchyMetric * getFreeflowCCHMetric(SUMOVehicleClass vClass, SUMOTime time, const SUMOVehicle *veh)
the free-flow CCH metric for MSNet's routers (TraCI / triggers / GUI), keyed by vehicle type and fill...
static double patchSpeedForTurns(const MSEdge *edge, double currSpeed)
static MSVehicleRouter & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const Prohibitions &prohibited={})
return the vehicle router instance
static double getEffortExtra(const MSEdge *const e, const SUMOVehicle *const v, double t)
static MSTransportableRouter & getIntermodalRouterTT(const int rngIndex, const Prohibitions &prohibited={})
return the person router instance
static std::vector< double > myEdgeBikeSpeeds
static void initWeightConstants(const OptionsCont &oc)
initialize constants for using myPriorityFactor
int getRNGIndex() const override
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)
bool hasVTypeDistribution(const std::string &id) const
Asks for a vehicle type distribution.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, SumoRNG *rng=nullptr, bool readOnly=false)
Returns the named vehicle type or a sample from the named distribution.
void insertVTypeIDs(std::vector< std::string > &into) const
Inserts ids of all known vehicle types and vehicle type distributions to the given vector.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
The car-following model and parameter.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
const std::string & getID() const
Returns the name of the vehicle type.
const Distribution_Parameterized & getSpeedFactor() const
Returns this type's speed factor.
bool isVehicleSpecific() const
Returns whether this type belongs to a single vehicle only (was modified)
const std::string & getID() const
Returns the id.
Definition Named.h:73
A storage for options typed value containers)
Definition OptionsCont.h:92
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)
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
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.
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="", const int maximumDepth=2)
Creates the device using the output definition stored in the named option.
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.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
SUMOAbstractRouter< E, V > & getVehicleRouter(SUMOVehicleClass svc) const
RouterProvider * clone()
IntermodalRouter< E, L, N, V > & getIntermodalRouter() const
virtual void prohibit(const Prohibitions &toProhibit)
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
int getInt(int id) const
Returns the int-value of the named (by its enum-value) attribute.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getChosenSpeedFactor() const =0
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
virtual int getRoutingMode() const =0
return routing mode (configures router choice but also handling of transient permission changes)
Representation of a vehicle.
Definition SUMOVehicle.h:63
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
Structure representing possible vehicle parameter.
std::string id
The vehicle's id.
static int parseCarWalkTransfer(const OptionsCont &oc, const bool hasTaxi)
A wrapper for a Command function.
const CustomizableContractionHierarchy * cch
#define UNUSED_PARAMETER(x)
#define DEBUG_COND
@ key
the parser read a key of a value in an object
TRACI_CONST int ROUTING_MODE_DEFAULT