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-2016 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 
165 
166 
168  void reroute(const SUMOTime currentTime, const bool onInit = false);
169 
170 
179  void skipRouting(const SUMOTime currentTime) {
180  mySkipRouting = currentTime;
181  }
182 
184  static SUMOReal getAssumedSpeed(const MSEdge* edge);
185 
186 
187 private:
188 #ifdef HAVE_FOX
189 
193  class WorkerThread : public FXWorkerThread {
194  public:
195  WorkerThread(FXWorkerThread::Pool& pool,
197  : FXWorkerThread(pool), myRouter(router) {}
198  SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter() const {
199  return *myRouter;
200  }
201  virtual ~WorkerThread() {
202  stop();
203  delete myRouter;
204  }
205  private:
207  };
208 
213  class RoutingTask : public FXWorkerThread::Task {
214  public:
215  RoutingTask(SUMOVehicle& v, const SUMOTime time, const bool onInit)
216  : myVehicle(v), myTime(time), myOnInit(onInit) {}
217  void run(FXWorkerThread* context);
218  private:
219  SUMOVehicle& myVehicle;
220  const SUMOTime myTime;
221  const bool myOnInit;
222  private:
224  RoutingTask& operator=(const RoutingTask&);
225  };
226 #endif
227 
235  MSDevice_Routing(SUMOVehicle& holder, const std::string& id, SUMOTime period, SUMOTime preInsertionPeriod);
236 
237 
249  SUMOTime preInsertionReroute(const SUMOTime currentTime);
250 
266 
267 
282  static SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
283 
284 
285 
288 
300  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
302 
303 
304 private:
307 
310 
313 
316 
319 
322 
324  static std::vector<SUMOReal> myEdgeSpeeds;
325 
328 
331 
334 
336  static int myAdaptationSteps;
337 
340 
342  static std::vector<std::vector<SUMOReal> > myPastEdgeSpeeds;
343 
345  static bool myWithTaz;
346 
348  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
349 
352 
355 
358 
359 #ifdef HAVE_FOX
360  static FXWorkerThread::Pool myThreadPool;
361 #endif
362 
363 private:
366 
369 
370 
371 };
372 
373 
374 #endif
375 
376 /****************************************************************************/
377 
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.
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:71
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.
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: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 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
static SUMOReal getAssumedSpeed(const MSEdge *edge)
return current travel speed assumption
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 std::vector< SUMOReal > myEdgeSpeeds
The container of edge speeds.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
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
#define SUMOReal
Definition: config.h:213
Abstract superclass of a task to be run with an index to keep track of pending tasks.
A thread repeatingly calculating incoming tasks.
static AStarRouter< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
static SUMOReal myAdaptationWeight
Information which weight prior edge efforts have.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
static SUMOReal myRandomizeWeightsFactor
Whether to disturb edge weights dynamically.
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 std::vector< std::vector< SUMOReal > > myPastEdgeSpeeds
The container of edge speeds.
SUMOTime preInsertionReroute(const SUMOTime currentTime)
Performs rerouting before insertion into the network.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.