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 
83 
101  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
102 
103 
105  static void cleanup();
106 
108  static bool isEnabled() {
109  return !myWithTaz && !myEdgeEfforts.empty();
110  }
111 
114  const MSEdgeVector& prohibited = MSEdgeVector());
115 
116 #ifdef HAVE_FOX
117  static void waitForAll();
118  static void lock() {
119  myThreadPool.lock();
120  }
121  static void unlock() {
122  myThreadPool.unlock();
123  }
124  static bool isParallel() {
125  return myThreadPool.size() > 0;
126  }
127 #endif
128 
129 
130 
131 public:
134 
135 
136 
139 
160 
161 
163  void reroute(const SUMOTime currentTime, const bool onInit = false);
164 
165 
174  void skipRouting(const SUMOTime currentTime) {
175  mySkipRouting = currentTime;
176  }
177 
179  static SUMOReal getAssumedSpeed(const MSEdge* edge);
180 
181 
182 private:
183 #ifdef HAVE_FOX
184 
188  class WorkerThread : public FXWorkerThread {
189  public:
190  WorkerThread(FXWorkerThread::Pool& pool,
192  : FXWorkerThread(pool), myRouter(router) {}
193  SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter() const {
194  return *myRouter;
195  }
196  virtual ~WorkerThread() {
197  stop();
198  delete myRouter;
199  }
200  private:
202  };
203 
208  class RoutingTask : public FXWorkerThread::Task {
209  public:
210  RoutingTask(SUMOVehicle& v, const SUMOTime time, const bool onInit)
211  : myVehicle(v), myTime(time), myOnInit(onInit) {}
212  void run(FXWorkerThread* context);
213  private:
214  SUMOVehicle& myVehicle;
215  const SUMOTime myTime;
216  const bool myOnInit;
217  private:
219  RoutingTask& operator=(const RoutingTask&);
220  };
221 #endif
222 
230  MSDevice_Routing(SUMOVehicle& holder, const std::string& id, SUMOTime period, SUMOTime preInsertionPeriod);
231 
232 
244  SUMOTime preInsertionReroute(const SUMOTime currentTime);
245 
261 
262 
277  static SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
278 
279 
280 
283 
295  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
297 
298 
299 private:
302 
305 
308 
311 
314 
317 
319  static std::vector<SUMOReal> myEdgeEfforts;
320 
323 
326 
329 
331  static bool myWithTaz;
332 
334  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
335 
338 
341 
344 
345 #ifdef HAVE_FOX
346  static FXWorkerThread::Pool myThreadPool;
347 #endif
348 
349 private:
352 
355 
356 
357 };
358 
359 
360 #endif
361 
362 /****************************************************************************/
363 
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.
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: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
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 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: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:77
SUMOTime preInsertionReroute(const SUMOTime currentTime)
Performs rerouting before insertion into the network.