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 /****************************************************************************/
16 // A device that performs vehicle rerouting based on current edge speeds
17 /****************************************************************************/
18 #ifndef MSRoutingEngine_h
19 #define MSRoutingEngine_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <set>
28 #include <vector>
29 #include <map>
30 #include <utils/common/SUMOTime.h>
34 #include <microsim/MSVehicle.h>
35 #include "MSDevice.h"
36 
37 #ifdef HAVE_FOX
39 #endif
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
64 public:
66  static void initWeightUpdate();
67 
69  static void initEdgeWeights();
70 
72  static bool hasEdgeUpdates() {
73  return myEdgeWeightSettingCommand != nullptr;
74  }
75 
78  return myLastAdaptation;
79  }
80 
82  static const MSRoute* getCachedRoute(const std::pair<const MSEdge*, const MSEdge*>& key);
83 
84  static void initRouter(SUMOVehicle* vehicle = nullptr);
85 
87  static void reroute(SUMOVehicle& vehicle, const SUMOTime currentTime, const std::string& info,
88  const bool onInit = false, const bool silent = false, const MSEdgeVector& prohibited = MSEdgeVector());
89 
91  static void setEdgeTravelTime(const MSEdge* const edge, const double travelTime);
92 
94  static void cleanup();
95 
97  static bool isEnabled() {
98  return !myWithTaz && myAdaptationInterval >= 0;
99  }
100 
102  static SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouterTT(const int rngIndex,
103  const MSEdgeVector& prohibited = MSEdgeVector());
104 
119  static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
120  static double getEffortExtra(const MSEdge* const e, const SUMOVehicle* const v, double t);
122 
124  static double getAssumedSpeed(const MSEdge* edge);
125 
126 #ifdef HAVE_FOX
127  static void waitForAll();
128 #endif
129 
130 
131 private:
132 #ifdef HAVE_FOX
133 
137  class RoutingTask : public FXWorkerThread::Task {
138  public:
139  RoutingTask(SUMOVehicle& v, const SUMOTime time, const std::string& info,
140  const bool onInit, const bool silent, const MSEdgeVector& prohibited)
141  : myVehicle(v), myTime(time), myInfo(info), myOnInit(onInit), mySilent(silent), myProhibited(prohibited) {}
142  void run(FXWorkerThread* context);
143  private:
144  SUMOVehicle& myVehicle;
145  const SUMOTime myTime;
146  const std::string myInfo;
147  const bool myOnInit;
148  const bool mySilent;
149  const MSEdgeVector myProhibited;
150  private:
152  RoutingTask& operator=(const RoutingTask&) = delete;
153  };
154 #endif
155 
158 
170  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
172 
173 
174 private:
177 
179  static std::vector<double> myEdgeSpeeds;
180 
182  static double myAdaptationWeight;
183 
186 
189 
191  static int myAdaptationSteps;
192 
195 
197  static std::vector<std::vector<double> > myPastEdgeSpeeds;
198 
200  static bool myWithTaz;
201 
204 
206  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
207 
208 #ifdef HAVE_FOX
209  static FXMutex myRouteCacheMutex;
211 #endif
212 
213 private:
216 
219 
220 
221 };
222 
223 
224 #endif
225 
226 /****************************************************************************/
227 
MSRoutingEngine::myAdaptationWeight
static double myAdaptationWeight
Information which weight prior edge efforts have.
Definition: MSRoutingEngine.h:182
SUMOTime.h
MSRoutingEngine::getLastAdaptation
static SUMOTime getLastAdaptation()
Information when the last edge weight adaptation occurred.
Definition: MSRoutingEngine.h:77
MSRoutingEngine::myEdgeWeightSettingCommand
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
Definition: MSRoutingEngine.h:176
MSRoutingEngine::MSRoutingEngine
MSRoutingEngine(const MSRoutingEngine &)
Invalidated copy constructor.
MSRoutingEngine::myRouter
static SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouter
The router to use.
Definition: MSRoutingEngine.h:203
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:206
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
MSRoutingEngine::getAssumedSpeed
static double getAssumedSpeed(const MSEdge *edge)
return current travel speed assumption
Definition: MSRoutingEngine.cpp:147
MSRoutingEngine::myEdgeSpeeds
static std::vector< double > myEdgeSpeeds
The container of edge speeds.
Definition: MSRoutingEngine.h:179
MSRoutingEngine::adaptEdgeEfforts
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
Definition: MSRoutingEngine.cpp:153
MSRoutingEngine::getRouterTT
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
Definition: MSRoutingEngine.cpp:307
MSRoutingEngine::myLastAdaptation
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
Definition: MSRoutingEngine.h:188
MSRoute
Definition: MSRoute.h:66
MSRoutingEngine::setEdgeTravelTime
static void setEdgeTravelTime(const MSEdge *const edge, const double travelTime)
adapt the known travel time for an edge
Definition: MSRoutingEngine.cpp:301
MSDevice.h
MSVehicle.h
MSRoutingEngine::cleanup
static void cleanup()
deletes the router instance
Definition: MSRoutingEngine.cpp:327
MSRoutingEngine::initEdgeWeights
static void initEdgeWeights()
initialize the edge weights if not done before
Definition: MSRoutingEngine.cpp:93
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:123
MSRoutingEngine::reroute
static void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const std::string &info, const bool onInit=false, const bool silent=false, const MSEdgeVector &prohibited=MSEdgeVector())
initiate the rerouting, create router / thread pool on first use
Definition: MSRoutingEngine.cpp:269
AStarRouter.h
MSRoutingEngine::myAdaptationStepsIndex
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
Definition: MSRoutingEngine.h:194
MSRoutingEngine::myWithTaz
static bool myWithTaz
whether taz shall be used at initial rerouting
Definition: MSRoutingEngine.h:200
MSRoutingEngine::initRouter
static void initRouter(SUMOVehicle *vehicle=nullptr)
Definition: MSRoutingEngine.cpp:218
MSRoutingEngine::myAdaptationInterval
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
Definition: MSRoutingEngine.h:185
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
FXWorkerThread.h
MSRoutingEngine::myPastEdgeSpeeds
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of edge speeds.
Definition: MSRoutingEngine.h:197
SUMOAbstractRouter< MSEdge, SUMOVehicle >
MSRoutingEngine::initWeightUpdate
static void initWeightUpdate()
intialize period edge weight update
Definition: MSRoutingEngine.cpp:69
MSRoutingEngine::hasEdgeUpdates
static bool hasEdgeUpdates()
returns whether any routing actions take place
Definition: MSRoutingEngine.h:72
MSRoutingEngine::isEnabled
static bool isEnabled()
returns whether any routing actions take place
Definition: MSRoutingEngine.h:97
MSRoutingEngine::getEffortExtra
static double getEffortExtra(const MSEdge *const e, const SUMOVehicle *const v, double t)
Definition: MSRoutingEngine.cpp:133
Command
Base (microsim) event class.
Definition: Command.h:52
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:74
MSRoutingEngine::myAdaptationSteps
static int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
Definition: MSRoutingEngine.h:191
config.h
MSRoutingEngine::myEffortFunc
static SUMOAbstractRouter< MSEdge, SUMOVehicle >::Operation myEffortFunc
Definition: MSRoutingEngine.h:121
FXWorkerThread::Task
Abstract superclass of a task to be run with an index to keep track of pending tasks.
Definition: FXWorkerThread.h:55
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:208
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:63
FXWorkerThread
A thread repeatingly calculating incoming tasks.
Definition: FXWorkerThread.h:48