Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2025 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>
33
34#ifdef HAVE_FOX
36#endif
37
38
39// ===========================================================================
40// class declarations
41// ===========================================================================
42class MSTransportable;
44
45// ===========================================================================
46// class definitions
47// ===========================================================================
67public:
68 typedef std::map<const MSEdge*, double> Prohibitions;
69
71 static void initWeightUpdate();
72
74 static void initEdgeWeights(SUMOVehicleClass svc, SUMOTime lastAdaption = -1, int index = -1);
75
77 static bool hasEdgeUpdates() {
78 return myEdgeWeightSettingCommand != nullptr;
79 }
80
83 return myLastAdaptation;
84 }
85
87 static ConstMSRoutePtr getCachedRoute(const std::pair<const MSEdge*, const MSEdge*>& key);
88
89 static void initRouter(SUMOVehicle* vehicle = nullptr);
90
92 static void reroute(SUMOVehicle& vehicle, const SUMOTime currentTime, const std::string& info,
93 const bool onInit = false, const bool silent = false, const Prohibitions& prohibited = {});
94
96 static void reroute(MSTransportable& t, const SUMOTime currentTime, const std::string& info,
97 const bool onInit = false, const bool silent = false, const Prohibitions& prohibited = {});
98
100 static void setEdgeTravelTime(const MSEdge* const edge, const double travelTime);
101
103 static void cleanup();
104
106 static bool isEnabled() {
107 return !myWithTaz && myAdaptationInterval >= 0;
108 }
109
111 static MSVehicleRouter& getRouterTT(const int rngIndex,
113 const Prohibitions& prohibited = {});
114
116 static MSTransportableRouter& getIntermodalRouterTT(const int rngIndex,
117 const Prohibitions& prohibited = {});
118
133 static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
134 static double getEffortBike(const MSEdge* const e, const SUMOVehicle* const v, double t);
135 static double getEffortExtra(const MSEdge* const e, const SUMOVehicle* const v, double t);
137
139 static double getAssumedSpeed(const MSEdge* edge, const SUMOVehicle* veh);
140
142 static bool withTaz() {
143 return myWithTaz;
144 }
145
147 static void addEdgeTravelTime(const MSEdge& edge, const SUMOTime travelTime);
148
153 static void saveState(OutputDevice& out);
154
159 static void loadState(const SUMOSAXAttributes& attrs);
160
161#ifdef HAVE_FOX
162 static void waitForAll();
163#endif
164
165
166private:
167#ifdef HAVE_FOX
172 class RoutingTask : public MFXWorkerThread::Task {
173 public:
174 RoutingTask(SUMOVehicle& v, const SUMOTime time, const std::string& info,
175 const bool onInit, const bool silent, const Prohibitions& prohibited)
176 : myVehicle(v), myTime(time), myInfo(info), myOnInit(onInit), mySilent(silent), myProhibited(prohibited) {}
177 void run(MFXWorkerThread* context);
178 private:
179 SUMOVehicle& myVehicle;
180 const SUMOTime myTime;
181 const std::string myInfo;
182 const bool myOnInit;
183 const bool mySilent;
184 const Prohibitions myProhibited;
185 private:
187 RoutingTask& operator=(const RoutingTask&) = delete;
188 };
189
190#endif
191
194
206 static SUMOTime adaptEdgeEfforts(SUMOTime currentTime);
207
208 static double patchSpeedForTurns(const MSEdge* edge, double currSpeed);
210
212 static void _initEdgeWeights(std::vector<double>& edgeSpeeds, std::vector<std::vector<double> >& pastEdgeSpeeds);
213
216
217private:
220
222 static double myAdaptationWeight;
223
226
229
232
235
236 typedef std::pair<SUMOTime, int> TimeAndCount;
237
239 static std::vector<double> myEdgeSpeeds;
240 static std::vector<double> myEdgeBikeSpeeds;
241
243 static std::vector<TimeAndCount> myEdgeTravelTimes;
244
246 static std::vector<std::vector<double> > myPastEdgeSpeeds;
247 static std::vector<std::vector<double> > myPastEdgeBikeSpeeds;
248
250 static bool myWithTaz;
251
253 static bool myBikeSpeeds;
254
257
259 static std::map<std::pair<const MSEdge*, const MSEdge*>, ConstMSRoutePtr> myCachedRoutes;
260
262 static double myPriorityFactor;
263
265 static double myMinEdgePriority;
267 static double myEdgePriorityRange;
268
271
272#ifdef HAVE_FOX
274 static FXMutex myRouteCacheMutex;
275#endif
276
277private:
280
283
284
285};
long long int SUMOTime
Definition GUI.h:36
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.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 void saveState(OutputDevice &out)
Saves the state (i.e. recorded speeds)
static SUMOTime myAdaptationInterval
At which time interval the edge weights get updated.
static void initEdgeWeights(SUMOVehicleClass svc, SUMOTime lastAdaption=-1, int index=-1)
initialize the edge weights if not done before
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 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 SumoRNG * getThreadRNG()
returns RNG associated with the current thread
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.
MSRoutingEngine & operator=(const MSRoutingEngine &)
Invalidated assignment operator.
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 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 void addEdgeTravelTime(const MSEdge &edge, const SUMOTime travelTime)
record actual travel time for an edge
static void initWeightUpdate()
intialize period edge weight update
static bool myDynamicRandomness
whether randomness varies over time
static SUMOTime myLastAdaptation
Information when the last edge weight adaptation occurred.
static void cleanup()
deletes the router instance
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.
std::map< const MSEdge *, double > Prohibitions
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 void reroute(SUMOVehicle &vehicle, const SUMOTime currentTime, const std::string &info, const bool onInit=false, const bool silent=false, const Prohibitions &prohibited={})
initiate the rerouting, create router / thread pool on first use
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 void loadState(const SUMOSAXAttributes &attrs)
Loads the state.
static double patchSpeedForTurns(const MSEdge *edge, double currSpeed)
static MSVehicleRouter & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const Prohibitions &prohibited={})
return the vehicle router instance
static double getEffortExtra(const MSEdge *const e, const SUMOVehicle *const v, double t)
static MSTransportableRouter & getIntermodalRouterTT(const int rngIndex, const Prohibitions &prohibited={})
return the person router instance
static std::vector< double > myEdgeBikeSpeeds
Static storage of an output device and its base (abstract) implementation.
Encapsulated SAX-Attributes.
Representation of a vehicle.
Definition SUMOVehicle.h:62