SUMO - Simulation of Urban MObility
MSDevice_Routing.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // A device that performs vehicle rerouting based on current edge speeds
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2007-2017 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include "MSDevice_Routing.h"
35 #include <microsim/MSNet.h>
36 #include <microsim/MSLane.h>
37 #include <microsim/MSEdge.h>
38 #include <microsim/MSEdgeControl.h>
40 #include <microsim/MSGlobals.h>
48 #include <utils/vehicle/CHRouter.h>
50 
51 
52 // ===========================================================================
53 // static member variables
54 // ===========================================================================
55 std::vector<double> MSDevice_Routing::myEdgeSpeeds;
56 std::vector<std::vector<double> > MSDevice_Routing::myPastEdgeSpeeds;
64 std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> MSDevice_Routing::myCachedRoutes;
68 #ifdef HAVE_FOX
69 FXWorkerThread::Pool MSDevice_Routing::myThreadPool;
70 #endif
71 
72 
73 // ===========================================================================
74 // method definitions
75 // ===========================================================================
76 // ---------------------------------------------------------------------------
77 // static initialisation methods
78 // ---------------------------------------------------------------------------
79 void
81  insertDefaultAssignmentOptions("rerouting", "Routing", oc);
82 
83  oc.doRegister("device.rerouting.period", new Option_String("0", "TIME"));
84  oc.addSynonyme("device.rerouting.period", "device.routing.period", true);
85  oc.addDescription("device.rerouting.period", "Routing", "The period with which the vehicle shall be rerouted");
86 
87  oc.doRegister("device.rerouting.pre-period", new Option_String("1", "TIME"));
88  oc.addSynonyme("device.rerouting.pre-period", "device.routing.pre-period", true);
89  oc.addDescription("device.rerouting.pre-period", "Routing", "The rerouting period before depart");
90 
91  oc.doRegister("device.rerouting.adaptation-weight", new Option_Float(.5));
92  oc.addSynonyme("device.rerouting.adaptation-weight", "device.routing.adaptation-weight", true);
93  oc.addDescription("device.rerouting.adaptation-weight", "Routing", "The weight of prior edge weights for exponential moving average");
94 
95  oc.doRegister("device.rerouting.adaptation-steps", new Option_Integer(0));
96  oc.addSynonyme("device.rerouting.adaptation-steps", "device.routing.adaptation-steps", true);
97  oc.addDescription("device.rerouting.adaptation-steps", "Routing", "The number of steps for moving average weight of prior edge weights");
98 
99  oc.doRegister("device.rerouting.adaptation-interval", new Option_String("1", "TIME"));
100  oc.addSynonyme("device.rerouting.adaptation-interval", "device.routing.adaptation-interval", true);
101  oc.addDescription("device.rerouting.adaptation-interval", "Routing", "The interval for updating the edge weights");
102 
103  oc.doRegister("device.rerouting.with-taz", new Option_Bool(false));
104  oc.addSynonyme("device.rerouting.with-taz", "device.routing.with-taz", true);
105  oc.addSynonyme("device.rerouting.with-taz", "with-taz");
106  oc.addDescription("device.rerouting.with-taz", "Routing", "Use zones (districts) as routing start- and endpoints");
107 
108  oc.doRegister("device.rerouting.init-with-loaded-weights", new Option_Bool(false));
109  oc.addDescription("device.rerouting.init-with-loaded-weights", "Routing", "Use weight files given with option --weight-files for initializing edge weights");
110 
111  oc.doRegister("device.rerouting.threads", new Option_Integer(0));
112  oc.addDescription("device.rerouting.threads", "Routing", "The number of parallel execution threads used for rerouting");
113 
114  oc.doRegister("device.rerouting.output", new Option_FileName());
115  oc.addDescription("device.rerouting.output", "Routing", "Save adapting weights to FILE");
116 
118  myEdgeSpeeds.clear();
120  myAdaptationSteps = -1;
121  myLastAdaptation = -1;
122 }
123 
124 
125 bool
127  bool ok = true;
128  if (oc.getInt("device.rerouting.adaptation-steps") > 0 && !oc.isDefault("device.rerouting.adaptation-weight")) {
129  WRITE_ERROR("Only one of the options 'device.rerouting.adaptation-steps' or 'device.rerouting.adaptation-weight' may be given.");
130  ok = false;
131  }
132  if (oc.getFloat("weights.random-factor") < 1) {
133  WRITE_ERROR("weights.random-factor cannot be less than 1");
134  ok = false;
135  }
136  if (string2time(oc.getString("device.rerouting.adaptation-interval")) < 0) {
137  WRITE_ERROR("Negative value for device.rerouting.adaptation-interval!");
138  ok = false;
139  }
140  if (oc.getFloat("device.rerouting.adaptation-weight") < 0. ||
141  oc.getFloat("device.rerouting.adaptation-weight") > 1.) {
142  WRITE_ERROR("The value for device.rerouting.adaptation-weight must be between 0 and 1!");
143  ok = false;
144  }
145 #ifndef HAVE_FOX
146  if (oc.getInt("device.rerouting.threads") > 1) {
147  WRITE_ERROR("Parallel routing is only possible when compiled with Fox.");
148  ok = false;
149  }
150 #endif
151  return ok;
152 }
153 
154 
155 void
156 MSDevice_Routing::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
158  bool needRerouting = v.getParameter().wasSet(VEHPARS_FORCE_REROUTE);
159  needRerouting |= equippedByDefaultAssignmentOptions(oc, "rerouting", v);
160  if (!needRerouting && oc.getFloat("device.rerouting.probability") == 0 && !oc.isSet("device.rerouting.explicit")) {
161  // no route computation is modelled
162  return;
163  }
164  if (needRerouting) {
165  // route computation is enabled
166  myWithTaz = oc.getBool("device.rerouting.with-taz");
167  const SUMOTime period = string2time(oc.getString("device.rerouting.period"));
168  const SUMOTime prePeriod = string2time(oc.getString("device.rerouting.pre-period"));
169  // initialise edge efforts if not done before
170  if (myEdgeSpeeds.size() == 0) {
171  myAdaptationSteps = oc.getInt("device.rerouting.adaptation-steps");
173  const bool useLoaded = oc.getBool("device.rerouting.init-with-loaded-weights");
174  const double currentSecond = SIMTIME;
175  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
176  while ((*i)->getNumericalID() >= (int)myEdgeSpeeds.size()) {
177  myEdgeSpeeds.push_back(0);
178  if (myAdaptationSteps > 0) {
179  myPastEdgeSpeeds.push_back(std::vector<double>());
180  }
181  }
182  if (useLoaded) {
183  myEdgeSpeeds[(*i)->getNumericalID()] = (*i)->getLength() / MSNet::getTravelTime(*i, 0, currentSecond);
184  } else {
185  myEdgeSpeeds[(*i)->getNumericalID()] = (*i)->getMeanSpeed();
186  }
187  if (myAdaptationSteps > 0) {
188  myPastEdgeSpeeds[(*i)->getNumericalID()] = std::vector<double>(myAdaptationSteps, myEdgeSpeeds[(*i)->getNumericalID()]);
189  }
190  }
192  myRandomizeWeightsFactor = oc.getFloat("weights.random-factor");
193  }
194  // make the weights be updated
195  if (myAdaptationInterval == -1) {
196  myAdaptationInterval = string2time(oc.getString("device.rerouting.adaptation-interval"));
197  myAdaptationWeight = oc.getFloat("device.rerouting.adaptation-weight");
198  if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
201  } else if (period > 0) {
202  WRITE_WARNING("Rerouting is useless if the edge weights do not get updated!");
203  }
204  OutputDevice::createDeviceByOption("device.rerouting.output", "weights", "meandata_file.xsd");
205  }
206  // build the device
207  into.push_back(new MSDevice_Routing(v, "routing_" + v.getID(), period, prePeriod));
208  }
209 }
210 
211 
212 // ---------------------------------------------------------------------------
213 // MSDevice_Routing-methods
214 // ---------------------------------------------------------------------------
215 MSDevice_Routing::MSDevice_Routing(SUMOVehicle& holder, const std::string& id,
216  SUMOTime period, SUMOTime preInsertionPeriod)
217  : MSDevice(holder, id), myPeriod(period), myPreInsertionPeriod(preInsertionPeriod), myLastRouting(-1), mySkipRouting(-1), myRerouteCommand(0) {
219  // 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")
221  // if we don't update the edge weights, we might as well reroute now and hopefully use our threads better
222  const SUMOTime execTime = myEdgeWeightSettingCommand == 0 ? -1 : holder.getParameter().depart;
224  }
225 }
226 
227 
229  // make the rerouting command invalid if there is one
230  if (myRerouteCommand != 0 && MSNet::getInstance()->getInsertionEvents() != 0) {
232  }
233 }
234 
235 
236 bool
239  // clean up pre depart rerouting
240  if (myPreInsertionPeriod > 0) {
242  }
243  myRerouteCommand = 0;
244  // build repetition trigger if routing shall be done more often
245  if (myPeriod > 0) {
248  myRerouteCommand, myPeriod + MSNet::getInstance()->getCurrentTimeStep());
249  }
250  }
251  return false;
252 }
253 
254 
255 SUMOTime
257  if (mySkipRouting == currentTime) {
258  return DELTA_T;
259  }
260  const MSEdge* source = *myHolder.getRoute().begin();
261  const MSEdge* dest = myHolder.getRoute().getLastEdge();
262  if (source->isTazConnector() && dest->isTazConnector()) {
263  const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
264  if (myCachedRoutes.find(key) != myCachedRoutes.end()) {
265  if (myCachedRoutes[key]->size() > 2) {
267  return myPreInsertionPeriod;
268  }
269  }
270  }
271  reroute(currentTime, true);
272  return myPreInsertionPeriod;
273 }
274 
275 
276 SUMOTime
278  reroute(currentTime);
279  return myPeriod;
280 }
281 
282 
283 double
284 MSDevice_Routing::getEffort(const MSEdge* const e, const SUMOVehicle* const v, double) {
285  const int id = e->getNumericalID();
286  if (id < (int)myEdgeSpeeds.size()) {
287  double effort = MAX2(e->getLength() / MAX2(myEdgeSpeeds[id], NUMERICAL_EPS), e->getMinimumTravelTime(v));
288  if (myRandomizeWeightsFactor != 1) {
289  effort *= RandHelper::rand((double)1, myRandomizeWeightsFactor);
290  }
291  return effort;
292  }
293  return 0;
294 }
295 
296 
297 double
299  return edge->getLength() / getEffort(edge, 0, 0);
300 }
301 
302 
303 SUMOTime
305  if (MSNet::getInstance()->getVehicleControl().getDepartedVehicleNo() == 0) {
306  return myAdaptationInterval;
307  }
308  std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*>::iterator it = myCachedRoutes.begin();
309  for (; it != myCachedRoutes.end(); ++it) {
310  it->second->release();
311  }
312  myCachedRoutes.clear();
314  if (myAdaptationSteps > 0) {
315  // moving average
316  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
317  const int id = (*i)->getNumericalID();
318  const double currSpeed = (*i)->getMeanSpeed();
320  myPastEdgeSpeeds[id][myAdaptationStepsIndex] = currSpeed;
321  }
323  } else {
324  // exponential moving average
325  const double newWeightFactor = (double)(1. - myAdaptationWeight);
326  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
327  const int id = (*i)->getNumericalID();
328  const double currSpeed = (*i)->getMeanSpeed();
329  if (currSpeed != myEdgeSpeeds[id]) {
330  myEdgeSpeeds[id] = myEdgeSpeeds[id] * myAdaptationWeight + currSpeed * newWeightFactor;
331  }
332  }
333  }
334  myLastAdaptation = currentTime + DELTA_T; // because we run at the end of the time step
335  if (OptionsCont::getOptions().isSet("device.rerouting.output")) {
336  OutputDevice& dev = OutputDevice::getDeviceByOption("device.rerouting.output");
338  dev.writeAttr(SUMO_ATTR_ID, "device.rerouting");
339  dev.writeAttr(SUMO_ATTR_BEGIN, STEPS2TIME(currentTime));
341  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
342  const int id = (*i)->getNumericalID();
343  dev.openTag(SUMO_TAG_EDGE);
344  dev.writeAttr(SUMO_ATTR_ID, (*i)->getID());
345  dev.writeAttr("traveltime", (*i)->getLength() / myEdgeSpeeds[id]);
346  dev.closeTag();
347  }
348  dev.closeTag();
349  }
350  return myAdaptationInterval;
351 }
352 
353 
354 void
355 MSDevice_Routing::reroute(const SUMOTime currentTime, const bool onInit) {
356  //check whether the weights did change since the last reroute
358  return;
359  }
360  myLastRouting = currentTime;
361 #ifdef HAVE_FOX
362  const bool needThread = (myRouter == 0 && myThreadPool.isFull());
363 #else
364  const bool needThread = true;
365 #endif
366  if (needThread && myRouter == 0) {
368  const std::string routingAlgorithm = oc.getString("routing-algorithm");
369  const bool mayHaveRestrictions = MSNet::getInstance()->hasPermissions() || oc.getInt("remote-port") != 0;
370  if (routingAlgorithm == "dijkstra") {
371  if (mayHaveRestrictions) {
374  } else {
377  }
378  } else if (routingAlgorithm == "astar") {
379  if (mayHaveRestrictions) {
381  const AStar::LookupTable* lookup = 0;
382  if (oc.isSet("astar.all-distances")) {
383  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)MSEdge::getAllEdges().size());
384  } else if (oc.isSet("astar.landmark-distances")) {
385  const double speedFactor = myHolder.getChosenSpeedFactor();
386  // we need an exemplary vehicle with speedFactor 1
391  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), MSEdge::getAllEdges(), &router, &myHolder, "", oc.getInt("device.rerouting.threads"));
392  myHolder.setChosenSpeedFactor(speedFactor);
393  }
394  myRouter = new AStar(MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, lookup);
395  } else {
397  const AStar::LookupTable* lookup = 0;
398  if (oc.isSet("astar.all-distances")) {
399  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)MSEdge::getAllEdges().size());
400  } else if (oc.isSet("astar.landmark-distances")) {
401  const double speedFactor = myHolder.getChosenSpeedFactor();
402  // we need an exemplary vehicle with speedFactor 1
407  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), MSEdge::getAllEdges(), &router, &myHolder, "", oc.getInt("device.rerouting.threads"));
408  myHolder.setChosenSpeedFactor(speedFactor);
409  }
410  myRouter = new AStar(MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, lookup);
411  }
412  } else if (routingAlgorithm == "CH") {
414  if (mayHaveRestrictions) {
416  MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, myHolder.getVClass(), weightPeriod, true);
417  } else {
419  MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, myHolder.getVClass(), weightPeriod, false);
420  }
421  } else if (routingAlgorithm == "CHWrapper") {
425  string2time(oc.getString("begin")), string2time(oc.getString("end")), weightPeriod, oc.getInt("device.rerouting.threads"));
426  } else {
427  throw ProcessError("Unknown routing algorithm '" + routingAlgorithm + "'!");
428  }
429  }
430 #ifdef HAVE_FOX
431  if (needThread) {
432  const int numThreads = OptionsCont::getOptions().getInt("device.rerouting.threads");
433  if (myThreadPool.size() < numThreads) {
434  new WorkerThread(myThreadPool, myRouter);
435  }
436  if (myThreadPool.size() < numThreads) {
437  myRouter = 0;
438  }
439  }
440  if (myThreadPool.size() > 0) {
441  myThreadPool.add(new RoutingTask(myHolder, currentTime, onInit));
442  return;
443  }
444 #endif
445  myHolder.reroute(currentTime, *myRouter, onInit, myWithTaz);
446 }
447 
448 
451  if (myRouterWithProhibited == 0) {
454  }
455  myRouterWithProhibited->prohibit(prohibited);
456  return *myRouterWithProhibited;
457 }
458 
459 
460 std::string
461 MSDevice_Routing::getParameter(const std::string& key) const {
462  if (StringUtils::startsWith(key, "edge:")) {
463  const std::string edgeID = key.substr(5);
464  const MSEdge* edge = MSEdge::dictionary(edgeID);
465  if (edge == 0) {
466  throw InvalidArgument("Edge '" + edgeID + "' is invalid for parameter retrieval of '" + deviceName() + "'");
467  }
468  return toString(getEffort(edge, &myHolder, 0));
469  } else if (key == "period") {
470  return time2string(myPeriod);
471  }
472  throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
473 }
474 
475 
476 void
477 MSDevice_Routing::setParameter(const std::string& key, const std::string& value) {
478  double doubleValue;
479  try {
480  doubleValue = TplConvert::_2double(value.c_str());
481  } catch (NumberFormatException) {
482  throw InvalidArgument("Setting parameter '" + key + "' requires a number for device of type '" + deviceName() + "'");
483  }
484  if (StringUtils::startsWith(key, "edge:")) {
485  const std::string edgeID = key.substr(5);
486  const MSEdge* edge = MSEdge::dictionary(edgeID);
487  if (edge == 0) {
488  throw InvalidArgument("Edge '" + edgeID + "' is invalid for parameter setting of '" + deviceName() + "'");
489  }
490  myEdgeSpeeds[edge->getNumericalID()] = edge->getLength() / doubleValue;
491  } else if (key == "period") {
492  const SUMOTime oldPeriod = myPeriod;
493  myPeriod = TIME2STEPS(doubleValue);
494  if (myPeriod <= 0) {
496  } else if (oldPeriod <= 0) {
497  // re-schedule routing command
499  }
500  } else {
501  throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
502  }
503 }
504 
505 
506 
507 void
509  delete myRouterWithProhibited;
511 #ifdef HAVE_FOX
512  if (myThreadPool.size() > 0) {
513  // we cannot wait for the static destructor to do the cleanup
514  // because the output devices are gone by then
515  myThreadPool.clear();
516  // router deletion is done in thread destructor
517  myRouter = 0;
518  return;
519  }
520 #endif
521  delete myRouter;
522  myRouter = 0;
523 }
524 
525 
526 #ifdef HAVE_FOX
527 void
528 MSDevice_Routing::waitForAll() {
529  if (myThreadPool.size() > 0) {
530  myThreadPool.waitAll();
531  }
532 }
533 
534 
535 // ---------------------------------------------------------------------------
536 // MSDevice_Routing::RoutingTask-methods
537 // ---------------------------------------------------------------------------
538 void
539 MSDevice_Routing::RoutingTask::run(FXWorkerThread* context) {
540  myVehicle.reroute(myTime, static_cast<WorkerThread*>(context)->getRouter(), myOnInit, myWithTaz);
541  const MSEdge* source = *myVehicle.getRoute().begin();
542  const MSEdge* dest = myVehicle.getRoute().getLastEdge();
543  if (source->isTazConnector() && dest->isTazConnector()) {
544  const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
545  lock();
547  MSDevice_Routing::myCachedRoutes[key] = &myVehicle.getRoute();
548  myVehicle.getRoute().addReference();
549  }
550  unlock();
551  }
552 }
553 #endif
554 
555 
556 /****************************************************************************/
557 
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:414
Computes the shortest path through a contracted network.
Definition: CHRouter.h:69
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 ...
double getLength() const
return the length of the edge
Definition: MSEdge.h:570
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:82
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:261
virtual double getChosenSpeedFactor() const =0
virtual bool replaceRoute(const MSRoute *route, bool onInit=false, int offset=0, bool addStops=true)=0
Replaces the current route by the given one.
const int VEHPARS_FORCE_REROUTE
static double myRandomizeWeightsFactor
Whether to disturb edge weights dynamically.
SUMOTime mySkipRouting
The time for which routing may be skipped because we cannot be inserted.
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
bool isTazConnector() const
Definition: MSEdge.h:253
SUMOVehicle & myHolder
The vehicle that stores the device.
Definition: MSDevice.h:187
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:92
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
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:65
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:60
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:85
weights: time range begin
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
SUMOTime myPreInsertionPeriod
The period with which a vehicle shall be rerouted before insertion.
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:169
T MAX2(T a, T b)
Definition: StdDefs.h:74
SUMOTime DELTA_T
Definition: SUMOTime.cpp:40
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:745
SUMOTime wrappedRerouteCommandExecute(SUMOTime currentTime)
Performs rerouting after a period.
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
const std::string deviceName() const
return the name for this type of device
Base (microsim) event class.
Definition: Command.h:61
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:252
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
Computes the shortest path through a network using the Dijkstra algorithm.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
#define SIMTIME
Definition: SUMOTime.h:70
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of edge speeds.
virtual SUMOVehicleClass getVClass() const =0
Returns the vehicle&#39;s access class.
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)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
A road/street connecting two junctions.
Definition: MSEdge.h:81
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
#define max(a, b)
Definition: polyfonts.c:65
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:56
Representation of a vehicle.
Definition: SUMOVehicle.h:67
bool wasSet(int what) const
Returns whether the given parameter was set.
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:152
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:398
virtual void reroute(SUMOTime t, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false)=0
Performs a rerouting using the given router.
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
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:65
A wrapper for a Command function.
Definition: StaticCommand.h:49
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:47
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:97
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
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:408
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
Abstract in-vehicle device.
Definition: MSDevice.h:71
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:111
A pool of worker threads which distributes the tasks and collects the results.
The vehicle has departed (was inserted into the network)
virtual const MSRoute & getRoute() const =0
Returns the current route.
An integer-option.
Definition: Option.h:313
int getNumericalID() const
Returns the numerical id of the edge.
Definition: MSEdge.h:260
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:778
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
weights: time range end
A storage for options typed value containers)
Definition: OptionsCont.h:99
static double _2double(const E *const data)
converts a char-type array into the double value described by it
Definition: TplConvert.h:312
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
MSEventControl * getInsertionEvents()
Returns the event control for insertion events.
Definition: MSNet.h:418
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key ...
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes a new route on vehicle insertion.
void prohibit(const std::vector< E * > &toProhibit)
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;s parameter (including departure definition)
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:71
static void cleanup()
deletes the router instance
static bool checkOptions(OptionsCont &oc)
checks MSDevice_Routing-options
bool closeTag()
Closes the most recently opened tag.
A thread repeatingly calculating incoming tasks.
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:348
long long int SUMOTime
Definition: TraCIDefs.h:52
static AStarRouter< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
#define NUMERICAL_EPS
Definition: config.h:152
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:78
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
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
Definition: MSNet.h:172
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occured.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
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.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:74
SUMOTime preInsertionReroute(const SUMOTime currentTime)
Performs rerouting before insertion into the network.
const MSEdgeVector & getEdges() const
Returns loaded edges.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
Computes the shortest path through a contracted network.