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-2020 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/MSVehicle.h>
34 #include "MSDevice.h"
35 
36 #ifdef HAVE_FOX
38 #endif
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
63 public:
65 
67  static void initWeightUpdate();
68 
70  static void initEdgeWeights(SUMOVehicleClass svc);
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 
85  static void initRouter(SUMOVehicle* vehicle = nullptr);
86 
88  static void reroute(SUMOVehicle& vehicle, const SUMOTime currentTime, const std::string& info,
89  const bool onInit = false, const bool silent = false, const MSEdgeVector& prohibited = MSEdgeVector());
90 
92  static void setEdgeTravelTime(const MSEdge* const edge, const double travelTime);
93 
95  static void cleanup();
96 
98  static bool isEnabled() {
99  return !myWithTaz && myAdaptationInterval >= 0;
100  }
101 
103  static SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouterTT(const int rngIndex,
104  SUMOVehicleClass svc,
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 
134 #ifdef HAVE_FOX
135  static void waitForAll();
136 #endif
137 
138 
139 private:
140 #ifdef HAVE_FOX
145  class RoutingTask : public FXWorkerThread::Task {
146  public:
147  RoutingTask(SUMOVehicle& v, const SUMOTime time, const std::string& info,
148  const bool onInit, const bool silent, const MSEdgeVector& prohibited)
149  : myVehicle(v), myTime(time), myInfo(info), myOnInit(onInit), mySilent(silent), myProhibited(prohibited) {}
150  void run(FXWorkerThread* context);
151  private:
152  SUMOVehicle& myVehicle;
153  const SUMOTime myTime;
154  const std::string myInfo;
155  const bool myOnInit;
156  const bool mySilent;
157  const MSEdgeVector myProhibited;
158  private:
160  RoutingTask& operator=(const RoutingTask&) = delete;
161  };
162 #endif
163 
166 
178  static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
180 
182  static void _initEdgeWeights(std::vector<double>& edgeSpeeds, std::vector<std::vector<double> >& pastEdgeSpeeds);
183 
184 private:
187 
189  static double myAdaptationWeight;
190 
193 
196 
198  static int myAdaptationSteps;
199 
202 
204  static std::vector<double> myEdgeSpeeds;
205  static std::vector<double> myEdgeBikeSpeeds;
206 
208  static std::vector<std::vector<double> > myPastEdgeSpeeds;
209  static std::vector<std::vector<double> > myPastEdgeBikeSpeeds;
210 
212  static bool myWithTaz;
213 
215  static bool myBikeSpeeds;
216 
219 
221  static std::map<std::pair<const MSEdge*, const MSEdge*>, const MSRoute*> myCachedRoutes;
222 
224  static double myPriorityFactor;
225 
227  static double myMinEdgePriority;
229  static double myEdgePriorityRange;
230 
231 #ifdef HAVE_FOX
233  static FXMutex myRouteCacheMutex;
234 #endif
235 
236 private:
239 
242 
243 
244 };
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
long long int SUMOTime
Definition: SUMOTime.h:31
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
Base (microsim) event class.
Definition: Command.h:49
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.
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.
static bool hasEdgeUpdates()
returns whether any routing actions take place
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 getEffortExtra(const MSEdge *const e, const SUMOVehicle *const v, double t)
static std::vector< double > myEdgeBikeSpeeds
Representation of a vehicle.
Definition: SUMOVehicle.h:58