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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // A device that performs vehicle rerouting based on current edge speeds
22 /****************************************************************************/
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include "MSDevice_Routing.h"
34 #include <microsim/MSNet.h>
35 #include <microsim/MSLane.h>
36 #include <microsim/MSEdge.h>
37 #include <microsim/MSEdgeControl.h>
39 #include <microsim/MSGlobals.h>
47 #include <utils/vehicle/CHRouter.h>
49 
50 
51 // ===========================================================================
52 // static member variables
53 // ===========================================================================
54 std::vector<double> MSDevice_Routing::myEdgeSpeeds;
55 std::vector<std::vector<double> > MSDevice_Routing::myPastEdgeSpeeds;
63 std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> MSDevice_Routing::myCachedRoutes;
67 #ifdef HAVE_FOX
68 FXWorkerThread::Pool MSDevice_Routing::myThreadPool;
69 #endif
70 
71 
72 // ===========================================================================
73 // method definitions
74 // ===========================================================================
75 // ---------------------------------------------------------------------------
76 // static initialisation methods
77 // ---------------------------------------------------------------------------
78 void
80  insertDefaultAssignmentOptions("rerouting", "Routing", oc);
81 
82  oc.doRegister("device.rerouting.period", new Option_String("0", "TIME"));
83  oc.addSynonyme("device.rerouting.period", "device.routing.period", true);
84  oc.addDescription("device.rerouting.period", "Routing", "The period with which the vehicle shall be rerouted");
85 
86  oc.doRegister("device.rerouting.pre-period", new Option_String("1", "TIME"));
87  oc.addSynonyme("device.rerouting.pre-period", "device.routing.pre-period", true);
88  oc.addDescription("device.rerouting.pre-period", "Routing", "The rerouting period before depart");
89 
90  oc.doRegister("device.rerouting.adaptation-weight", new Option_Float(.5));
91  oc.addSynonyme("device.rerouting.adaptation-weight", "device.routing.adaptation-weight", true);
92  oc.addDescription("device.rerouting.adaptation-weight", "Routing", "The weight of prior edge weights for exponential moving average");
93 
94  oc.doRegister("device.rerouting.adaptation-steps", new Option_Integer(0));
95  oc.addSynonyme("device.rerouting.adaptation-steps", "device.routing.adaptation-steps", true);
96  oc.addDescription("device.rerouting.adaptation-steps", "Routing", "The number of steps for moving average weight of prior edge weights");
97 
98  oc.doRegister("device.rerouting.adaptation-interval", new Option_String("1", "TIME"));
99  oc.addSynonyme("device.rerouting.adaptation-interval", "device.routing.adaptation-interval", true);
100  oc.addDescription("device.rerouting.adaptation-interval", "Routing", "The interval for updating the edge weights");
101 
102  oc.doRegister("device.rerouting.with-taz", new Option_Bool(false));
103  oc.addSynonyme("device.rerouting.with-taz", "device.routing.with-taz", true);
104  oc.addSynonyme("device.rerouting.with-taz", "with-taz");
105  oc.addDescription("device.rerouting.with-taz", "Routing", "Use zones (districts) as routing start- and endpoints");
106 
107  oc.doRegister("device.rerouting.init-with-loaded-weights", new Option_Bool(false));
108  oc.addDescription("device.rerouting.init-with-loaded-weights", "Routing", "Use weight files given with option --weight-files for initializing edge weights");
109 
110  oc.doRegister("device.rerouting.threads", new Option_Integer(0));
111  oc.addDescription("device.rerouting.threads", "Routing", "The number of parallel execution threads used for rerouting");
112 
113  oc.doRegister("device.rerouting.output", new Option_FileName());
114  oc.addDescription("device.rerouting.output", "Routing", "Save adapting weights to FILE");
115 
117  myEdgeSpeeds.clear();
119  myAdaptationSteps = -1;
120  myLastAdaptation = -1;
121 }
122 
123 
124 bool
126  bool ok = true;
127  if (oc.getInt("device.rerouting.adaptation-steps") > 0 && !oc.isDefault("device.rerouting.adaptation-weight")) {
128  WRITE_ERROR("Only one of the options 'device.rerouting.adaptation-steps' or 'device.rerouting.adaptation-weight' may be given.");
129  ok = false;
130  }
131  if (oc.getFloat("weights.random-factor") < 1) {
132  WRITE_ERROR("weights.random-factor cannot be less than 1");
133  ok = false;
134  }
135  if (string2time(oc.getString("device.rerouting.adaptation-interval")) < 0) {
136  WRITE_ERROR("Negative value for device.rerouting.adaptation-interval!");
137  ok = false;
138  }
139  if (oc.getFloat("device.rerouting.adaptation-weight") < 0. ||
140  oc.getFloat("device.rerouting.adaptation-weight") > 1.) {
141  WRITE_ERROR("The value for device.rerouting.adaptation-weight must be between 0 and 1!");
142  ok = false;
143  }
144 #ifndef HAVE_FOX
145  if (oc.getInt("device.rerouting.threads") > 1) {
146  WRITE_ERROR("Parallel routing is only possible when compiled with Fox.");
147  ok = false;
148  }
149 #endif
150  return ok;
151 }
152 
153 
154 void
155 MSDevice_Routing::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
156  const OptionsCont& oc = OptionsCont::getOptions();
158  // route computation is enabled
159  myWithTaz = oc.getBool("device.rerouting.with-taz");
160  const SUMOTime period = string2time(oc.getString("device.rerouting.period"));
161  const SUMOTime prePeriod = string2time(oc.getString("device.rerouting.pre-period"));
162  // make the weights be updated
163  if (myAdaptationInterval == -1) {
164  myAdaptationInterval = string2time(oc.getString("device.rerouting.adaptation-interval"));
165  myAdaptationWeight = oc.getFloat("device.rerouting.adaptation-weight");
166  if (myAdaptationWeight < 1. && myAdaptationInterval > 0) {
169  } else if (period > 0) {
170  WRITE_WARNING("Rerouting is useless if the edge weights do not get updated!");
171  }
172  OutputDevice::createDeviceByOption("device.rerouting.output", "weights", "meandata_file.xsd");
173  }
174  // build the device
175  into.push_back(new MSDevice_Routing(v, "routing_" + v.getID(), period, prePeriod));
176  }
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 == 0 ? -1 : holder.getParameter().depart;
192  }
193 }
194 
195 
197  // make the rerouting command invalid if there is one
198  if (myRerouteCommand != 0 && MSNet::getInstance()->getInsertionEvents() != 0) {
200  }
201 }
202 
203 
204 bool
207  // clean up pre depart rerouting
208  if (myPreInsertionPeriod > 0) {
210  }
211  myRerouteCommand = 0;
212  // build repetition trigger if routing shall be done more often
213  if (myPeriod > 0) {
216  myRerouteCommand, myPeriod + MSNet::getInstance()->getCurrentTimeStep());
217  }
218  }
219  return false;
220 }
221 
222 
223 void
225  if (myEdgeSpeeds.empty()) {
226  const OptionsCont& oc = OptionsCont::getOptions();
227  myAdaptationSteps = oc.getInt("device.rerouting.adaptation-steps");
228  const bool useLoaded = oc.getBool("device.rerouting.init-with-loaded-weights");
229  const double currentSecond = SIMTIME;
230  for (const MSEdge* const edge : MSNet::getInstance()->getEdgeControl().getEdges()) {
231  while (edge->getNumericalID() >= (int)myEdgeSpeeds.size()) {
232  myEdgeSpeeds.push_back(0);
233  if (myAdaptationSteps > 0) {
234  myPastEdgeSpeeds.push_back(std::vector<double>());
235  }
236  }
237  if (useLoaded) {
238  myEdgeSpeeds[edge->getNumericalID()] = edge->getLength() / MSNet::getTravelTime(edge, 0, currentSecond);
239  } else {
240  myEdgeSpeeds[edge->getNumericalID()] = edge->getMeanSpeed();
241  }
242  if (myAdaptationSteps > 0) {
243  myPastEdgeSpeeds[edge->getNumericalID()] = std::vector<double>(myAdaptationSteps, myEdgeSpeeds[edge->getNumericalID()]);
244  }
245  }
247  myRandomizeWeightsFactor = oc.getFloat("weights.random-factor");
248  }
249 }
250 
251 
252 SUMOTime
254  if (mySkipRouting == currentTime) {
255  return DELTA_T;
256  }
257  const MSEdge* source = *myHolder.getRoute().begin();
258  const MSEdge* dest = myHolder.getRoute().getLastEdge();
259  if (source->isTazConnector() && dest->isTazConnector()) {
260  const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
261  if (myCachedRoutes.find(key) != myCachedRoutes.end()) {
262  if (myCachedRoutes[key]->size() > 2) {
264  return myPreInsertionPeriod;
265  }
266  }
267  }
268  reroute(currentTime, true);
269  return myPreInsertionPeriod;
270 }
271 
272 
273 SUMOTime
275  reroute(currentTime);
276  return myPeriod;
277 }
278 
279 
280 double
281 MSDevice_Routing::getEffort(const MSEdge* const e, const SUMOVehicle* const v, double) {
282  const int id = e->getNumericalID();
283  if (id < (int)myEdgeSpeeds.size()) {
284  double effort = MAX2(e->getLength() / MAX2(myEdgeSpeeds[id], NUMERICAL_EPS), e->getMinimumTravelTime(v));
285  if (myRandomizeWeightsFactor != 1) {
286  effort *= RandHelper::rand((double)1, myRandomizeWeightsFactor);
287  }
288  return effort;
289  }
290  return 0;
291 }
292 
293 
294 double
296  return edge->getLength() / getEffort(edge, 0, 0);
297 }
298 
299 
300 SUMOTime
302  initEdgeWeights();
303  if (MSNet::getInstance()->getVehicleControl().getDepartedVehicleNo() == 0) {
304  return myAdaptationInterval;
305  }
306  std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*>::iterator it = myCachedRoutes.begin();
307  for (; it != myCachedRoutes.end(); ++it) {
308  it->second->release();
309  }
310  myCachedRoutes.clear();
312  if (myAdaptationSteps > 0) {
313  // moving average
314  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
315  const int id = (*i)->getNumericalID();
316  const double currSpeed = (*i)->getMeanSpeed();
318  myPastEdgeSpeeds[id][myAdaptationStepsIndex] = currSpeed;
319  }
321  } else {
322  // exponential moving average
323  const double newWeightFactor = (double)(1. - myAdaptationWeight);
324  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
325  const int id = (*i)->getNumericalID();
326  const double currSpeed = (*i)->getMeanSpeed();
327  if (currSpeed != myEdgeSpeeds[id]) {
328  myEdgeSpeeds[id] = myEdgeSpeeds[id] * myAdaptationWeight + currSpeed * newWeightFactor;
329  }
330  }
331  }
332  myLastAdaptation = currentTime + DELTA_T; // because we run at the end of the time step
333  if (OptionsCont::getOptions().isSet("device.rerouting.output")) {
334  OutputDevice& dev = OutputDevice::getDeviceByOption("device.rerouting.output");
336  dev.writeAttr(SUMO_ATTR_ID, "device.rerouting");
337  dev.writeAttr(SUMO_ATTR_BEGIN, STEPS2TIME(currentTime));
339  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
340  const int id = (*i)->getNumericalID();
341  dev.openTag(SUMO_TAG_EDGE);
342  dev.writeAttr(SUMO_ATTR_ID, (*i)->getID());
343  dev.writeAttr("traveltime", (*i)->getLength() / myEdgeSpeeds[id]);
344  dev.closeTag();
345  }
346  dev.closeTag();
347  }
348  return myAdaptationInterval;
349 }
350 
351 
352 void
353 MSDevice_Routing::reroute(const SUMOTime currentTime, const bool onInit) {
354  initEdgeWeights();
355  //check whether the weights did change since the last reroute
357  return;
358  }
359  myLastRouting = currentTime;
360 #ifdef HAVE_FOX
361  const bool needThread = (myRouter == 0 && myThreadPool.isFull());
362 #else
363  const bool needThread = true;
364 #endif
365  if (needThread && myRouter == 0) {
367  const std::string routingAlgorithm = oc.getString("routing-algorithm");
368  const bool mayHaveRestrictions = MSNet::getInstance()->hasPermissions() || oc.getInt("remote-port") != 0;
369  if (routingAlgorithm == "dijkstra") {
370  if (mayHaveRestrictions) {
373  } else {
376  }
377  } else if (routingAlgorithm == "astar") {
378  if (mayHaveRestrictions) {
380  const AStar::LookupTable* lookup = 0;
381  if (oc.isSet("astar.all-distances")) {
382  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)MSEdge::getAllEdges().size());
383  } else if (oc.isSet("astar.landmark-distances")) {
384  const double speedFactor = myHolder.getChosenSpeedFactor();
385  // we need an exemplary vehicle with speedFactor 1
389  string2time(oc.getString("begin")), string2time(oc.getString("end")), std::numeric_limits<int>::max(), 1);
390  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), MSEdge::getAllEdges(), &router, &myHolder, "", oc.getInt("device.rerouting.threads"));
391  myHolder.setChosenSpeedFactor(speedFactor);
392  }
393  myRouter = new AStar(MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, lookup);
394  } else {
396  const AStar::LookupTable* lookup = 0;
397  if (oc.isSet("astar.all-distances")) {
398  lookup = new AStar::FLT(oc.getString("astar.all-distances"), (int)MSEdge::getAllEdges().size());
399  } else if (oc.isSet("astar.landmark-distances")) {
400  const double speedFactor = myHolder.getChosenSpeedFactor();
401  // we need an exemplary vehicle with speedFactor 1
405  string2time(oc.getString("begin")), string2time(oc.getString("end")), std::numeric_limits<int>::max(), 1);
406  lookup = new AStar::LMLT(oc.getString("astar.landmark-distances"), MSEdge::getAllEdges(), &router, &myHolder, "", oc.getInt("device.rerouting.threads"));
407  myHolder.setChosenSpeedFactor(speedFactor);
408  }
409  myRouter = new AStar(MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, lookup);
410  }
411  } else if (routingAlgorithm == "CH") {
412  const SUMOTime weightPeriod = myAdaptationInterval > 0 ? myAdaptationInterval : std::numeric_limits<int>::max();
413  if (mayHaveRestrictions) {
415  MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, myHolder.getVClass(), weightPeriod, true);
416  } else {
418  MSEdge::getAllEdges(), true, &MSDevice_Routing::getEffort, myHolder.getVClass(), weightPeriod, false);
419  }
420  } else if (routingAlgorithm == "CHWrapper") {
421  const SUMOTime weightPeriod = myAdaptationInterval > 0 ? myAdaptationInterval : std::numeric_limits<int>::max();
424  string2time(oc.getString("begin")), string2time(oc.getString("end")), weightPeriod, oc.getInt("device.rerouting.threads"));
425  } else {
426  throw ProcessError("Unknown routing algorithm '" + routingAlgorithm + "'!");
427  }
428  }
429 #ifdef HAVE_FOX
430  if (needThread) {
431  const int numThreads = OptionsCont::getOptions().getInt("device.rerouting.threads");
432  if (myThreadPool.size() < numThreads) {
433  new WorkerThread(myThreadPool, myRouter);
434  }
435  if (myThreadPool.size() < numThreads) {
436  myRouter = 0;
437  }
438  }
439  if (myThreadPool.size() > 0) {
440  myThreadPool.add(new RoutingTask(myHolder, currentTime, onInit));
441  return;
442  }
443 #endif
444  myHolder.reroute(currentTime, *myRouter, onInit, myWithTaz);
445 }
446 
447 
450  if (myRouterWithProhibited == 0) {
453  }
454  myRouterWithProhibited->prohibit(prohibited);
455  return *myRouterWithProhibited;
456 }
457 
458 
459 std::string
460 MSDevice_Routing::getParameter(const std::string& key) const {
461  if (StringUtils::startsWith(key, "edge:")) {
462  const std::string edgeID = key.substr(5);
463  const MSEdge* edge = MSEdge::dictionary(edgeID);
464  if (edge == 0) {
465  throw InvalidArgument("Edge '" + edgeID + "' is invalid for parameter retrieval of '" + deviceName() + "'");
466  }
467  return toString(getEffort(edge, &myHolder, 0));
468  } else if (key == "period") {
469  return time2string(myPeriod);
470  }
471  throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
472 }
473 
474 
475 void
476 MSDevice_Routing::setParameter(const std::string& key, const std::string& value) {
477  double doubleValue;
478  try {
479  doubleValue = TplConvert::_2double(value.c_str());
480  } catch (NumberFormatException) {
481  throw InvalidArgument("Setting parameter '" + key + "' requires a number for device of type '" + deviceName() + "'");
482  }
483  if (StringUtils::startsWith(key, "edge:")) {
484  const std::string edgeID = key.substr(5);
485  const MSEdge* edge = MSEdge::dictionary(edgeID);
486  if (edge == 0) {
487  throw InvalidArgument("Edge '" + edgeID + "' is invalid for parameter setting of '" + deviceName() + "'");
488  }
489  myEdgeSpeeds[edge->getNumericalID()] = edge->getLength() / doubleValue;
490  } else if (key == "period") {
491  const SUMOTime oldPeriod = myPeriod;
492  myPeriod = TIME2STEPS(doubleValue);
493  if (myPeriod <= 0) {
495  } else if (oldPeriod <= 0) {
496  // re-schedule routing command
498  }
499  } else {
500  throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
501  }
502 }
503 
504 
505 
506 void
508  delete myRouterWithProhibited;
510 #ifdef HAVE_FOX
511  if (myThreadPool.size() > 0) {
512  // we cannot wait for the static destructor to do the cleanup
513  // because the output devices are gone by then
514  myThreadPool.clear();
515  // router deletion is done in thread destructor
516  myRouter = 0;
517  return;
518  }
519 #endif
520  delete myRouter;
521  myRouter = 0;
522 }
523 
524 
525 #ifdef HAVE_FOX
526 void
527 MSDevice_Routing::waitForAll() {
528  if (myThreadPool.size() > 0) {
529  myThreadPool.waitAll();
530  }
531 }
532 
533 
534 // ---------------------------------------------------------------------------
535 // MSDevice_Routing::RoutingTask-methods
536 // ---------------------------------------------------------------------------
537 void
538 MSDevice_Routing::RoutingTask::run(FXWorkerThread* context) {
539  myVehicle.reroute(myTime, static_cast<WorkerThread*>(context)->getRouter(), myOnInit, myWithTaz);
540  const MSEdge* source = *myVehicle.getRoute().begin();
541  const MSEdge* dest = myVehicle.getRoute().getLastEdge();
542  if (source->isTazConnector() && dest->isTazConnector()) {
543  const std::pair<const MSEdge*, const MSEdge*> key = std::make_pair(source, dest);
544  lock();
546  MSDevice_Routing::myCachedRoutes[key] = &myVehicle.getRoute();
547  myVehicle.getRoute().addReference();
548  }
549  unlock();
550  }
551 }
552 #endif
553 
554 
555 /****************************************************************************/
556 
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 ...
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:81
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
void prohibit(const std::vector< E *> &toProhibit)
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:173
SUMOVehicle & myHolder
The vehicle that stores the device.
Definition: MSDevice.h:188
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
virtual bool replaceRoute(const MSRoute *route, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true)=0
Replaces the current route by the given one.
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:64
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:59
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:84
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.
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:167
T MAX2(T a, T b)
Definition: StdDefs.h:73
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
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:744
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:91
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.
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
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:60
double getLength() const
return the length of the edge
Definition: MSEdge.h:569
int getNumericalID() const
Returns the numerical id of the edge.
Definition: MSEdge.h:259
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
#define SIMTIME
Definition: SUMOTime.h:71
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of edge speeds.
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)
A road/street connecting two junctions.
Definition: MSEdge.h:80
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:55
Representation of a vehicle.
Definition: SUMOVehicle.h:66
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:150
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:399
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.
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:413
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:64
A wrapper for a Command function.
Definition: StaticCommand.h:48
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:253
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
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:101
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:409
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
Abstract in-vehicle device.
Definition: MSDevice.h:70
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:115
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:312
bool isTazConnector() const
Definition: MSEdge.h:252
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:777
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:98
static double _2double(const E *const data)
converts a char-type array into the double value described by it
Definition: TplConvert.h:311
MSEventControl * getInsertionEvents()
Returns the event control for insertion events.
Definition: MSNet.h:419
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.
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:70
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:349
long long int SUMOTime
Definition: TraCIDefs.h:51
static AStarRouter< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
#define NUMERICAL_EPS
Definition: config.h:151
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:73
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
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
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occured.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
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.