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  static bool isParallel() {
120  return myThreadPool.size() > 0;
121  }
122 #endif
123 
124 
125 
126 public:
129 
130 
131 
134 
155 
156 
158  void reroute(const SUMOTime currentTime, const bool onInit = false);
159 
160 
169  void skipRouting(const SUMOTime currentTime) {
170  mySkipRouting = currentTime;
171  }
172 
173 
174 private:
175 #ifdef HAVE_FOX
176 
180  class WorkerThread : public FXWorkerThread {
181  public:
182  WorkerThread(FXWorkerThread::Pool& pool,
184  : FXWorkerThread(pool), myRouter(router) {}
185  SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter() const {
186  return *myRouter;
187  }
188  virtual ~WorkerThread() {
189  stop();
190  delete myRouter;
191  }
192  private:
194  };
195 
200  class RoutingTask : public FXWorkerThread::Task {
201  public:
202  RoutingTask(SUMOVehicle& v, const SUMOTime time, const bool onInit)
203  : myVehicle(v), myTime(time), myOnInit(onInit) {}
204  void run(FXWorkerThread* context);
205  private:
206  SUMOVehicle& myVehicle;
207  const SUMOTime myTime;
208  const bool myOnInit;
209  private:
211  RoutingTask& operator=(const RoutingTask&);
212  };
213 #endif
214 
222  MSDevice_Routing(SUMOVehicle& holder, const std::string& id, SUMOTime period, SUMOTime preInsertionPeriod);
223 
224 
236  SUMOTime preInsertionReroute(const SUMOTime currentTime);
237 
253 
254 
269  static SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
270 
271 
272 
275 
287  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
289 
290 
291 private:
294 
297 
300 
303 
306 
309 
311  static std::vector<SUMOReal> myEdgeEfforts;
312 
315 
318 
321 
323  static bool myWithTaz;
324 
326  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
327 
330 
333 
334 #ifdef HAVE_FOX
335  static FXWorkerThread::Pool myThreadPool;
336 #endif
337 
338 private:
341 
344 
345 
346 };
347 
348 
349 #endif
350 
351 /****************************************************************************/
352 
SUMOTime myPeriod
The period with which a vehicle shall be rerouted.
long long int SUMOTime
Definition: SUMOTime.h:43
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
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:214
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.