Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSRoute.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2002-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/****************************************************************************/
22// A vehicle route
23/****************************************************************************/
24#pragma once
25#include <config.h>
26
27#include <string>
28#include <map>
29#include <vector>
30#include <algorithm>
31#include <memory>
32#include <utils/common/Named.h>
37#ifdef HAVE_FOX
39#include <FXThread.h>
40#endif
41
42
43// ===========================================================================
44// class declarations
45// ===========================================================================
46class MSEdge;
47class MSLane;
48class MSRoute;
49class OutputDevice;
50
51
52// ===========================================================================
53// types definitions
54// ===========================================================================
55typedef std::vector<const MSEdge*> ConstMSEdgeVector;
56typedef std::vector<MSEdge*> MSEdgeVector;
57typedef ConstMSEdgeVector::const_iterator MSRouteIterator;
58typedef std::shared_ptr<const MSRoute> ConstMSRoutePtr;
59
60
61// ===========================================================================
62// class definitions
63// ===========================================================================
67class MSRoute : public Named, public Parameterised {
68public:
70 MSRoute(const std::string& id, const ConstMSEdgeVector& edges,
71 const bool isPermanent, const RGBColor* const c,
72 const StopParVector& stops,
73 SUMOTime replacedTime = -1,
74 int replacedIndex = 0);
75
77 virtual ~MSRoute();
78
80 MSRouteIterator begin() const;
81
83 MSRouteIterator end() const;
84
86 int size() const;
87
89 const MSEdge* getLastEdge() const;
90
92 const MSEdge* getFirstEdge() const;
93
95 void checkRemoval(bool force = false) const;
96
105 int writeEdgeIDs(OutputDevice& os, int firstIndex = 0, int lastIndex = -1, bool withInternal = false, SUMOVehicleClass svc = SVC_IGNORING) const;
106
107 bool contains(const MSEdge* const edge) const {
108 return std::find(myEdges.begin(), myEdges.end(), edge) != myEdges.end();
109 }
110
111 bool containsAnyOf(const MSEdgeVector& edgelist) const;
112
113 const MSEdge* operator[](int index) const;
114
117
122 static void dict_saveState(OutputDevice& out);
123
125 static void dict_clearState();
127
129 return myEdges;
130 }
131
150 double getDistanceBetween(double fromPos, double toPos, const MSLane* fromLane, const MSLane* toLane, int routePosition = 0) const;
151
163 double getDistanceBetween(double fromPos, double toPos, const MSRouteIterator& fromEdge, const MSRouteIterator& toEdge, bool includeInternal = true) const;
164
165
167 const RGBColor& getColor() const;
168
171 return myPeriod;
172 }
173
178 double getCosts() const {
179 return myCosts;
180 }
181
186 double getSavings() const {
187 return mySavings;
188 }
189
192 return myReplacedTime;
193 }
194
196 int getReplacedIndex() const {
197 return myReplacedIndex;
198 }
199
201 void setPeriod(SUMOTime period) {
202 myPeriod = period;
203 }
204
209 void setCosts(double costs) {
210 myCosts = costs;
211 }
216 void setSavings(double savings) {
217 mySavings = savings;
218 }
219
220 bool mustReroute() const {
221 return myReroute;
222 }
223
224 void setReroute(bool reroute = true) {
225 myReroute = reroute;
226 }
227
229 const StopParVector& getStops() const;
230
231public:
241 static bool dictionary(const std::string& id, ConstMSRoutePtr route);
242
253 static bool dictionary(const std::string& id, RandomDistributor<ConstMSRoutePtr>* const routeDist, const bool permanent = true);
254
263 static ConstMSRoutePtr dictionary(const std::string& id, SumoRNG* rng = 0);
264
266 static bool hasRoute(const std::string& id);
267
275 static RandomDistributor<ConstMSRoutePtr>* distDictionary(const std::string& id);
276
278 static void clear();
279
281 static void checkDist(const std::string& id);
282
283 static void insertIDs(std::vector<std::string>& into);
284
285private:
288
290 const bool myAmPermanent;
291
293 const RGBColor* const myColor;
294
297
299 double myCosts;
300
302 double mySavings;
303
306
309
312
315
316private:
318 typedef std::map<std::string, ConstMSRoutePtr> RouteDict;
319
322
324 typedef std::map<std::string, std::pair<RandomDistributor<ConstMSRoutePtr>*, bool> > RouteDistDict;
325
328
329#ifdef HAVE_FOX
331 static FXMutex myDictMutex;
332#endif
333private:
336
337};
long long int SUMOTime
Definition GUI.h:36
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:73
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSRoute.h:55
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition MSRoute.h:57
std::vector< MSEdge * > MSEdgeVector
Definition MSRoute.h:56
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition MSRoute.h:58
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
std::vector< SUMOVehicleParameter::Stop > StopParVector
A road/street connecting two junctions.
Definition MSEdge.h:77
Representation of a lane in the micro simulation.
Definition MSLane.h:84
static void dict_clearState()
Decrement all route references before quick-loading state.
Definition MSRoute.cpp:308
bool myReroute
Whether this route is incomplete and requires rerouting.
Definition MSRoute.h:305
double myCosts
The assigned or calculated costs.
Definition MSRoute.h:299
void setReroute(bool reroute=true)
Definition MSRoute.h:224
int size() const
Returns the number of edges to pass.
Definition MSRoute.cpp:85
static RouteDistDict myDistDict
The dictionary container.
Definition MSRoute.h:327
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition MSRoute.cpp:268
const RGBColor *const myColor
The color.
Definition MSRoute.h:293
const ConstMSEdgeVector & getEdges() const
Definition MSRoute.h:128
StopParVector myStops
List of the stops on the parsed route.
Definition MSRoute.h:308
static RouteDict myDict
The dictionary container.
Definition MSRoute.h:321
int getReplacedIndex() const
Returns the index at which this route was replaced.
Definition MSRoute.h:196
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition MSRoute.cpp:79
int writeEdgeIDs(OutputDevice &os, int firstIndex=0, int lastIndex=-1, bool withInternal=false, SUMOVehicleClass svc=SVC_IGNORING) const
Output the edge ids up to but not including the id of the given edge.
Definition MSRoute.cpp:226
void setCosts(double costs)
Sets the costs of the route.
Definition MSRoute.h:209
double getSavings() const
Returns the estimated savings due to using this route (compare to the route before rerouting)
Definition MSRoute.h:186
static bool hasRoute(const std::string &id)
returns whether a route with the given id exists
Definition MSRoute.cpp:159
void checkRemoval(bool force=false) const
removes the route from the internal dict if it is not marked as permanent
Definition MSRoute.cpp:105
std::map< std::string, ConstMSRoutePtr > RouteDict
Definition of the dictionary container.
Definition MSRoute.h:318
virtual ~MSRoute()
Destructor.
Definition MSRoute.cpp:67
const MSEdge * operator[](int index) const
Definition MSRoute.cpp:262
bool contains(const MSEdge *const edge) const
Definition MSRoute.h:107
const MSEdge * getLastEdge() const
returns the destination edge
Definition MSRoute.cpp:91
SUMOTime myReplacedTime
The time where this route was replaced with an alternative route (or -1)
Definition MSRoute.h:311
SUMOTime myPeriod
The period when repeating this route.
Definition MSRoute.h:296
ConstMSEdgeVector myEdges
The list of edges to pass.
Definition MSRoute.h:287
static void insertIDs(std::vector< std::string > &into)
Definition MSRoute.cpp:211
bool containsAnyOf(const MSEdgeVector &edgelist) const
Definition MSRoute.cpp:250
int myReplacedIndex
The index where this route was replaced with an alternative route.
Definition MSRoute.h:314
std::map< std::string, std::pair< RandomDistributor< ConstMSRoutePtr > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition MSRoute.h:324
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Definition MSRoute.cpp:116
const RGBColor & getColor() const
Returns the color.
Definition MSRoute.cpp:402
static RandomDistributor< ConstMSRoutePtr > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition MSRoute.cpp:168
void setPeriod(SUMOTime period)
sets the period
Definition MSRoute.h:201
const MSEdge * getFirstEdge() const
returns the origin edge
Definition MSRoute.cpp:98
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition MSRoute.cpp:73
double getDistanceBetween(double fromPos, double toPos, const MSLane *fromLane, const MSLane *toLane, int routePosition=0) const
Compute the distance between 2 given edges on this route, optionally including the length of internal...
Definition MSRoute.cpp:318
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
Definition MSRoute.h:290
const StopParVector & getStops() const
Returns the stops.
Definition MSRoute.cpp:411
SUMOTime getReplacedTime() const
Returns the time at which this route was replaced (or -1)
Definition MSRoute.h:191
bool mustReroute() const
Definition MSRoute.h:220
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition MSRoute.cpp:194
double mySavings
The estimated savings when rerouting.
Definition MSRoute.h:302
MSRoute & operator=(const MSRoute &s)
static void clear()
Clears the dictionary (delete all known routes, too)
Definition MSRoute.cpp:181
SUMOTime getPeriod() const
returns the period
Definition MSRoute.h:170
void setSavings(double savings)
Sets the savings of the route.
Definition MSRoute.h:216
double getCosts() const
Returns the costs of the route.
Definition MSRoute.h:178
Base class for objects which have an id.
Definition Named.h:54
Static storage of an output device and its base (abstract) implementation.
An upper class for objects with additional parameters.
Represents a generic random distribution.