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>
30 #include <microsim/MSEdgeControl.h>
32 #include <microsim/MSGlobals.h>
41 #include <utils/router/CHRouter.h>
43 
44 //#define DEBUG_SEPARATE_TURNS
45 #define DEBUG_COND(obj) (obj->isSelected())
46 
47 // ===========================================================================
48 // static member variables
49 // ===========================================================================
50 std::vector<double> MSRoutingEngine::myEdgeSpeeds;
51 std::vector<double> MSRoutingEngine::myEdgeBikeSpeeds;
52 std::vector<MSRoutingEngine::TimeAndCount> MSRoutingEngine::myEdgeTravelTimes;
53 std::vector<std::vector<double> > MSRoutingEngine::myPastEdgeSpeeds;
54 std::vector<std::vector<double> > MSRoutingEngine::myPastEdgeBikeSpeeds;
64 std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> MSRoutingEngine::myCachedRoutes;
66 double MSRoutingEngine::myMinEdgePriority(std::numeric_limits<double>::max());
68 
70 #ifdef HAVE_FOX
71 FXMutex MSRoutingEngine::myRouteCacheMutex;
72 #endif
73 
74 
75 // ===========================================================================
76 // method definitions
77 // ===========================================================================
78 void
80  if (myAdaptationInterval == -1) {
82  myEdgeSpeeds.clear();
83  myEdgeTravelTimes.clear();
84  myAdaptationSteps = -1;
85  myLastAdaptation = -1;
87  myWithTaz = oc.getBool("device.rerouting.with-taz");
88  myAdaptationInterval = string2time(oc.getString("device.rerouting.adaptation-interval"));
89  myAdaptationWeight = oc.getFloat("device.rerouting.adaptation-weight");
90  const SUMOTime period = string2time(oc.getString("device.rerouting.period"));
91  if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
94  } else if (period > 0) {
95  WRITE_WARNING("Rerouting is useless if the edge weights do not get updated!");
96  }
97  OutputDevice::createDeviceByOption("device.rerouting.output", "weights", "meandata_file.xsd");
98  }
99 }
100 
101 
102 void
104  if (myBikeSpeeds && svc == SVC_BICYCLE) {
106  } else {
108  }
109 }
110 
111 
112 void
113 MSRoutingEngine::_initEdgeWeights(std::vector<double>& edgeSpeeds, std::vector<std::vector<double> >& pastEdgeSpeeds) {
114  if (edgeSpeeds.empty()) {
115  const OptionsCont& oc = OptionsCont::getOptions();
116  if (myAdaptationWeight == 0 || !oc.isDefault("device.rerouting.adaptation-steps")) {
117  myAdaptationSteps = oc.getInt("device.rerouting.adaptation-steps");
118  }
119  const bool useLoaded = oc.getBool("device.rerouting.init-with-loaded-weights");
120  const double currentSecond = SIMTIME;
121  double maxEdgePriority = -std::numeric_limits<double>::max();
122  for (const MSEdge* const edge : MSNet::getInstance()->getEdgeControl().getEdges()) {
123  while (edge->getNumericalID() >= (int)edgeSpeeds.size()) {
124  edgeSpeeds.push_back(0);
125  if (myAdaptationSteps > 0) {
126  pastEdgeSpeeds.push_back(std::vector<double>());
127  }
128  if (MSGlobals::gWeightsSeparateTurns && edgeSpeeds == myEdgeSpeeds) {
129  myEdgeTravelTimes.push_back(TimeAndCount(0, 0));
130  }
131  }
132  if (useLoaded) {
133  edgeSpeeds[edge->getNumericalID()] = edge->getLength() / MSNet::getTravelTime(edge, nullptr, currentSecond);
134  } else {
135  edgeSpeeds[edge->getNumericalID()] = edge->getMeanSpeed();
136  }
137  if (myAdaptationSteps > 0) {
138  pastEdgeSpeeds[edge->getNumericalID()] = std::vector<double>(myAdaptationSteps, edgeSpeeds[edge->getNumericalID()]);
139  }
140  maxEdgePriority = MAX2(maxEdgePriority, (double)edge->getPriority());
141  myMinEdgePriority = MIN2(myMinEdgePriority, (double)edge->getPriority());
142  }
143  myEdgePriorityRange = maxEdgePriority - myMinEdgePriority;
145  myPriorityFactor = oc.getFloat("weights.priority-factor");
146  if (myPriorityFactor < 0) {
147  throw ProcessError("weights.priority-factor cannot be negative.");
148  }
149  if (myPriorityFactor > 0) {
150  if (myEdgePriorityRange == 0) {
151  WRITE_WARNING("Option weights.priority-factor does not take effect because all edges have the same priority");
152  myPriorityFactor = 0;
153  }
154  }
155  }
156 }
157 
158 
159 double
160 MSRoutingEngine::getEffort(const MSEdge* const e, const SUMOVehicle* const v, double) {
161  const int id = e->getNumericalID();
162  if (id < (int)myEdgeSpeeds.size()) {
163  return MAX2(e->getLength() / MAX2(myEdgeSpeeds[id], NUMERICAL_EPS), e->getMinimumTravelTime(v));
164  }
165  return e->getMinimumTravelTime(v);
166 }
167 
168 
169 double
170 MSRoutingEngine::getEffortBike(const MSEdge* const e, const SUMOVehicle* const v, double) {
171  const int id = e->getNumericalID();
172  if (id < (int)myEdgeBikeSpeeds.size()) {
173  return MAX2(e->getLength() / MAX2(myEdgeBikeSpeeds[id], NUMERICAL_EPS), e->getMinimumTravelTime(v));
174  }
175  return e->getMinimumTravelTime(v);
176 }
177 
178 
179 
180 double
181 MSRoutingEngine::getEffortExtra(const MSEdge* const e, const SUMOVehicle* const v, double t) {
182  double effort = (!myBikeSpeeds || v == nullptr || v->getVClass() != SVC_BICYCLE
183  ? getEffort(e, v, t)
184  : getEffortBike(e, v, t));
185  if (gWeightsRandomFactor != 1.) {
186  effort *= RandHelper::rand(1., gWeightsRandomFactor);
187  }
188  if (myPriorityFactor != 0) {
189  // lower priority should result in higher effort (and the edge with
190  // minimum priority receives a factor of 1 + myPriorityFactor
191  const double relativeInversePrio = 1 - ((e->getPriority() - myMinEdgePriority) / myEdgePriorityRange);
192  effort *= 1 + relativeInversePrio * myPriorityFactor;
193  }
194  return effort;
195 }
196 
197 
198 double
200  return edge->getLength() / myEffortFunc(edge, veh, 0);
201 }
202 
203 
204 SUMOTime
207  if (myBikeSpeeds) {
209  }
210  if (MSNet::getInstance()->getVehicleControl().getDepartedVehicleNo() == 0) {
211  return myAdaptationInterval;
212  }
213  std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*>::iterator it = myCachedRoutes.begin();
214  for (; it != myCachedRoutes.end(); ++it) {
215  it->second->release();
216  }
217  myCachedRoutes.clear();
219  if (myAdaptationSteps > 0) {
220  // moving average
221  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
222  if ((*i)->isDelayed()) {
223  const int id = (*i)->getNumericalID();
224  double currSpeed = (*i)->getMeanSpeed();
225  if (MSGlobals::gWeightsSeparateTurns > 0 && (*i)->getNumSuccessors() > 1) {
226  currSpeed = patchSpeedForTurns(*i, currSpeed);
227  }
228 #ifdef DEBUG_SEPARATE_TURNS
229  if (DEBUG_COND((*i)->getLanes()[0])) {
230  std::cout << SIMTIME << " edge=" << (*i)->getID()
231  << " meanSpeed=" << (*i)->getMeanSpeed()
232  << " currSpeed=" << currSpeed
233  << " oldestSpeed=" << myPastEdgeSpeeds[id][myAdaptationStepsIndex]
234  << " oldAvg=" << myEdgeSpeeds[id]
235  << "\n";
236  }
237 #endif
239  myPastEdgeSpeeds[id][myAdaptationStepsIndex] = currSpeed;
240  }
241  }
242  if (myBikeSpeeds) {
243  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
244  if ((*i)->isDelayed()) {
245  const int id = (*i)->getNumericalID();
246  const double currSpeed = (*i)->getMeanSpeedBike();
249  }
250  }
251  }
253  } else {
254  // exponential moving average
255  const double newWeightFactor = (double)(1. - myAdaptationWeight);
256  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
257  if ((*i)->isDelayed()) {
258  const int id = (*i)->getNumericalID();
259  const double currSpeed = (*i)->getMeanSpeed();
260  if (currSpeed != myEdgeSpeeds[id]) {
261  myEdgeSpeeds[id] = myEdgeSpeeds[id] * myAdaptationWeight + currSpeed * newWeightFactor;
262  }
263  }
264  }
265  if (myBikeSpeeds) {
266  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
267  if ((*i)->isDelayed()) {
268  const int id = (*i)->getNumericalID();
269  const double currSpeed = (*i)->getMeanSpeedBike();
270  if (currSpeed != myEdgeBikeSpeeds[id]) {
271  myEdgeBikeSpeeds[id] = myEdgeBikeSpeeds[id] * myAdaptationWeight + currSpeed * newWeightFactor;
272  }
273  }
274  }
275  }
276  }
277  myLastAdaptation = currentTime + DELTA_T; // because we run at the end of the time step
278  if (OptionsCont::getOptions().isSet("device.rerouting.output")) {
279  OutputDevice& dev = OutputDevice::getDeviceByOption("device.rerouting.output");
281  dev.writeAttr(SUMO_ATTR_ID, "device.rerouting");
282  dev.writeAttr(SUMO_ATTR_BEGIN, STEPS2TIME(currentTime));
284  for (const MSEdge* e : edges) {
285  dev.openTag(SUMO_TAG_EDGE);
286  dev.writeAttr(SUMO_ATTR_ID, e->getID());
287  dev.writeAttr("traveltime", myEffortFunc(e, nullptr, STEPS2TIME(currentTime)));
288  if (myBikeSpeeds) {
289  // @note edge-priority is not included here
290  dev.writeAttr("traveltimeBike", getEffortBike(e, nullptr, STEPS2TIME(currentTime)));
291  }
292  dev.closeTag();
293  }
294  dev.closeTag();
295  }
296  return myAdaptationInterval;
297 }
298 
299 
300 double
301 MSRoutingEngine::patchSpeedForTurns(const MSEdge* edge, double currSpeed) {
302  const double length = edge->getLength();
303  double maxSpeed = 0;
304  for (const auto& pair : edge->getViaSuccessors()) {
305  TimeAndCount& tc = myEdgeTravelTimes[pair.second->getNumericalID()];
306  if (tc.second > 0) {
307  const double avgSpeed = length / STEPS2TIME(tc.first / tc.second);
308  maxSpeed = MAX2(avgSpeed, maxSpeed);
309  }
310  }
311  if (maxSpeed > 0) {
312  // perform correction
313  const double correctedSpeed = MSGlobals::gWeightsSeparateTurns * maxSpeed + (1 - MSGlobals::gWeightsSeparateTurns) * currSpeed;
314  for (const auto& pair : edge->getViaSuccessors()) {
315  const int iid = pair.second->getNumericalID();
316  TimeAndCount& tc = myEdgeTravelTimes[iid];
317  if (tc.second > 0) {
318  const double avgSpeed = length / STEPS2TIME(tc.first / tc.second);
319  if (avgSpeed < correctedSpeed) {
320  double internalTT = pair.second->getLength() / pair.second->getSpeedLimit();
321  internalTT += (length / avgSpeed - length / correctedSpeed) * MSGlobals::gWeightsSeparateTurns;
322  const double origInternalSpeed = myEdgeSpeeds[iid];
323  const double newInternalSpeed = pair.second->getLength() / internalTT;
324  const double origCurrSpeed = myPastEdgeSpeeds[iid][myAdaptationStepsIndex];
325 
326  myEdgeSpeeds[iid] = newInternalSpeed;
327  // to ensure myEdgeSpeed reverts to the speed limit
328  // when there are no updates, we also have to patch
329  // myPastEdgeSpeeds with a virtual value that is consistent
330  // with the updated speed
331  // note: internal edges were handled before the normal ones
332  const double virtualSpeed = (newInternalSpeed - (origInternalSpeed - origCurrSpeed / myAdaptationSteps)) * myAdaptationSteps;
333  myPastEdgeSpeeds[iid][myAdaptationStepsIndex] = virtualSpeed;
334 
335 #ifdef DEBUG_SEPARATE_TURNS
336  if (DEBUG_COND(pair.second->getLanes()[0])) {
337  std::cout << SIMTIME << " edge=" << edge->getID() << " to=" << pair.first->getID() << " via=" << pair.second->getID()
338  << " origSpeed=" << currSpeed
339  << " maxSpeed=" << maxSpeed
340  << " correctedSpeed=" << correctedSpeed
341  << " avgSpeed=" << avgSpeed
342  << " internalTT=" << internalTT
343  << " internalSpeed=" << origInternalSpeed
344  << " newInternalSpeed=" << newInternalSpeed
345  << " virtualSpeed=" << virtualSpeed
346  << "\n";
347  }
348 #endif
349  }
350  if (myAdaptationStepsIndex == 0) {
351  tc.first = 0;
352  tc.second = 0;
353  }
354  }
355  }
356  return correctedSpeed;
357  }
358  return currSpeed;
359 }
360 
361 
362 const MSRoute*
363 MSRoutingEngine::getCachedRoute(const std::pair<const MSEdge*, const MSEdge*>& key) {
364  auto routeIt = myCachedRoutes.find(key);
365  if (routeIt != myCachedRoutes.end()) {
366  return routeIt->second;
367  }
368  return nullptr;
369 }
370 
371 
372 void
375  const std::string routingAlgorithm = oc.getString("routing-algorithm");
376  const bool hasPermissions = MSNet::getInstance()->hasPermissions();
377  myBikeSpeeds = oc.getBool("device.rerouting.bike-speeds");
379 
380  SUMOAbstractRouter<MSEdge, SUMOVehicle>* router = nullptr;
381  if (routingAlgorithm == "dijkstra") {
382  router = new DijkstraRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, myEffortFunc, nullptr, false, nullptr, true);
383  } else if (routingAlgorithm == "astar") {
384  typedef AStarRouter<MSEdge, SUMOVehicle> AStar;
385  std::shared_ptr<const AStar::LookupTable> lookup = nullptr;
386  if (oc.isSet("astar.all-distances")) {
387  lookup = std::make_shared<const AStar::FLT>(oc.getString("astar.all-distances"), (int)MSEdge::getAllEdges().size());
388  } else if (oc.isSet("astar.landmark-distances") && vehicle != nullptr) {
389  const double speedFactor = vehicle->getChosenSpeedFactor();
390  // we need an exemplary vehicle with speedFactor 1
391  vehicle->setChosenSpeedFactor(1);
394  string2time(oc.getString("begin")), string2time(oc.getString("end")), SUMOTime_MAX, hasPermissions, 1);
395  lookup = std::make_shared<const AStar::LMLT>(oc.getString("astar.landmark-distances"), MSEdge::getAllEdges(), &chrouter,
396  nullptr, vehicle, "", oc.getInt("device.rerouting.threads"));
397  vehicle->setChosenSpeedFactor(speedFactor);
398  }
399  router = new AStar(MSEdge::getAllEdges(), true, myEffortFunc, lookup, true);
400  } else if (routingAlgorithm == "CH" && !hasPermissions) {
401  const SUMOTime weightPeriod = myAdaptationInterval > 0 ? myAdaptationInterval : SUMOTime_MAX;
402  router = new CHRouter<MSEdge, SUMOVehicle>(
403  MSEdge::getAllEdges(), true, myEffortFunc, vehicle == nullptr ? SVC_PASSENGER : vehicle->getVClass(), weightPeriod, true, false);
404  } else if (routingAlgorithm == "CHWrapper" || routingAlgorithm == "CH") {
405  // use CHWrapper instead of CH if the net has permissions
406  const SUMOTime weightPeriod = myAdaptationInterval > 0 ? myAdaptationInterval : SUMOTime_MAX;
409  string2time(oc.getString("begin")), string2time(oc.getString("end")), weightPeriod, hasPermissions, oc.getInt("device.rerouting.threads"));
410  } else {
411  throw ProcessError("Unknown routing algorithm '" + routingAlgorithm + "'!");
412  }
413 
414  RailwayRouter<MSEdge, SUMOVehicle>* railRouter = nullptr;
415  if (MSNet::getInstance()->hasBidiEdges()) {
416  railRouter = new RailwayRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, myEffortFunc, nullptr, false, true, false, oc.getFloat("railway.max-train-length"));
417  }
418  myRouterProvider = new MSRouterProvider(router, nullptr, nullptr, railRouter);
419 #ifndef THREAD_POOL
420 #ifdef HAVE_FOX
421  FXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
422  if (threadPool.size() > 0) {
423  const std::vector<FXWorkerThread*>& threads = threadPool.getWorkers();
424  if (static_cast<MSEdgeControl::WorkerThread*>(threads.front())->setRouterProvider(myRouterProvider)) {
425  for (std::vector<FXWorkerThread*>::const_iterator t = threads.begin() + 1; t != threads.end(); ++t) {
426  static_cast<MSEdgeControl::WorkerThread*>(*t)->setRouterProvider(myRouterProvider->clone());
427  }
428  }
429  }
430 #endif
431 #endif
432 }
433 
434 
435 void
436 MSRoutingEngine::reroute(SUMOVehicle& vehicle, const SUMOTime currentTime, const std::string& info,
437  const bool onInit, const bool silent, const MSEdgeVector& prohibited) {
438  if (myRouterProvider == nullptr) {
439  initRouter(&vehicle);
440  }
441  auto& router = myRouterProvider->getVehicleRouter(vehicle.getVClass());
442 #ifndef THREAD_POOL
443 #ifdef HAVE_FOX
444  FXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
445  if (threadPool.size() > 0) {
446  threadPool.add(new RoutingTask(vehicle, currentTime, info, onInit, silent, prohibited));
447  return;
448  }
449 #endif
450 #endif
451  if (!prohibited.empty()) {
452  router.prohibit(prohibited);
453  }
454  try {
455  vehicle.reroute(currentTime, info, router, onInit, myWithTaz, silent);
456  } catch (ProcessError&) {
457  if (!silent) {
458  if (!prohibited.empty()) {
459  router.prohibit(MSEdgeVector());
460  }
461  throw;
462  }
463  }
464  if (!prohibited.empty()) {
465  router.prohibit(MSEdgeVector());
466  }
467 }
468 
469 
470 void
471 MSRoutingEngine::setEdgeTravelTime(const MSEdge* const edge, const double travelTime) {
472  myEdgeSpeeds[edge->getNumericalID()] = edge->getLength() / travelTime;
473 }
474 
475 void
476 MSRoutingEngine::addEdgeTravelTime(const MSEdge& edge, const SUMOTime travelTime) {
478  tc.first += travelTime;
479  tc.second += 1;
480 }
481 
482 
484 MSRoutingEngine::getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector& prohibited) {
485  if (myRouterProvider == nullptr) {
487  initEdgeWeights(svc);
488  initRouter();
489  }
490 #ifndef THREAD_POOL
491 #ifdef HAVE_FOX
492  FXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
493  if (threadPool.size() > 0) {
494  auto& router = static_cast<MSEdgeControl::WorkerThread*>(threadPool.getWorkers()[rngIndex % MSGlobals::gNumThreads])->getRouter(svc);
495  router.prohibit(prohibited);
496  return router;
497  }
498 #endif
499 #endif
500  myRouterProvider->getVehicleRouter(svc).prohibit(prohibited);
501  return myRouterProvider->getVehicleRouter(svc);
502 }
503 
504 
505 void
507  myAdaptationInterval = -1; // responsible for triggering initEdgeWeights
508  myPastEdgeSpeeds.clear();
509  myEdgeSpeeds.clear();
510  myEdgeTravelTimes.clear();
511  myPastEdgeBikeSpeeds.clear();
512  myEdgeBikeSpeeds.clear();
513  // @todo recheck. calling release crashes in parallel routing
514  //for (auto& item : myCachedRoutes) {
515  // item.second->release();
516  //}
517  myCachedRoutes.clear();
519 #ifdef HAVE_FOX
520  if (MSGlobals::gNumThreads > 1) {
521  // router deletion is done in thread destructor
522  myRouterProvider = nullptr;
523  return;
524  }
525 #endif
526  delete myRouterProvider;
527  myRouterProvider = nullptr;
528 }
529 
530 
531 #ifdef HAVE_FOX
532 void
533 MSRoutingEngine::waitForAll() {
534 #ifndef THREAD_POOL
535  FXWorkerThread::Pool& threadPool = MSNet::getInstance()->getEdgeControl().getThreadPool();
536  if (threadPool.size() > 0) {
537  threadPool.waitAll();
538  }
539 #endif
540 }
541 
542 
543 // ---------------------------------------------------------------------------
544 // MSRoutingEngine::RoutingTask-methods
545 // ---------------------------------------------------------------------------
546 void
547 MSRoutingEngine::RoutingTask::run(FXWorkerThread* context) {
548  SUMOAbstractRouter<MSEdge, SUMOVehicle>& router = static_cast<MSEdgeControl::WorkerThread*>(context)->getRouter(myVehicle.getVClass());
549  if (!myProhibited.empty()) {
550  router.prohibit(myProhibited);
551  }
552  try {
553  myVehicle.reroute(myTime, myInfo, router, myOnInit, myWithTaz, mySilent);
554  } catch (ProcessError&) {
555  if (!mySilent) {
556  if (!myProhibited.empty()) {
557  router.prohibit(MSEdgeVector());
558  }
559  throw;
560  }
561  }
562  if (!myProhibited.empty()) {
563  router.prohibit(MSEdgeVector());
564  }
565  const MSEdge* source = *myVehicle.getRoute().begin();
566  const MSEdge* dest = myVehicle.getRoute().getLastEdge();
567  if (source->isTazConnector() && dest->isTazConnector()) {
568  const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
569  FXMutexLock lock(myRouteCacheMutex);
571  MSRoutingEngine::myCachedRoutes[key] = &myVehicle.getRoute();
572  myVehicle.getRoute().addReference();
573  }
574  }
575 }
576 #endif
577 
578 
579 /****************************************************************************/
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
#define DEBUG_COND(obj)
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
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:53
#define SUMOTime_MAX
Definition: SUMOTime.h:33
#define SIMTIME
Definition: SUMOTime.h:60
long long int SUMOTime
Definition: SUMOTime.h:32
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:29
T MIN2(T a, T b)
Definition: StdDefs.h:74
T MAX2(T a, T b)
Definition: StdDefs.h:80
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 add(Task *const t, int index=-1)
Gives a number to the given task and assigns it to the worker with the given index....
const std::vector< FXWorkerThread * > & getWorkers()
int size() const
Returns the number of threads in the pool.
void waitAll(const bool deleteFinished=true)
waits for all tasks to be finished
A thread repeatingly calculating incoming tasks.
const MSEdgeVector & getEdges() const
Returns loaded edges.
A road/street connecting two junctions.
Definition: MSEdge.h:77
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:918
int getPriority() const
Returns the priority of the edge.
Definition: MSEdge.h:322
const MSConstEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges with internal vias, restricted by vClass.
Definition: MSEdge.cpp:1114
double getLength() const
return the length of the edge
Definition: MSEdge.h:641
bool isTazConnector() const
Definition: MSEdge.h:285
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:459
int getNumericalID() const
Returns the numerical id of the edge.
Definition: MSEdge.h:300
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:160
static int gNumThreads
how many threads to use
Definition: MSGlobals.h:136
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:174
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:318
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:479
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:157
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:419
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
Definition: MSNet.h:209
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
static double myAdaptationWeight
Information which weight prior edge efforts have.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
static double myMinEdgePriority
Minimum priority for all edges.
static std::vector< TimeAndCount > myEdgeTravelTimes
Sum of travel times experienced by equipped vehicles for each edge.
static double getEffortBike(const MSEdge *const e, const SUMOVehicle *const v, double t)
static void setEdgeTravelTime(const MSEdge *const edge, const double travelTime)
adapt the known travel time for an edge
static void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const std::string &info, const bool onInit=false, const bool silent=false, const MSEdgeVector &prohibited=MSEdgeVector())
initiate the rerouting, create router / thread pool on first use
static double myEdgePriorityRange
the difference between maximum and minimum priority for all edges
static double myPriorityFactor
Coefficient for factoring edge priority into routing weight.
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
static const MSRoute * getCachedRoute(const std::pair< const MSEdge *, const MSEdge * > &key)
return the cached route or nullptr on miss
static bool myBikeSpeeds
whether separate speeds for bicycles shall be tracked
static void _initEdgeWeights(std::vector< double > &edgeSpeeds, std::vector< std::vector< double > > &pastEdgeSpeeds)
initialized edge speed storage into the given containers
static MSRouterProvider * myRouterProvider
The router to use.
static bool myWithTaz
whether taz shall be used at initial rerouting
static std::vector< std::vector< double > > myPastEdgeBikeSpeeds
static std::vector< double > myEdgeSpeeds
The container of edge speeds.
std::pair< SUMOTime, int > TimeAndCount
static void addEdgeTravelTime(const MSEdge &edge, const SUMOTime travelTime)
record actual travel time for an edge
static void initWeightUpdate()
intialize period edge weight update
RouterProvider< MSEdge, MSLane, MSJunction, SUMOVehicle > MSRouterProvider
static void initEdgeWeights(SUMOVehicleClass svc)
initialize the edge weights if not done before
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
static void cleanup()
deletes the router instance
static void initRouter(SUMOVehicle *vehicle=nullptr)
static SUMOAbstractRouter< MSEdge, SUMOVehicle >::Operation myEffortFunc
static int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of past edge speeds (when using a simple moving average)
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
static double getAssumedSpeed(const MSEdge *edge, const SUMOVehicle *veh)
return current travel speed assumption
static double patchSpeedForTurns(const MSEdge *edge, double currSpeed)
static double getEffortExtra(const MSEdge *const e, const SUMOVehicle *const v, double t)
static std::vector< double > myEdgeBikeSpeeds
const std::string & getID() const
Returns the id.
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:58
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="")
Creates the device using the output definition stored in the named option.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
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.h:119
RouterProvider * clone()
SUMOAbstractRouter< E, V > & getVehicleRouter(SUMOVehicleClass svc) const
virtual void prohibit(const std::vector< E * > &toProhibit)
virtual double getChosenSpeedFactor() const =0
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
Representation of a vehicle.
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