SUMO - Simulation of Urban MObility
MSRoutingEngine.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 MSRoutingEngine_h
20 #define MSRoutingEngine_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 definitions
45 // ===========================================================================
65 public:
67  static void initWeightUpdate();
68 
70  static void initEdgeWeights();
71 
73  static bool hasEdgeUpdates() {
74  return myEdgeWeightSettingCommand != nullptr;
75  }
76 
79  return myLastAdaptation;
80  }
81 
83  static const MSRoute* getCachedRoute(const std::pair<const MSEdge*, const MSEdge*>& key);
84 
86  static void reroute(SUMOVehicle& vehicle, const SUMOTime currentTime, const bool onInit);
87 
89  static void setEdgeTravelTime(const MSEdge* const edge, const double travelTime);
90 
92  static void cleanup();
93 
95  static bool isEnabled() {
96  return !myWithTaz && myAdaptationInterval >= 0;
97  }
98 
101  const MSEdgeVector& prohibited = MSEdgeVector());
102 
117  static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
118 
120  static double getAssumedSpeed(const MSEdge* edge);
121 
122 #ifdef HAVE_FOX
123  static void waitForAll();
124  static void lock() {
125  myThreadPool.lock();
126  }
127  static void unlock() {
128  myThreadPool.unlock();
129  }
130  static bool isParallel() {
131  return myThreadPool.size() > 0;
132  }
133 #endif
134 
135 
136 private:
137 #ifdef HAVE_FOX
138 
142  class WorkerThread : public FXWorkerThread {
143  public:
144  WorkerThread(FXWorkerThread::Pool& pool,
146  : FXWorkerThread(pool), myRouter(router) {}
147  SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter() const {
148  return *myRouter;
149  }
150  virtual ~WorkerThread() {
151  stop();
152  delete myRouter;
153  }
154  private:
156  };
157 
162  class RoutingTask : public FXWorkerThread::Task {
163  public:
164  RoutingTask(SUMOVehicle& v, const SUMOTime time, const bool onInit)
165  : myVehicle(v), myTime(time), myOnInit(onInit) {}
166  void run(FXWorkerThread* context);
167  private:
168  SUMOVehicle& myVehicle;
169  const SUMOTime myTime;
170  const bool myOnInit;
171  private:
173  RoutingTask& operator=(const RoutingTask&);
174  };
175 #endif
176 
179 
191  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
193 
194 
195 private:
198 
200  static std::vector<double> myEdgeSpeeds;
201 
203  static double myAdaptationWeight;
204 
207 
210 
212  static int myAdaptationSteps;
213 
216 
218  static std::vector<std::vector<double> > myPastEdgeSpeeds;
219 
221  static bool myWithTaz;
222 
225 
228 
231 
233  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
234 
235 #ifdef HAVE_FOX
236  static FXWorkerThread::Pool myThreadPool;
237 #endif
238 
239 private:
242 
245 
246 
247 };
248 
249 
250 #endif
251 
252 /****************************************************************************/
253 
static void setEdgeTravelTime(const MSEdge *const edge, const double travelTime)
adapt the known travel time for an edge
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
long long int SUMOTime
Definition: SUMOTime.h:36
static int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
static AStarRouter< MSEdge, SUMOVehicle, SUMOAbstractRouterPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
static void initWeightUpdate()
intialize period edge weight update
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:78
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
Base (microsim) event class.
Definition: Command.h:54
static void initEdgeWeights()
initialize the edge weights if not done before
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
A road/street connecting two junctions.
Definition: MSEdge.h:75
static bool hasEdgeUpdates()
returns whether any routing actions take place
static const MSRoute * getCachedRoute(const std::pair< const MSEdge *, const MSEdge *> &key)
return the cached route or nullptr on miss
Representation of a vehicle.
Definition: SUMOVehicle.h:60
static double myAdaptationWeight
Information which weight prior edge efforts have.
static void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const bool onInit)
initiate the rerouting, create router / thread pool on first use
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of edge speeds.
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
static SUMOTime getLastAdaptation()
Information when the last edge weight adaptation occurred.
static double myRandomizeWeightsFactor
Whether to disturb edge weights dynamically.
MSRoutingEngine & operator=(const MSRoutingEngine &)
Invalidated assignment operator.
static std::vector< double > myEdgeSpeeds
The container of edge speeds.
A pool of worker threads which distributes the tasks and collects the results.
MSRoutingEngine(const MSRoutingEngine &)
Invalidated copy constructor.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouter
The router to use.
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
static double getAssumedSpeed(const MSEdge *edge)
return current travel speed assumption
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
static bool myWithTaz
whether taz shall be used at initial rerouting
A device that performs vehicle rerouting based on current edge speeds.
Abstract superclass of a task to be run with an index to keep track of pending tasks.
A thread repeatingly calculating incoming tasks.
static void cleanup()
deletes the router instance
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:71
static bool isEnabled()
returns whether any routing actions take place