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-2022 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 <utils/common/SUMOTime.h>
33 #include <microsim/MSEdge.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 
68  static void initWeightUpdate();
69 
71  static void initEdgeWeights(SUMOVehicleClass svc);
72 
74  static bool hasEdgeUpdates() {
75  return myEdgeWeightSettingCommand != nullptr;
76  }
77 
80  return myLastAdaptation;
81  }
82 
84  static const MSRoute* getCachedRoute(const std::pair<const MSEdge*, const MSEdge*>& key);
85 
86  static void initRouter(SUMOVehicle* vehicle = nullptr);
87 
89  static void reroute(SUMOVehicle& vehicle, const SUMOTime currentTime, const std::string& info,
90  const bool onInit = false, const bool silent = false, const MSEdgeVector& prohibited = MSEdgeVector());
91 
93  static void setEdgeTravelTime(const MSEdge* const edge, const double travelTime);
94 
96  static void cleanup();
97 
99  static bool isEnabled() {
100  return !myWithTaz && myAdaptationInterval >= 0;
101  }
102 
104  static SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouterTT(const int rngIndex,
105  SUMOVehicleClass svc,
106  const MSEdgeVector& prohibited = MSEdgeVector());
107 
122  static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
123  static double getEffortBike(const MSEdge* const e, const SUMOVehicle* const v, double t);
124  static double getEffortExtra(const MSEdge* const e, const SUMOVehicle* const v, double t);
126 
128  static double getAssumedSpeed(const MSEdge* edge, const SUMOVehicle* veh);
129 
131  static bool withTaz() {
132  return myWithTaz;
133  }
134 
136  static void addEdgeTravelTime(const MSEdge& edge, const SUMOTime travelTime);
137 
138 #ifdef HAVE_FOX
139  static void waitForAll();
140 #endif
141 
142 
143 private:
144 #ifdef HAVE_FOX
149  class RoutingTask : public FXWorkerThread::Task {
150  public:
151  RoutingTask(SUMOVehicle& v, const SUMOTime time, const std::string& info,
152  const bool onInit, const bool silent, const MSEdgeVector& prohibited)
153  : myVehicle(v), myTime(time), myInfo(info), myOnInit(onInit), mySilent(silent), myProhibited(prohibited) {}
154  void run(FXWorkerThread* context);
155  private:
156  SUMOVehicle& myVehicle;
157  const SUMOTime myTime;
158  const std::string myInfo;
159  const bool myOnInit;
160  const bool mySilent;
161  const MSEdgeVector myProhibited;
162  private:
164  RoutingTask& operator=(const RoutingTask&) = delete;
165  };
166 #endif
167 
170 
182  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
183 
184  static double patchSpeedForTurns(const MSEdge* edge, double currSpeed);
186 
188  static void _initEdgeWeights(std::vector<double>& edgeSpeeds, std::vector<std::vector<double> >& pastEdgeSpeeds);
189 
190 private:
193 
195  static double myAdaptationWeight;
196 
199 
202 
204  static int myAdaptationSteps;
205 
208 
209  typedef std::pair<SUMOTime, int> TimeAndCount;
210 
212  static std::vector<double> myEdgeSpeeds;
213  static std::vector<double> myEdgeBikeSpeeds;
214 
216  static std::vector<TimeAndCount> myEdgeTravelTimes;
217 
219  static std::vector<std::vector<double> > myPastEdgeSpeeds;
220  static std::vector<std::vector<double> > myPastEdgeBikeSpeeds;
221 
223  static bool myWithTaz;
224 
226  static bool myBikeSpeeds;
227 
230 
232  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
233 
235  static double myPriorityFactor;
236 
238  static double myMinEdgePriority;
240  static double myEdgePriorityRange;
241 
242 #ifdef HAVE_FOX
244  static FXMutex myRouteCacheMutex;
245 #endif
246 
247 private:
250 
253 
254 
255 };
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
long long int SUMOTime
Definition: SUMOTime.h:32
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 SUMOTime adaptEdgeEfforts(SUMOTime currentTime)
Adapt edge efforts by the current edge states.
static const MSRoute * getCachedRoute(const std::pair< const MSEdge *, const MSEdge * > &key)
return the cached route or nullptr on miss
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 MSRouterProvider * myRouterProvider
The router to use.
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 routing actions take place
static void addEdgeTravelTime(const MSEdge &edge, const SUMOTime travelTime)
record actual travel time for an edge
static void initWeightUpdate()
intialize period edge weight update
RouterProvider< MSEdge, MSLane, MSJunction, SUMOVehicle > MSRouterProvider
static void initEdgeWeights(SUMOVehicleClass svc)
initialize the edge weights if not done before
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 int myAdaptationSteps
The number of steps for averaging edge speeds (ring-buffer)
static std::map< std::pair< const MSEdge *, const MSEdge * >, const MSRoute * > myCachedRoutes
The container of pre-calculated routes.
static Command * myEdgeWeightSettingCommand
The weights adaptation/overwriting command.
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
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 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