SUMO - Simulation of Urban MObility
MSDevice_Routing.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // A device that performs vehicle rerouting based on current edge speeds
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2007-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef MSDevice_Routing_h
23 #define MSDevice_Routing_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <set>
36 #include <vector>
37 #include <map>
38 #include <utils/common/SUMOTime.h>
42 #include <microsim/MSVehicle.h>
43 #include "MSDevice.h"
44 
45 #ifdef HAVE_FOX
47 #endif
48 
49 
50 // ===========================================================================
51 // class declarations
52 // ===========================================================================
53 class MSLane;
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
76 class MSDevice_Routing : public MSDevice {
77 public:
81  static void insertOptions(OptionsCont& oc);
82 
86  static bool checkOptions(OptionsCont& oc);
87 
88 
106  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
107 
108 
110  static void cleanup();
111 
113  static bool isEnabled() {
114  return !myWithTaz && !myEdgeSpeeds.empty();
115  }
116 
119  const MSEdgeVector& prohibited = MSEdgeVector());
120 
121 #ifdef HAVE_FOX
122  static void waitForAll();
123  static void lock() {
124  myThreadPool.lock();
125  }
126  static void unlock() {
127  myThreadPool.unlock();
128  }
129  static bool isParallel() {
130  return myThreadPool.size() > 0;
131  }
132 #endif
133 
134 
135 
136 public:
139 
140 
141 
144 
163  bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
165 
167  const std::string deviceName() const {
168  return "rerouting";
169  }
170 
171 
173  void reroute(const SUMOTime currentTime, const bool onInit = false);
174 
175 
184  void skipRouting(const SUMOTime currentTime) {
185  mySkipRouting = currentTime;
186  }
187 
189  static double getAssumedSpeed(const MSEdge* edge);
190 
192  std::string getParameter(const std::string& key) const;
193 
195  void setParameter(const std::string& key, const std::string& value);
196 
197 
198 private:
199 #ifdef HAVE_FOX
200 
204  class WorkerThread : public FXWorkerThread {
205  public:
206  WorkerThread(FXWorkerThread::Pool& pool,
208  : FXWorkerThread(pool), myRouter(router) {}
209  SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter() const {
210  return *myRouter;
211  }
212  virtual ~WorkerThread() {
213  stop();
214  delete myRouter;
215  }
216  private:
218  };
219 
224  class RoutingTask : public FXWorkerThread::Task {
225  public:
226  RoutingTask(SUMOVehicle& v, const SUMOTime time, const bool onInit)
227  : myVehicle(v), myTime(time), myOnInit(onInit) {}
228  void run(FXWorkerThread* context);
229  private:
230  SUMOVehicle& myVehicle;
231  const SUMOTime myTime;
232  const bool myOnInit;
233  private:
235  RoutingTask& operator=(const RoutingTask&);
236  };
237 #endif
238 
246  MSDevice_Routing(SUMOVehicle& holder, const std::string& id, SUMOTime period, SUMOTime preInsertionPeriod);
247 
248 
260  SUMOTime preInsertionReroute(const SUMOTime currentTime);
261 
277 
278 
293  static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
294 
295 
296 
299 
311  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
313 
314 
315 private:
318 
321 
324 
327 
330 
333 
335  static std::vector<double> myEdgeSpeeds;
336 
338  static double myAdaptationWeight;
339 
342 
345 
347  static int myAdaptationSteps;
348 
351 
353  static std::vector<std::vector<double> > myPastEdgeSpeeds;
354 
356  static bool myWithTaz;
357 
359  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
360 
363 
366 
369 
370 #ifdef HAVE_FOX
371  static FXWorkerThread::Pool myThreadPool;
372 #endif
373 
374 private:
377 
380 
381 
382 };
383 
384 
385 #endif
386 
387 /****************************************************************************/
388 
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 ...
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.
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
SUMOTime myLastRouting
The last time a routing took place.
MSDevice_Routing(SUMOVehicle &holder, const std::string &id, SUMOTime period, SUMOTime preInsertionPeriod)
Constructor.
Notification
Definition of a vehicle state.
A device that performs vehicle rerouting based on current edge speeds.
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:85
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)
SUMOTime wrappedRerouteCommandExecute(SUMOTime currentTime)
Performs rerouting after a period.
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
const std::string deviceName() const
return the name for this type of device
void skipRouting(const SUMOTime currentTime)
Labels the current time step as "unroutable".
Base (microsim) event class.
Definition: Command.h:61
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of edge speeds.
static double myAdaptationWeight
Information which weight prior edge efforts have.
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
Representation of a vehicle.
Definition: SUMOVehicle.h:67
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
MSDevice_Routing & operator=(const MSDevice_Routing &)
Invalidated assignment operator.
static std::vector< double > myEdgeSpeeds
The container of edge speeds.
WrappingCommand< MSDevice_Routing > * myRerouteCommand
The (optional) command responsible for rerouting.
static bool isEnabled()
returns whether any routing actions take place
Abstract in-vehicle device.
Definition: MSDevice.h:71
A pool of worker threads which distributes the tasks and collects the results.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouter
The router to use.
A storage for options typed value containers)
Definition: OptionsCont.h:99
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.
~MSDevice_Routing()
Destructor.
static void cleanup()
deletes the router instance
static bool checkOptions(OptionsCont &oc)
checks MSDevice_Routing-options
Abstract superclass of a task to be run with an index to keep track of pending tasks.
A thread repeatingly calculating incoming tasks.
long long int SUMOTime
Definition: TraCIDefs.h:52
static AStarRouter< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:78
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:79
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
SUMOTime preInsertionReroute(const SUMOTime currentTime)
Performs rerouting before insertion into the network.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.