SUMO - Simulation of Urban MObility
MSDevice_Routing.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2007-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A device that performs vehicle rerouting based on current edge speeds
18 /****************************************************************************/
19 #ifndef MSDevice_Routing_h
20 #define MSDevice_Routing_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <set>
29 #include <vector>
30 #include <map>
31 #include <utils/common/SUMOTime.h>
35 #include <microsim/MSVehicle.h>
36 #include "MSDevice.h"
37 
38 #ifdef HAVE_FOX
40 #endif
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class MSLane;
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
69 class MSDevice_Routing : public MSDevice {
70 public:
74  static void insertOptions(OptionsCont& oc);
75 
79  static bool checkOptions(OptionsCont& oc);
80 
81 
99  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
100 
101 
103  static void cleanup();
104 
106  static bool isEnabled() {
107  return !myWithTaz && myAdaptationInterval >= 0;
108  }
109 
112  const MSEdgeVector& prohibited = MSEdgeVector());
113 
114 #ifdef HAVE_FOX
115  static void waitForAll();
116  static void lock() {
117  myThreadPool.lock();
118  }
119  static void unlock() {
120  myThreadPool.unlock();
121  }
122  static bool isParallel() {
123  return myThreadPool.size() > 0;
124  }
125 #endif
126 
127 
128 
129 public:
132 
133 
134 
137 
156  bool notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
158 
160  const std::string deviceName() const {
161  return "rerouting";
162  }
163 
168  void saveState(OutputDevice& out) const;
169 
174  void loadState(const SUMOSAXAttributes& attrs);
175 
177  void reroute(const SUMOTime currentTime, const bool onInit = false);
178 
179 
188  void skipRouting(const SUMOTime currentTime) {
189  mySkipRouting = currentTime;
190  }
191 
193  static double getAssumedSpeed(const MSEdge* edge);
194 
196  std::string getParameter(const std::string& key) const;
197 
199  void setParameter(const std::string& key, const std::string& value);
200 
201 
202 private:
203 #ifdef HAVE_FOX
204 
208  class WorkerThread : public FXWorkerThread {
209  public:
210  WorkerThread(FXWorkerThread::Pool& pool,
212  : FXWorkerThread(pool), myRouter(router) {}
213  SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter() const {
214  return *myRouter;
215  }
216  virtual ~WorkerThread() {
217  stop();
218  delete myRouter;
219  }
220  private:
222  };
223 
228  class RoutingTask : public FXWorkerThread::Task {
229  public:
230  RoutingTask(SUMOVehicle& v, const SUMOTime time, const bool onInit)
231  : myVehicle(v), myTime(time), myOnInit(onInit) {}
232  void run(FXWorkerThread* context);
233  private:
234  SUMOVehicle& myVehicle;
235  const SUMOTime myTime;
236  const bool myOnInit;
237  private:
239  RoutingTask& operator=(const RoutingTask&);
240  };
241 #endif
242 
250  MSDevice_Routing(SUMOVehicle& holder, const std::string& id, SUMOTime period, SUMOTime preInsertionPeriod);
251 
253  static void initEdgeWeights();
254 
256  static void initWeightUpdate();
257 
269  SUMOTime preInsertionReroute(const SUMOTime currentTime);
270 
286 
287 
302  static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
303 
304 
305 
308 
320  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
322 
323 
324 private:
327 
330 
333 
336 
339 
342 
344  static std::vector<double> myEdgeSpeeds;
345 
347  static double myAdaptationWeight;
348 
351 
354 
356  static int myAdaptationSteps;
357 
360 
362  static std::vector<std::vector<double> > myPastEdgeSpeeds;
363 
365  static bool myWithTaz;
366 
368  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
369 
372 
375 
378 
379 #ifdef HAVE_FOX
380  static FXWorkerThread::Pool myThreadPool;
381 #endif
382 
383 private:
386 
389 
390 
391 };
392 
393 
394 #endif
395 
396 /****************************************************************************/
397 
SUMOTime myPeriod
The period with which a vehicle shall be rerouted.
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key ...
long long int SUMOTime
Definition: SUMOTime.h:36
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:77
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)
void saveState(OutputDevice &out) const
Saves the state of the device.
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:54
static AStarRouter< MSEdge, SUMOVehicle, SUMOAbstractRouterPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
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:75
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:60
Encapsulated SAX-Attributes.
static void initEdgeWeights()
initialize the edge weights if not done before
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
static void initWeightUpdate()
intialize period edge weight update
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:65
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:92
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.
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
~MSDevice_Routing()
Destructor.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
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.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:71
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 occurred.
Representation of a lane in the micro simulation.
Definition: MSLane.h:71
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key ...
SUMOTime preInsertionReroute(const SUMOTime currentTime)
Performs rerouting before insertion into the network.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.