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  const int id = (*i)->getNumericalID();
325  const double currSpeed = (*i)->getMeanSpeed();
327  myPastEdgeSpeeds[id][myAdaptationStepsIndex] = currSpeed;
328  }
330  } else {
331  // exponential moving average
332  const double newWeightFactor = (double)(1. - myAdaptationWeight);
333  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
334  const int id = (*i)->getNumericalID();
335  const double currSpeed = (*i)->getMeanSpeed();
336  if (currSpeed != myEdgeSpeeds[id]) {
337  myEdgeSpeeds[id] = myEdgeSpeeds[id] * myAdaptationWeight + currSpeed * newWeightFactor;
338  }
339  }
340  }
341  myLastAdaptation = currentTime + DELTA_T; // because we run at the end of the time step
342  if (OptionsCont::getOptions().isSet("device.rerouting.output")) {
343  OutputDevice& dev = OutputDevice::getDeviceByOption("device.rerouting.output");
345  dev.writeAttr(SUMO_ATTR_ID, "device.rerouting");
346  dev.writeAttr(SUMO_ATTR_BEGIN, STEPS2TIME(currentTime));
348  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
349  const int id = (*i)->getNumericalID();
350  dev.openTag(SUMO_TAG_EDGE);
351  dev.writeAttr(SUMO_ATTR_ID, (*i)->getID());
352  dev.writeAttr("traveltime", (*i)->getLength() / myEdgeSpeeds[id]);
353  dev.closeTag();
354  }
355  dev.closeTag();
356  }
357  return myAdaptationInterval;
358 }
359 
360 
361 void
362 MSDevice_Routing::reroute(const SUMOTime currentTime, const bool onInit) {
363  initEdgeWeights();
364  //check whether the weights did change since the last reroute
366  return;
367  }
368  myLastRouting = currentTime;
369 #ifdef HAVE_FOX
370  const bool needThread = (myRouter == 0 && myThreadPool.isFull());
371 #else
372  const bool needThread = true;
373 #endif
374  if (needThread && myRouter == 0) {
376  const std::string routingAlgorithm = oc.getString("routing-algorithm");
377  const bool mayHaveRestrictions = MSNet::getInstance()->hasPermissions() || oc.getInt("remote-port") != 0;
378  if (routingAlgorithm == "dijkstra") {
379  if (mayHaveRestrictions) {
382  } else {
385  }
386  } else if (routingAlgorithm == "astar") {
387  if (mayHaveRestrictions) {
389  const AStar::LookupTable* lookup = 0;
390  if (oc.isSet("astar.all-distances")) {
391  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)MSEdge::getAllEdges().size());
392  } else if (oc.isSet("astar.landmark-distances")) {
393  const double speedFactor = myHolder.getChosenSpeedFactor();
394  // we need an exemplary vehicle with speedFactor 1
398  string2time(oc.getString("begin")), string2time(oc.getString("end")), std::numeric_limits<int>::max(), 1);
399  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), MSEdge::getAllEdges(), &router, &myHolder, "", oc.getInt("device.rerouting.threads"));
400  myHolder.setChosenSpeedFactor(speedFactor);
401  }
402  myRouter = new AStar(MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, lookup);
403  } else {
405  const AStar::LookupTable* lookup = 0;
406  if (oc.isSet("astar.all-distances")) {
407  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)MSEdge::getAllEdges().size());
408  } else if (oc.isSet("astar.landmark-distances")) {
409  const double speedFactor = myHolder.getChosenSpeedFactor();
410  // we need an exemplary vehicle with speedFactor 1
414  string2time(oc.getString("begin")), string2time(oc.getString("end")), std::numeric_limits<int>::max(), 1);
415  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), MSEdge::getAllEdges(), &router, &myHolder, "", oc.getInt("device.rerouting.threads"));
416  myHolder.setChosenSpeedFactor(speedFactor);
417  }
418  myRouter = new AStar(MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, lookup);
419  }
420  } else if (routingAlgorithm == "CH") {
421  const SUMOTime weightPeriod = myAdaptationInterval > 0 ? myAdaptationInterval : std::numeric_limits<int>::max();
422  if (mayHaveRestrictions) {
424  MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, myHolder.getVClass(), weightPeriod, true);
425  } else {
427  MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, myHolder.getVClass(), weightPeriod, false);
428  }
429  } else if (routingAlgorithm == "CHWrapper") {
430  const SUMOTime weightPeriod = myAdaptationInterval > 0 ? myAdaptationInterval : std::numeric_limits<int>::max();
433  string2time(oc.getString("begin")), string2time(oc.getString("end")), weightPeriod, oc.getInt("device.rerouting.threads"));
434  } else {
435  throw ProcessError("Unknown routing algorithm '" + routingAlgorithm + "'!");
436  }
437  }
438 #ifdef HAVE_FOX
439  if (needThread) {
440  const int numThreads = OptionsCont::getOptions().getInt("device.rerouting.threads");
441  if (myThreadPool.size() < numThreads) {
442  new WorkerThread(myThreadPool, myRouter);
443  }
444  if (myThreadPool.size() < numThreads) {
445  myRouter = 0;
446  }
447  }
448  if (myThreadPool.size() > 0) {
449  myThreadPool.add(new RoutingTask(myHolder, currentTime, onInit));
450  return;
451  }
452 #endif
453  myHolder.reroute(currentTime, "device.rerouting", *myRouter, onInit, myWithTaz);
454 }
455 
456 
459  if (myRouterWithProhibited == 0) {
462  initEdgeWeights();
464  }
465  myRouterWithProhibited->prohibit(prohibited);
466  return *myRouterWithProhibited;
467 }
468 
469 
470 std::string
471 MSDevice_Routing::getParameter(const std::string& key) const {
472  if (StringUtils::startsWith(key, "edge:")) {
473  const std::string edgeID = key.substr(5);
474  const MSEdge* edge = MSEdge::dictionary(edgeID);
475  if (edge == 0) {
476  throw InvalidArgument("Edge '" + edgeID + "' is invalid for parameter retrieval of '" + deviceName() + "'");
477  }
478  return toString(getEffort(edge, &myHolder, 0));
479  } else if (key == "period") {
480  return time2string(myPeriod);
481  }
482  throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
483 }
484 
485 
486 void
487 MSDevice_Routing::setParameter(const std::string& key, const std::string& value) {
488  double doubleValue;
489  try {
490  doubleValue = TplConvert::_2double(value.c_str());
491  } catch (NumberFormatException&) {
492  throw InvalidArgument("Setting parameter '" + key + "' requires a number for device of type '" + deviceName() + "'");
493  }
494  if (StringUtils::startsWith(key, "edge:")) {
495  const std::string edgeID = key.substr(5);
496  const MSEdge* edge = MSEdge::dictionary(edgeID);
497  if (edge == 0) {
498  throw InvalidArgument("Edge '" + edgeID + "' is invalid for parameter setting of '" + deviceName() + "'");
499  }
500  myEdgeSpeeds[edge->getNumericalID()] = edge->getLength() / doubleValue;
501  } else if (key == "period") {
502  const SUMOTime oldPeriod = myPeriod;
503  myPeriod = TIME2STEPS(doubleValue);
504  if (myPeriod <= 0) {
506  } else if (oldPeriod <= 0) {
507  // re-schedule routing command
509  }
510  } else {
511  throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
512  }
513 }
514 
515 
516 void
519  out.writeAttr(SUMO_ATTR_ID, getID());
520  std::vector<std::string> internals;
521  internals.push_back(toString(myPeriod));
522  out.writeAttr(SUMO_ATTR_STATE, toString(internals));
523  out.closeTag();
524 }
525 
526 
527 void
529  std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
530  bis >> myPeriod;
531 }
532 
533 
534 
535 
536 void
538  delete myRouterWithProhibited;
540 #ifdef HAVE_FOX
541  if (myThreadPool.size() > 0) {
542  // we cannot wait for the static destructor to do the cleanup
543  // because the output devices are gone by then
544  myThreadPool.clear();
545  // router deletion is done in thread destructor
546  myRouter = 0;
547  return;
548  }
549 #endif
550  delete myRouter;
551  myRouter = 0;
552 }
553 
554 
555 #ifdef HAVE_FOX
556 void
557 MSDevice_Routing::waitForAll() {
558  if (myThreadPool.size() > 0) {
559  myThreadPool.waitAll();
560  }
561 }
562 
563 
564 // ---------------------------------------------------------------------------
565 // MSDevice_Routing::RoutingTask-methods
566 // ---------------------------------------------------------------------------
567 void
568 MSDevice_Routing::RoutingTask::run(FXWorkerThread* context) {
569  myVehicle.reroute(myTime, "device.rerouting", static_cast<WorkerThread*>(context)->getRouter(), myOnInit, myWithTaz);
570  const MSEdge* source = *myVehicle.getRoute().begin();
571  const MSEdge* dest = myVehicle.getRoute().getLastEdge();
572  if (source->isTazConnector() && dest->isTazConnector()) {
573  const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
574  lock();
576  MSDevice_Routing::myCachedRoutes[key] = &myVehicle.getRoute();
577  myVehicle.getRoute().addReference();
578  }
579  unlock();
580  }
581 }
582 #endif
583 
584 
585 /****************************************************************************/
586 
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:68
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:740
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:306
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:773
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.