Eclipse 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-2019 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  static double getEffortExtra(const MSEdge* const e, const SUMOVehicle* const v, double t);
120 
122  static double getAssumedSpeed(const MSEdge* edge);
123 
124 #ifdef HAVE_FOX
125  static void waitForAll();
126  static void lock() {
127  myThreadPool.lock();
128  }
129  static void unlock() {
130  myThreadPool.unlock();
131  }
132  static bool isParallel() {
133  return myThreadPool.size() > 0;
134  }
135 #endif
136 
137 
138 private:
139 #ifdef HAVE_FOX
140 
144  class WorkerThread : public FXWorkerThread {
145  public:
146  WorkerThread(FXWorkerThread::Pool& pool,
148  : FXWorkerThread(pool), myRouter(router) {}
149  SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter() const {
150  return *myRouter;
151  }
152  virtual ~WorkerThread() {
153  stop();
154  delete myRouter;
155  }
156  private:
158  };
159 
164  class RoutingTask : public FXWorkerThread::Task {
165  public:
166  RoutingTask(SUMOVehicle& v, const SUMOTime time, const bool onInit)
167  : myVehicle(v), myTime(time), myOnInit(onInit) {}
168  void run(FXWorkerThread* context);
169  private:
170  SUMOVehicle& myVehicle;
171  const SUMOTime myTime;
172  const bool myOnInit;
173  private:
175  RoutingTask& operator=(const RoutingTask&);
176  };
177 #endif
178 
181 
193  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
195 
196 
197 private:
200 
202  static std::vector<double> myEdgeSpeeds;
203 
205  static double myAdaptationWeight;
206 
209 
212 
214  static int myAdaptationSteps;
215 
218 
220  static std::vector<std::vector<double> > myPastEdgeSpeeds;
221 
223  static bool myWithTaz;
224 
227 
230 
232  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
233 
234 #ifdef HAVE_FOX
235  static FXWorkerThread::Pool myThreadPool;
236 #endif
237 
238 private:
241 
244 
245 
246 };
247 
248 
249 #endif
250 
251 /****************************************************************************/
252 
MSRoutingEngine::getRouterTT
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
Definition: MSRoutingEngine.cpp:324
MSRoutingEngine::reroute
static void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const bool onInit)
initiate the rerouting, create router / thread pool on first use
Definition: MSRoutingEngine.cpp:225
MSRoutingEngine::myAdaptationWeight
static double myAdaptationWeight
Information which weight prior edge efforts have.
Definition: MSRoutingEngine.h:205
SUMOTime.h
MSRoutingEngine::getLastAdaptation
static SUMOTime getLastAdaptation()
Information when the last edge weight adaptation occurred.
Definition: MSRoutingEngine.h:78
MSRoutingEngine::myEdgeWeightSettingCommand
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
Definition: MSRoutingEngine.h:199
MSRoutingEngine::MSRoutingEngine
MSRoutingEngine(const MSRoutingEngine &)
Invalidated copy constructor.
MSRoutingEngine::myRouter
static SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouter
The router to use.
Definition: MSRoutingEngine.h:226
WrappingCommand.h
MSRoutingEngine::myCachedRoutes
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
Definition: MSRoutingEngine.h:232
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
MSRoutingEngine::getAssumedSpeed
static double getAssumedSpeed(const MSEdge *edge)
return current travel speed assumption
Definition: MSRoutingEngine.cpp:154
MSRoutingEngine::myEdgeSpeeds
static std::vector< double > myEdgeSpeeds
The container of edge speeds.
Definition: MSRoutingEngine.h:202
MSRoutingEngine::adaptEdgeEfforts
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
Definition: MSRoutingEngine.cpp:160
MSRoutingEngine::myLastAdaptation
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
Definition: MSRoutingEngine.h:211
MSRoute
Definition: MSRoute.h:67
MSRoutingEngine::setEdgeTravelTime
static void setEdgeTravelTime(const MSEdge *const edge, const double travelTime)
adapt the known travel time for an edge
Definition: MSRoutingEngine.cpp:318
MSDevice.h
MSVehicle.h
MSRoutingEngine::cleanup
static void cleanup()
deletes the router instance
Definition: MSRoutingEngine.cpp:340
MSRoutingEngine::initEdgeWeights
static void initEdgeWeights()
initialize the edge weights if not done before
Definition: MSRoutingEngine.cpp:100
MSRoutingEngine::getEffort
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
Definition: MSRoutingEngine.cpp:130
AStarRouter.h
MSRoutingEngine::myAdaptationStepsIndex
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
Definition: MSRoutingEngine.h:217
MSRoutingEngine::myWithTaz
static bool myWithTaz
whether taz shall be used at initial rerouting
Definition: MSRoutingEngine.h:223
MSRoutingEngine::myAdaptationInterval
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
Definition: MSRoutingEngine.h:208
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:76
FXWorkerThread.h
MSRoutingEngine::myPastEdgeSpeeds
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of edge speeds.
Definition: MSRoutingEngine.h:220
SUMOAbstractRouter< MSEdge, SUMOVehicle >
MSRoutingEngine::initWeightUpdate
static void initWeightUpdate()
intialize period edge weight update
Definition: MSRoutingEngine.cpp:74
MSRoutingEngine::hasEdgeUpdates
static bool hasEdgeUpdates()
returns whether any routing actions take place
Definition: MSRoutingEngine.h:73
MSRoutingEngine::myRouterWithProhibited
static AStarRouter< MSEdge, SUMOVehicle, SUMOAbstractRouterPermissions< MSEdge, SUMOVehicle > > * myRouterWithProhibited
The router to use by rerouter elements.
Definition: MSRoutingEngine.h:229
MSRoutingEngine::isEnabled
static bool isEnabled()
returns whether any routing actions take place
Definition: MSRoutingEngine.h:95
MSRoutingEngine::getEffortExtra
static double getEffortExtra(const MSEdge *const e, const SUMOVehicle *const v, double t)
Definition: MSRoutingEngine.cpp:140
FXWorkerThread::Pool
A pool of worker threads which distributes the tasks and collects the results.
Definition: FXWorkerThread.h:89
Command
Base (microsim) event class.
Definition: Command.h:53
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:72
AStarRouter
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:78
MSRoutingEngine::myAdaptationSteps
static int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
Definition: MSRoutingEngine.h:214
config.h
MSRoutingEngine::myEffortFunc
static SUMOAbstractRouter< MSEdge, SUMOVehicle >::Operation myEffortFunc
Definition: MSRoutingEngine.h:119
FXWorkerThread::Task
Abstract superclass of a task to be run with an index to keep track of pending tasks.
Definition: FXWorkerThread.h:56
MSRoutingEngine::getCachedRoute
static const MSRoute * getCachedRoute(const std::pair< const MSEdge *, const MSEdge * > &key)
return the cached route or nullptr on miss
Definition: MSRoutingEngine.cpp:215
SUMOAbstractRouter.h
MSRoutingEngine::operator=
MSRoutingEngine & operator=(const MSRoutingEngine &)
Invalidated assignment operator.
MSRoutingEngine
A device that performs vehicle rerouting based on current edge speeds.
Definition: MSRoutingEngine.h:64
FXWorkerThread
A thread repeatingly calculating incoming tasks.
Definition: FXWorkerThread.h:49