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-2015 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>
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 
82 
100  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
101 
102 
104  static void cleanup();
105 
107  static bool isEnabled() {
108  return !myWithTaz && !myEdgeEfforts.empty();
109  }
110 
111 #ifdef HAVE_FOX
112  static void waitForAll();
113  static void lock() {
114  myThreadPool.lock();
115  }
116  static void unlock() {
117  myThreadPool.unlock();
118  }
119 #endif
120 
121 
122 
123 public:
126 
127 
128 
131 
152 
153 
155  void reroute(const SUMOTime currentTime, const bool onInit = false);
156 
157 
166  void skipRouting(const SUMOTime currentTime) {
167  mySkipRouting = currentTime;
168  }
169 
170 
171 private:
172 #ifdef HAVE_FOX
173 
177  class WorkerThread : public FXWorkerThread {
178  public:
179  WorkerThread(FXWorkerThread::Pool& pool,
181  : FXWorkerThread(pool), myRouter(router) {}
182  SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter() const {
183  return *myRouter;
184  }
185  virtual ~WorkerThread() {
186  stop();
187  delete myRouter;
188  }
189  private:
191  };
192 
197  class RoutingTask : public FXWorkerThread::Task {
198  public:
199  RoutingTask(SUMOVehicle& v, const SUMOTime time, const bool onInit)
200  : myVehicle(v), myTime(time), myOnInit(onInit) {}
201  void run(FXWorkerThread* context);
202  private:
203  SUMOVehicle& myVehicle;
204  const SUMOTime myTime;
205  const bool myOnInit;
206  private:
208  RoutingTask& operator=(const RoutingTask&);
209  };
210 #endif
211 
219  MSDevice_Routing(SUMOVehicle& holder, const std::string& id, SUMOTime period, SUMOTime preInsertionPeriod);
220 
221 
233  SUMOTime preInsertionReroute(const SUMOTime currentTime);
234 
250 
251 
266  static SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
267 
268 
269 
272 
284  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
286 
287 
288 private:
291 
294 
297 
300 
303 
306 
308  static std::vector<SUMOReal> myEdgeEfforts;
309 
312 
315 
318 
320  static bool myWithTaz;
321 
323  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
324 
327 
330 
331 #ifdef HAVE_FOX
332  static FXWorkerThread::Pool myThreadPool;
333 #endif
334 
335 private:
338 
341 
342 
343 };
344 
345 
346 #endif
347 
348 /****************************************************************************/
349 
SUMOTime myPeriod
The period with which a vehicle shall be rerouted.
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.
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.
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
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:65
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.
WrappingCommand< MSDevice_Routing > * myRerouteCommand
The (optional) command responsible for rerouting.
static bool isEnabled()
returns whether any routing actions take place
static SUMOReal getEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the effort to pass an edge.
Abstract in-vehicle device.
Definition: MSDevice.h:69
A pool of worker threads which distributes the tasks and collects the results.
static std::vector< SUMOReal > myEdgeEfforts
The container of edge efforts.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouter
The router to use.
A storage for options typed value containers)
Definition: OptionsCont.h:108
int SUMOTime
Definition: SUMOTime.h:43
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Computes a new route on vehicle insertion.
~MSDevice_Routing()
Destructor.
static void cleanup()
deletes the router instance
#define SUMOReal
Definition: config.h:218
Abstract superclass of a task to be run with an index to keep track of pending tasks.
A thread repeatingly calculating incoming tasks.
static SUMOReal myAdaptationWeight
Information which weight prior edge efforts have.
static SUMOReal myRandomizeWeightsFactor
Whether to disturb edge weights dynamically.
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occured.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
SUMOTime preInsertionReroute(const SUMOTime currentTime)
Performs rerouting before insertion into the network.