SUMO - Simulation of Urban MObility
MSDevice_Routing.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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // A device that performs vehicle rerouting based on current edge speeds
20 /****************************************************************************/
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include "MSDevice_Routing.h"
28 #include <microsim/MSNet.h>
29 #include <microsim/MSLane.h>
30 #include <microsim/MSEdge.h>
31 #include <microsim/MSEdgeControl.h>
33 #include <microsim/MSGlobals.h>
42 #include <utils/vehicle/CHRouter.h>
44 
45 
46 // ===========================================================================
47 // static member variables
48 // ===========================================================================
49 std::vector<double> MSDevice_Routing::myEdgeSpeeds;
50 std::vector<std::vector<double> > MSDevice_Routing::myPastEdgeSpeeds;
58 std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> MSDevice_Routing::myCachedRoutes;
62 #ifdef HAVE_FOX
63 FXWorkerThread::Pool MSDevice_Routing::myThreadPool;
64 #endif
65 
66 
67 // ===========================================================================
68 // method definitions
69 // ===========================================================================
70 // ---------------------------------------------------------------------------
71 // static initialisation methods
72 // ---------------------------------------------------------------------------
73 void
75  insertDefaultAssignmentOptions("rerouting", "Routing", oc);
76 
77  oc.doRegister("device.rerouting.period", new Option_String("0", "TIME"));
78  oc.addSynonyme("device.rerouting.period", "device.routing.period", true);
79  oc.addDescription("device.rerouting.period", "Routing", "The period with which the vehicle shall be rerouted");
80 
81  oc.doRegister("device.rerouting.pre-period", new Option_String("60", "TIME"));
82  oc.addSynonyme("device.rerouting.pre-period", "device.routing.pre-period", true);
83  oc.addDescription("device.rerouting.pre-period", "Routing", "The rerouting period before depart");
84 
85  oc.doRegister("device.rerouting.adaptation-weight", new Option_Float(.5));
86  oc.addSynonyme("device.rerouting.adaptation-weight", "device.routing.adaptation-weight", true);
87  oc.addDescription("device.rerouting.adaptation-weight", "Routing", "The weight of prior edge weights for exponential moving average");
88 
89  oc.doRegister("device.rerouting.adaptation-steps", new Option_Integer(0));
90  oc.addSynonyme("device.rerouting.adaptation-steps", "device.routing.adaptation-steps", true);
91  oc.addDescription("device.rerouting.adaptation-steps", "Routing", "The number of steps for moving average weight of prior edge weights");
92 
93  oc.doRegister("device.rerouting.adaptation-interval", new Option_String("1", "TIME"));
94  oc.addSynonyme("device.rerouting.adaptation-interval", "device.routing.adaptation-interval", true);
95  oc.addDescription("device.rerouting.adaptation-interval", "Routing", "The interval for updating the edge weights");
96 
97  oc.doRegister("device.rerouting.with-taz", new Option_Bool(false));
98  oc.addSynonyme("device.rerouting.with-taz", "device.routing.with-taz", true);
99  oc.addSynonyme("device.rerouting.with-taz", "with-taz");
100  oc.addDescription("device.rerouting.with-taz", "Routing", "Use zones (districts) as routing start- and endpoints");
101 
102  oc.doRegister("device.rerouting.init-with-loaded-weights", new Option_Bool(false));
103  oc.addDescription("device.rerouting.init-with-loaded-weights", "Routing", "Use weight files given with option --weight-files for initializing edge weights");
104 
105  oc.doRegister("device.rerouting.threads", new Option_Integer(0));
106  oc.addDescription("device.rerouting.threads", "Routing", "The number of parallel execution threads used for rerouting");
107 
108  oc.doRegister("device.rerouting.output", new Option_FileName());
109  oc.addDescription("device.rerouting.output", "Routing", "Save adapting weights to FILE");
110 
112  myEdgeSpeeds.clear();
114  myAdaptationSteps = -1;
115  myLastAdaptation = -1;
116 }
117 
118 
119 bool
121  bool ok = true;
122  if (oc.getInt("device.rerouting.adaptation-steps") > 0 && !oc.isDefault("device.rerouting.adaptation-weight")) {
123  WRITE_ERROR("Only one of the options 'device.rerouting.adaptation-steps' or 'device.rerouting.adaptation-weight' may be given.");
124  ok = false;
125  }
126  if (oc.getFloat("weights.random-factor") < 1) {
127  WRITE_ERROR("weights.random-factor cannot be less than 1");
128  ok = false;
129  }
130  if (string2time(oc.getString("device.rerouting.adaptation-interval")) < 0) {
131  WRITE_ERROR("Negative value for device.rerouting.adaptation-interval!");
132  ok = false;
133  }
134  if (oc.getFloat("device.rerouting.adaptation-weight") < 0. ||
135  oc.getFloat("device.rerouting.adaptation-weight") > 1.) {
136  WRITE_ERROR("The value for device.rerouting.adaptation-weight must be between 0 and 1!");
137  ok = false;
138  }
139 #ifndef HAVE_FOX
140  if (oc.getInt("device.rerouting.threads") > 1) {
141  WRITE_ERROR("Parallel routing is only possible when compiled with Fox.");
142  ok = false;
143  }
144 #endif
145  return ok;
146 }
147 
148 
149 void
150 MSDevice_Routing::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
151  const OptionsCont& oc = OptionsCont::getOptions();
152  if (v.getParameter().wasSet(VEHPARS_FORCE_REROUTE) || equippedByDefaultAssignmentOptions(oc, "rerouting", v, false)) {
153  // route computation is enabled
154  myWithTaz = oc.getBool("device.rerouting.with-taz");
155  const SUMOTime period = string2time(oc.getString("device.rerouting.period"));
156  const SUMOTime prePeriod = string2time(oc.getString("device.rerouting.pre-period"));
158  // build the device
159  into.push_back(new MSDevice_Routing(v, "routing_" + v.getID(), period, prePeriod));
160  }
161 }
162 
163 void
165  if (myAdaptationInterval == -1) {
166  const OptionsCont& oc = OptionsCont::getOptions();
167  myAdaptationInterval = string2time(oc.getString("device.rerouting.adaptation-interval"));
168  myAdaptationWeight = oc.getFloat("device.rerouting.adaptation-weight");
169  const SUMOTime period = string2time(oc.getString("device.rerouting.period"));
170  if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
173  } else if (period > 0) {
174  WRITE_WARNING("Rerouting is useless if the edge weights do not get updated!");
175  }
176  OutputDevice::createDeviceByOption("device.rerouting.output", "weights", "meandata_file.xsd");
177  }
178 }
179 
180 // ---------------------------------------------------------------------------
181 // MSDevice_Routing-methods
182 // ---------------------------------------------------------------------------
183 MSDevice_Routing::MSDevice_Routing(SUMOVehicle& holder, const std::string& id,
184  SUMOTime period, SUMOTime preInsertionPeriod)
185  : MSDevice(holder, id), myPeriod(period), myPreInsertionPeriod(preInsertionPeriod), myLastRouting(-1), mySkipRouting(-1), myRerouteCommand(0) {
187  // we do always a pre insertion reroute for trips to fill the best lanes of the vehicle with somehow meaningful values (especially for deaprtLane="best")
189  // if we don't update the edge weights, we might as well reroute now and hopefully use our threads better
190  const SUMOTime execTime = myEdgeWeightSettingCommand == nullptr ? -1 : holder.getParameter().depart;
192  if (myPreInsertionPeriod == 0) {
193  // the event will deschedule and destroy itself so it does not need to be stored
194  myRerouteCommand = nullptr;
195  }
196  }
197 }
198 
199 
201  // make the rerouting command invalid if there is one
202  if (myRerouteCommand != nullptr) {
204  }
205 }
206 
207 
208 bool
211  // clean up pre depart rerouting
212  if (myRerouteCommand != nullptr) {
214  }
215  myRerouteCommand = nullptr;
216  // build repetition trigger if routing shall be done more often
217  if (myPeriod > 0) {
220  myRerouteCommand, myPeriod + MSNet::getInstance()->getCurrentTimeStep());
221  }
222  }
223  return false;
224 }
225 
226 
227 void
229  if (myEdgeSpeeds.empty()) {
230  const OptionsCont& oc = OptionsCont::getOptions();
231  myAdaptationSteps = oc.getInt("device.rerouting.adaptation-steps");
232  const bool useLoaded = oc.getBool("device.rerouting.init-with-loaded-weights");
233  const double currentSecond = SIMTIME;
234  for (const MSEdge* const edge : MSNet::getInstance()->getEdgeControl().getEdges()) {
235  while (edge->getNumericalID() >= (int)myEdgeSpeeds.size()) {
236  myEdgeSpeeds.push_back(0);
237  if (myAdaptationSteps > 0) {
238  myPastEdgeSpeeds.push_back(std::vector<double>());
239  }
240  }
241  if (useLoaded) {
242  myEdgeSpeeds[edge->getNumericalID()] = edge->getLength() / MSNet::getTravelTime(edge, 0, currentSecond);
243  } else {
244  myEdgeSpeeds[edge->getNumericalID()] = edge->getMeanSpeed();
245  }
246  if (myAdaptationSteps > 0) {
247  myPastEdgeSpeeds[edge->getNumericalID()] = std::vector<double>(myAdaptationSteps, myEdgeSpeeds[edge->getNumericalID()]);
248  }
249  }
251  myRandomizeWeightsFactor = oc.getFloat("weights.random-factor");
252  }
253 }
254 
255 
256 SUMOTime
258  if (mySkipRouting == currentTime) {
259  return DELTA_T;
260  }
261  const MSEdge* source = *myHolder.getRoute().begin();
262  const MSEdge* dest = myHolder.getRoute().getLastEdge();
263  if (source->isTazConnector() && dest->isTazConnector()) {
264  const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
265  if (myCachedRoutes.find(key) != myCachedRoutes.end()) {
266  if (myCachedRoutes[key]->size() > 2) {
267  myHolder.replaceRoute(myCachedRoutes[key], "device.rerouting", true);
268  return myPreInsertionPeriod;
269  }
270  }
271  }
272  try {
273  reroute(currentTime, true);
274  } catch (ProcessError&) {
275  myRerouteCommand = nullptr;
276  throw;
277  }
278  return myPreInsertionPeriod;
279 }
280 
281 
282 SUMOTime
284  reroute(currentTime);
285  return myPeriod;
286 }
287 
288 
289 double
290 MSDevice_Routing::getEffort(const MSEdge* const e, const SUMOVehicle* const v, double) {
291  const int id = e->getNumericalID();
292  if (id < (int)myEdgeSpeeds.size()) {
293  double effort = MAX2(e->getLength() / MAX2(myEdgeSpeeds[id], NUMERICAL_EPS), e->getMinimumTravelTime(v));
294  if (myRandomizeWeightsFactor != 1.) {
296  }
297  return effort;
298  }
299  return 0.;
300 }
301 
302 
303 double
305  return edge->getLength() / getEffort(edge, 0, 0);
306 }
307 
308 
309 SUMOTime
311  initEdgeWeights();
312  if (MSNet::getInstance()->getVehicleControl().getDepartedVehicleNo() == 0) {
313  return myAdaptationInterval;
314  }
315  std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*>::iterator it = myCachedRoutes.begin();
316  for (; it != myCachedRoutes.end(); ++it) {
317  it->second->release();
318  }
319  myCachedRoutes.clear();
321  if (myAdaptationSteps > 0) {
322  // moving average
323  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
324  if ((*i)->isDelayed()) {
325  const int id = (*i)->getNumericalID();
326  const double currSpeed = (*i)->getMeanSpeed();
328  myPastEdgeSpeeds[id][myAdaptationStepsIndex] = currSpeed;
329  }
330  }
332  } else {
333  // exponential moving average
334  const double newWeightFactor = (double)(1. - myAdaptationWeight);
335  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
336  if ((*i)->isDelayed()) {
337  const int id = (*i)->getNumericalID();
338  const double currSpeed = (*i)->getMeanSpeed();
339  if (currSpeed != myEdgeSpeeds[id]) {
340  myEdgeSpeeds[id] = myEdgeSpeeds[id] * myAdaptationWeight + currSpeed * newWeightFactor;
341  }
342  }
343  }
344  }
345  myLastAdaptation = currentTime + DELTA_T; // because we run at the end of the time step
346  if (OptionsCont::getOptions().isSet("device.rerouting.output")) {
347  OutputDevice& dev = OutputDevice::getDeviceByOption("device.rerouting.output");
349  dev.writeAttr(SUMO_ATTR_ID, "device.rerouting");
350  dev.writeAttr(SUMO_ATTR_BEGIN, STEPS2TIME(currentTime));
352  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
353  const int id = (*i)->getNumericalID();
354  dev.openTag(SUMO_TAG_EDGE);
355  dev.writeAttr(SUMO_ATTR_ID, (*i)->getID());
356  dev.writeAttr("traveltime", (*i)->getLength() / myEdgeSpeeds[id]);
357  dev.closeTag();
358  }
359  dev.closeTag();
360  }
361  return myAdaptationInterval;
362 }
363 
364 
365 void
366 MSDevice_Routing::reroute(const SUMOTime currentTime, const bool onInit) {
367  initEdgeWeights();
368  //check whether the weights did change since the last reroute
370  return;
371  }
372  myLastRouting = currentTime;
373 #ifdef HAVE_FOX
374  const bool needThread = (myRouter == 0 && myThreadPool.isFull());
375 #else
376  const bool needThread = true;
377 #endif
378  if (needThread && myRouter == 0) {
380  const std::string routingAlgorithm = oc.getString("routing-algorithm");
381  const bool mayHaveRestrictions = MSNet::getInstance()->hasPermissions() || oc.getInt("remote-port") != 0;
382  if (routingAlgorithm == "dijkstra") {
383  if (mayHaveRestrictions) {
386  } else {
389  }
390  } else if (routingAlgorithm == "astar") {
391  if (mayHaveRestrictions) {
393  const AStar::LookupTable* lookup = 0;
394  if (oc.isSet("astar.all-distances")) {
395  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)MSEdge::getAllEdges().size());
396  } else if (oc.isSet("astar.landmark-distances")) {
397  const double speedFactor = myHolder.getChosenSpeedFactor();
398  // we need an exemplary vehicle with speedFactor 1
402  string2time(oc.getString("begin")), string2time(oc.getString("end")), std::numeric_limits<int>::max(), 1);
403  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), MSEdge::getAllEdges(), &router, &myHolder, "", oc.getInt("device.rerouting.threads"));
404  myHolder.setChosenSpeedFactor(speedFactor);
405  }
406  myRouter = new AStar(MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, lookup);
407  } else {
409  const AStar::LookupTable* lookup = 0;
410  if (oc.isSet("astar.all-distances")) {
411  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)MSEdge::getAllEdges().size());
412  } else if (oc.isSet("astar.landmark-distances")) {
413  const double speedFactor = myHolder.getChosenSpeedFactor();
414  // we need an exemplary vehicle with speedFactor 1
418  string2time(oc.getString("begin")), string2time(oc.getString("end")), std::numeric_limits<int>::max(), 1);
419  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), MSEdge::getAllEdges(), &router, &myHolder, "", oc.getInt("device.rerouting.threads"));
420  myHolder.setChosenSpeedFactor(speedFactor);
421  }
422  myRouter = new AStar(MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, lookup);
423  }
424  } else if (routingAlgorithm == "CH") {
425  const SUMOTime weightPeriod = myAdaptationInterval > 0 ? myAdaptationInterval : std::numeric_limits<int>::max();
426  if (mayHaveRestrictions) {
428  MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, myHolder.getVClass(), weightPeriod, true);
429  } else {
431  MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, myHolder.getVClass(), weightPeriod, false);
432  }
433  } else if (routingAlgorithm == "CHWrapper") {
434  const SUMOTime weightPeriod = myAdaptationInterval > 0 ? myAdaptationInterval : std::numeric_limits<int>::max();
437  string2time(oc.getString("begin")), string2time(oc.getString("end")), weightPeriod, oc.getInt("device.rerouting.threads"));
438  } else {
439  throw ProcessError("Unknown routing algorithm '" + routingAlgorithm + "'!");
440  }
441  }
442 #ifdef HAVE_FOX
443  if (needThread) {
444  const int numThreads = OptionsCont::getOptions().getInt("device.rerouting.threads");
445  if (myThreadPool.size() < numThreads) {
446  new WorkerThread(myThreadPool, myRouter);
447  }
448  if (myThreadPool.size() < numThreads) {
449  myRouter = 0;
450  }
451  }
452  if (myThreadPool.size() > 0) {
453  myThreadPool.add(new RoutingTask(myHolder, currentTime, onInit));
454  return;
455  }
456 #endif
457  myHolder.reroute(currentTime, "device.rerouting", *myRouter, onInit, myWithTaz);
458 }
459 
460 
463  if (myRouterWithProhibited == 0) {
466  initEdgeWeights();
468  }
469  myRouterWithProhibited->prohibit(prohibited);
470  return *myRouterWithProhibited;
471 }
472 
473 
474 std::string
475 MSDevice_Routing::getParameter(const std::string& key) const {
476  if (StringUtils::startsWith(key, "edge:")) {
477  const std::string edgeID = key.substr(5);
478  const MSEdge* edge = MSEdge::dictionary(edgeID);
479  if (edge == 0) {
480  throw InvalidArgument("Edge '" + edgeID + "' is invalid for parameter retrieval of '" + deviceName() + "'");
481  }
482  return toString(getEffort(edge, &myHolder, 0));
483  } else if (key == "period") {
484  return time2string(myPeriod);
485  }
486  throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
487 }
488 
489 
490 void
491 MSDevice_Routing::setParameter(const std::string& key, const std::string& value) {
492  double doubleValue;
493  try {
494  doubleValue = TplConvert::_2double(value.c_str());
495  } catch (NumberFormatException&) {
496  throw InvalidArgument("Setting parameter '" + key + "' requires a number for device of type '" + deviceName() + "'");
497  }
498  if (StringUtils::startsWith(key, "edge:")) {
499  const std::string edgeID = key.substr(5);
500  const MSEdge* edge = MSEdge::dictionary(edgeID);
501  if (edge == 0) {
502  throw InvalidArgument("Edge '" + edgeID + "' is invalid for parameter setting of '" + deviceName() + "'");
503  }
504  myEdgeSpeeds[edge->getNumericalID()] = edge->getLength() / doubleValue;
505  } else if (key == "period") {
506  const SUMOTime oldPeriod = myPeriod;
507  myPeriod = TIME2STEPS(doubleValue);
508  if (myPeriod <= 0) {
510  } else if (oldPeriod <= 0) {
511  // re-schedule routing command
513  }
514  } else {
515  throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
516  }
517 }
518 
519 
520 void
523  out.writeAttr(SUMO_ATTR_ID, getID());
524  std::vector<std::string> internals;
525  internals.push_back(toString(myPeriod));
526  out.writeAttr(SUMO_ATTR_STATE, toString(internals));
527  out.closeTag();
528 }
529 
530 
531 void
533  std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
534  bis >> myPeriod;
535 }
536 
537 
538 
539 
540 void
542  delete myRouterWithProhibited;
544 #ifdef HAVE_FOX
545  if (myThreadPool.size() > 0) {
546  // we cannot wait for the static destructor to do the cleanup
547  // because the output devices are gone by then
548  myThreadPool.clear();
549  // router deletion is done in thread destructor
550  myRouter = 0;
551  return;
552  }
553 #endif
554  delete myRouter;
555  myRouter = 0;
556 }
557 
558 
559 #ifdef HAVE_FOX
560 void
561 MSDevice_Routing::waitForAll() {
562  if (myThreadPool.size() > 0) {
563  myThreadPool.waitAll();
564  }
565 }
566 
567 
568 // ---------------------------------------------------------------------------
569 // MSDevice_Routing::RoutingTask-methods
570 // ---------------------------------------------------------------------------
571 void
572 MSDevice_Routing::RoutingTask::run(FXWorkerThread* context) {
573  myVehicle.reroute(myTime, "device.rerouting", static_cast<WorkerThread*>(context)->getRouter(), myOnInit, myWithTaz);
574  const MSEdge* source = *myVehicle.getRoute().begin();
575  const MSEdge* dest = myVehicle.getRoute().getLastEdge();
576  if (source->isTazConnector() && dest->isTazConnector()) {
577  const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
578  lock();
580  MSDevice_Routing::myCachedRoutes[key] = &myVehicle.getRoute();
581  myVehicle.getRoute().addReference();
582  }
583  unlock();
584  }
585 }
586 #endif
587 
588 
589 /****************************************************************************/
590 
Computes the shortest path through a contracted network.
Definition: CHRouter.h:63
SUMOTime myPeriod
The period with which a vehicle shall be rerouted.
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key ...
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
long long int SUMOTime
Definition: SUMOTime.h:36
const int VEHPARS_FORCE_REROUTE
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
static double myRandomizeWeightsFactor
Whether to disturb edge weights dynamically.
SUMOTime mySkipRouting
The time for which routing may be skipped because we cannot be inserted.
virtual const MSRoute & getRoute() const =0
Returns the current route.
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
Definition: MSNet.h:176
SUMOVehicle & myHolder
The vehicle that stores the device.
Definition: MSDevice.h:195
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
SUMOTime myLastRouting
The last time a routing took place.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:61
MSDevice_Routing(SUMOVehicle &holder, const std::string &id, SUMOTime period, SUMOTime preInsertionPeriod)
Constructor.
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:77
weights: time range begin
const std::string deviceName() const
return the name for this type of device
SUMOTime myPreInsertionPeriod
The period with which a vehicle shall be rerouted before insertion.
virtual bool replaceRoute(const MSRoute *route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true)=0
Replaces the current route by the given one.
static int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
T MAX2(T a, T b)
Definition: StdDefs.h:76
SUMOTime DELTA_T
Definition: SUMOTime.cpp:35
void saveState(OutputDevice &out) const
Saves the state of the device.
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:742
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:85
SUMOTime wrappedRerouteCommandExecute(SUMOTime currentTime)
Performs rerouting after a period.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
const std::string & getID() const
Returns the id.
Definition: Named.h:69
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
Base (microsim) event class.
Definition: Command.h:54
static AStarRouter< MSEdge, SUMOVehicle, SUMOAbstractRouterPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
double getLength() const
return the length of the edge
Definition: MSEdge.h:563
int getNumericalID() const
Returns the numerical id of the edge.
Definition: MSEdge.h:254
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:242
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
#define SIMTIME
Definition: SUMOTime.h:65
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of edge speeds.
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
static double myAdaptationWeight
Information which weight prior edge efforts have.
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
Definition: OptionsCont.cpp:96
void prohibit(const std::vector< E *> &toProhibit)
The state of a link.
A road/street connecting two junctions.
Definition: MSEdge.h:75
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
virtual SUMOVehicleClass getVClass() const =0
Returns the vehicle&#39;s access class.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Routing-options.
static bool myWithTaz
whether taz shall be used at initial rerouting
void reroute(const SUMOTime currentTime, const bool onInit=false)
initiate the rerouting, create router / thread pool on first use
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
virtual void setChosenSpeedFactor(const double factor)=0
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
Representation of a vehicle.
Definition: SUMOVehicle.h:60
Encapsulated SAX-Attributes.
Computes the shortest path through a network using the Dijkstra algorithm.
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:143
static void initEdgeWeights()
initialize the edge weights if not done before
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:402
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:407
SUMOTime depart
The vehicle&#39;s departure time.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
A wrapper for a Command function.
Definition: StaticCommand.h:42
static void initWeightUpdate()
intialize period edge weight update
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:256
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:42
static std::vector< double > myEdgeSpeeds
The container of edge speeds.
WrappingCommand< MSDevice_Routing > * myRerouteCommand
The (optional) command responsible for rerouting.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:112
virtual double getChosenSpeedFactor() const =0
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
begin/end of the description of an edge
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:412
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:248
Abstract in-vehicle device.
Definition: MSDevice.h:65
A pool of worker threads which distributes the tasks and collects the results.
The vehicle has departed (was inserted into the network)
An integer-option.
Definition: Option.h:318
bool isTazConnector() const
Definition: MSEdge.h:247
void deschedule()
Marks this Command as being descheduled.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouter
The router to use.
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:775
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;s parameter (including departure definition)
weights: time range end
A storage for options typed value containers)
Definition: OptionsCont.h:92
static double _2double(const E *const data)
converts a char-type array into the double value described by it
Definition: TplConvert.h:305
MSEventControl * getInsertionEvents()
Returns the event control for insertion events.
Definition: MSNet.h:422
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes a new route on vehicle insertion.
const MSEdgeVector & getEdges() const
Returns loaded edges.
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v, bool outputOptionSet)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:126
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
bool wasSet(int what) const
Returns whether the given parameter was set.
an aggreagated-output interval
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.
~MSDevice_Routing()
Destructor.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static void cleanup()
deletes the router instance
static bool checkOptions(OptionsCont &oc)
checks MSDevice_Routing-options
A thread repeatingly calculating incoming tasks.
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:352
#define NUMERICAL_EPS
Definition: config.h:148
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:67
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:71
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
static double getAssumedSpeed(const MSEdge *edge)
return current travel speed assumption
virtual void reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false)=0
Performs a rerouting using the given router.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
Representation of a lane in the micro simulation.
Definition: MSLane.h:71
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key ...
SUMOTime preInsertionReroute(const SUMOTime currentTime)
Performs rerouting before insertion into the network.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
Computes the shortest path through a contracted network.