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.dev/sumo
3 // Copyright (C) 2007-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // A device that performs vehicle rerouting based on current edge speeds
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 
25 #include <set>
26 #include <vector>
27 #include <map>
28 #include <thread>
29 #include <utils/common/SUMOTime.h>
32 #include <microsim/MSRouterDefs.h>
33 
34 #ifdef HAVE_FOX
36 #endif
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
61 public:
63  static void initWeightUpdate();
64 
66  static void initEdgeWeights(SUMOVehicleClass svc);
67 
69  static bool hasEdgeUpdates() {
70  return myEdgeWeightSettingCommand != nullptr;
71  }
72 
75  return myLastAdaptation;
76  }
77 
79  static ConstMSRoutePtr getCachedRoute(const std::pair<const MSEdge*, const MSEdge*>& key);
80 
81  static void initRouter(SUMOVehicle* vehicle = nullptr);
82 
84  static void reroute(SUMOVehicle& vehicle, const SUMOTime currentTime, const std::string& info,
85  const bool onInit = false, const bool silent = false, const MSEdgeVector& prohibited = MSEdgeVector());
86 
88  static void setEdgeTravelTime(const MSEdge* const edge, const double travelTime);
89 
91  static void cleanup();
92 
94  static bool isEnabled() {
95  return !myWithTaz && myAdaptationInterval >= 0;
96  }
97 
99  static MSVehicleRouter& getRouterTT(const int rngIndex,
100  SUMOVehicleClass svc,
101  const MSEdgeVector& prohibited = MSEdgeVector());
102 
104  static MSTransportableRouter& getIntermodalRouterTT(const int rngIndex,
105  const MSEdgeVector& prohibited = MSEdgeVector());
106 
121  static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
122  static double getEffortBike(const MSEdge* const e, const SUMOVehicle* const v, double t);
123  static double getEffortExtra(const MSEdge* const e, const SUMOVehicle* const v, double t);
125 
127  static double getAssumedSpeed(const MSEdge* edge, const SUMOVehicle* veh);
128 
130  static bool withTaz() {
131  return myWithTaz;
132  }
133 
135  static void addEdgeTravelTime(const MSEdge& edge, const SUMOTime travelTime);
136 
137 #ifdef HAVE_FOX
138  static void waitForAll();
139 #endif
140 
141 
142 private:
143 #ifdef HAVE_FOX
148  class RoutingTask : public MFXWorkerThread::Task {
149  public:
150  RoutingTask(SUMOVehicle& v, const SUMOTime time, const std::string& info,
151  const bool onInit, const bool silent, const MSEdgeVector& prohibited)
152  : myVehicle(v), myTime(time), myInfo(info), myOnInit(onInit), mySilent(silent), myProhibited(prohibited) {}
153  void run(MFXWorkerThread* context);
154  private:
155  SUMOVehicle& myVehicle;
156  const SUMOTime myTime;
157  const std::string myInfo;
158  const bool myOnInit;
159  const bool mySilent;
160  const MSEdgeVector myProhibited;
161  private:
163  RoutingTask& operator=(const RoutingTask&) = delete;
164  };
165 #endif
166 
169 
181  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
182 
183  static double patchSpeedForTurns(const MSEdge* edge, double currSpeed);
185 
187  static void _initEdgeWeights(std::vector<double>& edgeSpeeds, std::vector<std::vector<double> >& pastEdgeSpeeds);
188 
190  static SumoRNG* getThreadRNG();
191 
192 private:
195 
197  static double myAdaptationWeight;
198 
201 
204 
206  static int myAdaptationSteps;
207 
210 
211  typedef std::pair<SUMOTime, int> TimeAndCount;
212 
214  static std::vector<double> myEdgeSpeeds;
215  static std::vector<double> myEdgeBikeSpeeds;
216 
218  static std::vector<TimeAndCount> myEdgeTravelTimes;
219 
221  static std::vector<std::vector<double> > myPastEdgeSpeeds;
222  static std::vector<std::vector<double> > myPastEdgeBikeSpeeds;
223 
225  static bool myWithTaz;
226 
228  static bool myBikeSpeeds;
229 
232 
233  static std::map<std::thread::id, SumoRNG*> myThreadRNGs;
234 
236  static std::map<std::pair<const MSEdge*, const MSEdge*>, ConstMSRoutePtr> myCachedRoutes;
237 
239  static double myPriorityFactor;
240 
242  static double myMinEdgePriority;
244  static double myEdgePriorityRange;
245 
246 #ifdef HAVE_FOX
248  static FXMutex myRouteCacheMutex;
249 #endif
250 
251 private:
254 
257 
258 
259 };
long long int SUMOTime
Definition: GUI.h:35
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition: Route.h:31
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
Base (microsim) event class.
Definition: Command.h:50
Abstract superclass of a task to be run with an index to keep track of pending tasks.
A thread repeatingly calculating incoming tasks.
A road/street connecting two junctions.
Definition: MSEdge.h:77
A device that performs vehicle rerouting based on current edge speeds.
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
static double myAdaptationWeight
Information which weight prior edge efforts have.
static int myAdaptationStepsIndex
The current index in the pastEdgeSpeed ring-buffer.
static double myMinEdgePriority
Minimum priority for all edges.
static std::vector< TimeAndCount > myEdgeTravelTimes
Sum of travel times experienced by equipped vehicles for each edge.
MSRoutingEngine(const MSRoutingEngine &)
Invalidated copy constructor.
static double getEffortBike(const MSEdge *const e, const SUMOVehicle *const v, double t)
static void setEdgeTravelTime(const MSEdge *const edge, const double travelTime)
adapt the known travel time for an edge
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
static SUMOTime getLastAdaptation()
Information when the last edge weight adaptation occurred.
static double myEdgePriorityRange
the difference between maximum and minimum priority for all edges
static bool withTaz()
whether taz-routing is enabled
static double myPriorityFactor
Coefficient for factoring edge priority into routing weight.
static std::map< std::pair< const MSEdge *, const MSEdge * >, ConstMSRoutePtr > myCachedRoutes
The container of pre-calculated routes.
static SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
static bool myBikeSpeeds
whether separate speeds for bicycles shall be tracked
static void _initEdgeWeights(std::vector< double > &edgeSpeeds, std::vector< std::vector< double > > &pastEdgeSpeeds)
initialized edge speed storage into the given containers
static SumoRNG * getThreadRNG()
returns RNG associated with the current thread
static bool isEnabled()
returns whether any routing actions take place
static bool myWithTaz
whether taz shall be used at initial rerouting
static std::vector< std::vector< double > > myPastEdgeBikeSpeeds
static std::vector< double > myEdgeSpeeds
The container of edge speeds.
std::pair< SUMOTime, int > TimeAndCount
static bool hasEdgeUpdates()
returns whether any edge weight updates will take place
static std::map< std::thread::id, SumoRNG * > myThreadRNGs
static void addEdgeTravelTime(const MSEdge &edge, const SUMOTime travelTime)
record actual travel time for an edge
static void initWeightUpdate()
intialize period edge weight update
static void initEdgeWeights(SUMOVehicleClass svc)
initialize the edge weights if not done before
static MSVehicleRouter & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector &prohibited=MSEdgeVector())
return the vehicle router instance
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
static void cleanup()
deletes the router instance
MSRoutingEngine & operator=(const MSRoutingEngine &)
Invalidated assignment operator.
static void initRouter(SUMOVehicle *vehicle=nullptr)
static SUMOAbstractRouter< MSEdge, SUMOVehicle >::Operation myEffortFunc
static ConstMSRoutePtr getCachedRoute(const std::pair< const MSEdge *, const MSEdge * > &key)
return the cached route or nullptr on miss
static int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
static MSRouterProvider * myRouterProvider
The router to use.
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
static std::vector< std::vector< double > > myPastEdgeSpeeds
The container of past edge speeds (when using a simple moving average)
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
static double getAssumedSpeed(const MSEdge *edge, const SUMOVehicle *veh)
return current travel speed assumption
static MSTransportableRouter & getIntermodalRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector())
return the person router instance
static double patchSpeedForTurns(const MSEdge *edge, double currSpeed)
static double getEffortExtra(const MSEdge *const e, const SUMOVehicle *const v, double t)
static std::vector< double > myEdgeBikeSpeeds
Representation of a vehicle.
Definition: SUMOVehicle.h:60