SUMO - Simulation of Urban MObility
MSDevice_Routing.h
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 /****************************************************************************/
19 // A device that performs vehicle rerouting based on current edge speeds
20 /****************************************************************************/
21 #ifndef MSDevice_Routing_h
22 #define MSDevice_Routing_h
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 <set>
35 #include <vector>
36 #include <map>
37 #include <utils/common/SUMOTime.h>
41 #include <microsim/MSVehicle.h>
42 #include "MSDevice.h"
43 
44 #ifdef HAVE_FOX
46 #endif
47 
48 
49 // ===========================================================================
50 // class declarations
51 // ===========================================================================
52 class MSLane;
53 
54 // ===========================================================================
55 // class definitions
56 // ===========================================================================
75 class MSDevice_Routing : public MSDevice {
76 public:
80  static void insertOptions(OptionsCont& oc);
81 
85  static bool checkOptions(OptionsCont& oc);
86 
87 
105  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
106 
107 
109  static void cleanup();
110 
112  static bool isEnabled() {
113  return !myWithTaz && myAdaptationInterval >= 0;
114  }
115 
118  const MSEdgeVector& prohibited = MSEdgeVector());
119 
120 #ifdef HAVE_FOX
121  static void waitForAll();
122  static void lock() {
123  myThreadPool.lock();
124  }
125  static void unlock() {
126  myThreadPool.unlock();
127  }
128  static bool isParallel() {
129  return myThreadPool.size() > 0;
130  }
131 #endif
132 
133 
134 
135 public:
138 
139 
140 
143 
162  bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
164 
166  const std::string deviceName() const {
167  return "rerouting";
168  }
169 
170 
172  void reroute(const SUMOTime currentTime, const bool onInit = false);
173 
174 
183  void skipRouting(const SUMOTime currentTime) {
184  mySkipRouting = currentTime;
185  }
186 
188  static double getAssumedSpeed(const MSEdge* edge);
189 
191  std::string getParameter(const std::string& key) const;
192 
194  void setParameter(const std::string& key, const std::string& value);
195 
196 
197 private:
198 #ifdef HAVE_FOX
199 
203  class WorkerThread : public FXWorkerThread {
204  public:
205  WorkerThread(FXWorkerThread::Pool& pool,
207  : FXWorkerThread(pool), myRouter(router) {}
208  SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter() const {
209  return *myRouter;
210  }
211  virtual ~WorkerThread() {
212  stop();
213  delete myRouter;
214  }
215  private:
217  };
218 
223  class RoutingTask : public FXWorkerThread::Task {
224  public:
225  RoutingTask(SUMOVehicle& v, const SUMOTime time, const bool onInit)
226  : myVehicle(v), myTime(time), myOnInit(onInit) {}
227  void run(FXWorkerThread* context);
228  private:
229  SUMOVehicle& myVehicle;
230  const SUMOTime myTime;
231  const bool myOnInit;
232  private:
234  RoutingTask& operator=(const RoutingTask&);
235  };
236 #endif
237 
245  MSDevice_Routing(SUMOVehicle& holder, const std::string& id, SUMOTime period, SUMOTime preInsertionPeriod);
246 
248  static void initEdgeWeights();
249 
261  SUMOTime preInsertionReroute(const SUMOTime currentTime);
262 
278 
279 
294  static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
295 
296 
297 
300 
312  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
314 
315 
316 private:
319 
322 
325 
328 
331 
334 
336  static std::vector<double> myEdgeSpeeds;
337 
339  static double myAdaptationWeight;
340 
343 
346 
348  static int myAdaptationSteps;
349 
352 
354  static std::vector<std::vector<double> > myPastEdgeSpeeds;
355 
357  static bool myWithTaz;
358 
360  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
361 
364 
367 
370 
371 #ifdef HAVE_FOX
372  static FXWorkerThread::Pool myThreadPool;
373 #endif
374 
375 private:
378 
381 
382 
383 };
384 
385 
386 #endif
387 
388 /****************************************************************************/
389 
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:84
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)
SUMOTime wrappedRerouteCommandExecute(SUMOTime currentTime)
Performs rerouting after a period.
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
void skipRouting(const SUMOTime currentTime)
Labels the current time step as "unroutable".
Base (microsim) event class.
Definition: Command.h:60
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:80
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:66
static void initEdgeWeights()
initialize the edge weights if not done before
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:70
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:98
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.
~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:51
static AStarRouter< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
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
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
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.