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 
191 
192 private:
193 #ifdef HAVE_FOX
194 
198  class WorkerThread : public FXWorkerThread {
199  public:
200  WorkerThread(FXWorkerThread::Pool& pool,
202  : FXWorkerThread(pool), myRouter(router) {}
203  SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter() const {
204  return *myRouter;
205  }
206  virtual ~WorkerThread() {
207  stop();
208  delete myRouter;
209  }
210  private:
212  };
213 
218  class RoutingTask : public FXWorkerThread::Task {
219  public:
220  RoutingTask(SUMOVehicle& v, const SUMOTime time, const bool onInit)
221  : myVehicle(v), myTime(time), myOnInit(onInit) {}
222  void run(FXWorkerThread* context);
223  private:
224  SUMOVehicle& myVehicle;
225  const SUMOTime myTime;
226  const bool myOnInit;
227  private:
229  RoutingTask& operator=(const RoutingTask&);
230  };
231 #endif
232 
240  MSDevice_Routing(SUMOVehicle& holder, const std::string& id, SUMOTime period, SUMOTime preInsertionPeriod);
241 
242 
254  SUMOTime preInsertionReroute(const SUMOTime currentTime);
255 
271 
272 
287  static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
288 
289 
290 
293 
305  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
307 
308 
309 private:
312 
315 
318 
321 
324 
327 
329  static std::vector<double> myEdgeSpeeds;
330 
332  static double myAdaptationWeight;
333 
336 
339 
341  static int myAdaptationSteps;
342 
345 
347  static std::vector<std::vector<double> > myPastEdgeSpeeds;
348 
350  static bool myWithTaz;
351 
353  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
354 
357 
360 
363 
364 #ifdef HAVE_FOX
365  static FXWorkerThread::Pool myThreadPool;
366 #endif
367 
368 private:
371 
374 
375 
376 };
377 
378 
379 #endif
380 
381 /****************************************************************************/
382 
SUMOTime myPeriod
The period with which a vehicle shall be rerouted.
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:74
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: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: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: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
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:52
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: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.