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-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/****************************************************************************/
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 std::vector<SUMOVehicleParameter::Stop>& 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 void checkRemoval() const;
93
102 int writeEdgeIDs(OutputDevice& os, int firstIndex = 0, int lastIndex = -1, bool withInternal = false, SUMOVehicleClass svc = SVC_IGNORING) const;
103
104 bool contains(const MSEdge* const edge) const {
105 return std::find(myEdges.begin(), myEdges.end(), edge) != myEdges.end();
106 }
107
108 bool containsAnyOf(const MSEdgeVector& edgelist) const;
109
110 const MSEdge* operator[](int index) const;
111
114
119 static void dict_saveState(OutputDevice& out);
120
122 static void dict_clearState();
124
126 return myEdges;
127 }
128
147 double getDistanceBetween(double fromPos, double toPos, const MSLane* fromLane, const MSLane* toLane, int routePosition = 0) const;
148
160 double getDistanceBetween(double fromPos, double toPos, const MSRouteIterator& fromEdge, const MSRouteIterator& toEdge, bool includeInternal = true) const;
161
162
164 const RGBColor& getColor() const;
165
168 return myPeriod;
169 }
170
175 double getCosts() const {
176 return myCosts;
177 }
178
183 double getSavings() const {
184 return mySavings;
185 }
186
189 return myReplacedTime;
190 }
191
193 int getReplacedIndex() const {
194 return myReplacedIndex;
195 }
196
198 void setPeriod(SUMOTime period) {
199 myPeriod = period;
200 }
201
206 void setCosts(double costs) {
207 myCosts = costs;
208 }
213 void setSavings(double savings) {
214 mySavings = savings;
215 }
216
217 bool mustReroute() const {
218 return myReroute;
219 }
220
221 void setReroute(bool reroute = true) {
222 myReroute = reroute;
223 }
224
226 const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
227
228public:
238 static bool dictionary(const std::string& id, ConstMSRoutePtr route);
239
250 static bool dictionary(const std::string& id, RandomDistributor<ConstMSRoutePtr>* const routeDist, const bool permanent = true);
251
260 static ConstMSRoutePtr dictionary(const std::string& id, SumoRNG* rng = 0);
261
263 static bool hasRoute(const std::string& id);
264
272 static RandomDistributor<ConstMSRoutePtr>* distDictionary(const std::string& id);
273
275 static void clear();
276
278 static void checkDist(const std::string& id);
279
280 static void insertIDs(std::vector<std::string>& into);
281
282private:
285
287 const bool myAmPermanent;
288
290 const RGBColor* const myColor;
291
294
296 double myCosts;
297
299 double mySavings;
300
303
305 std::vector<SUMOVehicleParameter::Stop> myStops;
306
309
312
313private:
315 typedef std::map<std::string, ConstMSRoutePtr> RouteDict;
316
319
321 typedef std::map<std::string, std::pair<RandomDistributor<ConstMSRoutePtr>*, bool> > RouteDistDict;
322
325
326#ifdef HAVE_FOX
328 static FXMutex myDictMutex;
329#endif
330private:
333
334};
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
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:301
bool myReroute
Whether this route is incomplete and requires rerouting.
Definition MSRoute.h:302
double myCosts
The assigned or calculated costs.
Definition MSRoute.h:296
void setReroute(bool reroute=true)
Definition MSRoute.h:221
int size() const
Returns the number of edges to pass.
Definition MSRoute.cpp:85
static RouteDistDict myDistDict
The dictionary container.
Definition MSRoute.h:324
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition MSRoute.cpp:261
const RGBColor *const myColor
The color.
Definition MSRoute.h:290
const ConstMSEdgeVector & getEdges() const
Definition MSRoute.h:125
static RouteDict myDict
The dictionary container.
Definition MSRoute.h:318
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition MSRoute.h:305
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition MSRoute.cpp:404
int getReplacedIndex() const
Returns the index at which this route was replaced.
Definition MSRoute.h:193
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:219
void setCosts(double costs)
Sets the costs of the route.
Definition MSRoute.h:206
double getSavings() const
Returns the estimated savings due to using this route (compare to the route before rerouting)
Definition MSRoute.h:183
static bool hasRoute(const std::string &id)
returns whether a route with the given id exists
Definition MSRoute.cpp:152
std::map< std::string, ConstMSRoutePtr > RouteDict
Definition of the dictionary container.
Definition MSRoute.h:315
virtual ~MSRoute()
Destructor.
Definition MSRoute.cpp:67
void checkRemoval() const
removes the route from the internal dict if it is not marked as permanent
Definition MSRoute.cpp:98
const MSEdge * operator[](int index) const
Definition MSRoute.cpp:255
bool contains(const MSEdge *const edge) const
Definition MSRoute.h:104
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:308
SUMOTime myPeriod
The period when repeating this route.
Definition MSRoute.h:293
ConstMSEdgeVector myEdges
The list of edges to pass.
Definition MSRoute.h:284
static void insertIDs(std::vector< std::string > &into)
Definition MSRoute.cpp:204
bool containsAnyOf(const MSEdgeVector &edgelist) const
Definition MSRoute.cpp:243
int myReplacedIndex
The index where this route was replaced with an alternative route.
Definition MSRoute.h:311
std::map< std::string, std::pair< RandomDistributor< ConstMSRoutePtr > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition MSRoute.h:321
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Definition MSRoute.cpp:109
const RGBColor & getColor() const
Returns the color.
Definition MSRoute.cpp:395
static RandomDistributor< ConstMSRoutePtr > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition MSRoute.cpp:161
void setPeriod(SUMOTime period)
sets the period
Definition MSRoute.h:198
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:311
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
Definition MSRoute.h:287
SUMOTime getReplacedTime() const
Returns the time at which this route was replaced (or -1)
Definition MSRoute.h:188
bool mustReroute() const
Definition MSRoute.h:217
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition MSRoute.cpp:187
double mySavings
The estimated savings when rerouting.
Definition MSRoute.h:299
MSRoute & operator=(const MSRoute &s)
static void clear()
Clears the dictionary (delete all known routes, too)
Definition MSRoute.cpp:174
SUMOTime getPeriod() const
returns the period
Definition MSRoute.h:167
void setSavings(double savings)
Sets the savings of the route.
Definition MSRoute.h:213
double getCosts() const
Returns the costs of the route.
Definition MSRoute.h:175
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.