Eclipse SUMO - Simulation of Urban MObility
MSRoute.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2002-2023 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 MSRoute;
48class OutputDevice;
49
50
51// ===========================================================================
52// types definitions
53// ===========================================================================
54typedef std::vector<const MSEdge*> ConstMSEdgeVector;
55typedef std::vector<MSEdge*> MSEdgeVector;
56typedef ConstMSEdgeVector::const_iterator MSRouteIterator;
57typedef std::shared_ptr<const MSRoute> ConstMSRoutePtr;
58
59
60// ===========================================================================
61// class definitions
62// ===========================================================================
66class MSRoute : public Named, public Parameterised {
67public:
69 MSRoute(const std::string& id, const ConstMSEdgeVector& edges,
70 const bool isPermanent, const RGBColor* const c,
71 const std::vector<SUMOVehicleParameter::Stop>& stops,
72 SUMOTime replacedTime = -1,
73 int replacedIndex = 0);
74
76 virtual ~MSRoute();
77
79 MSRouteIterator begin() const;
80
82 MSRouteIterator end() const;
83
85 int size() const;
86
88 const MSEdge* getLastEdge() const;
89
91 void checkRemoval() const;
92
101 int writeEdgeIDs(OutputDevice& os, int firstIndex = 0, int lastIndex = -1, bool withInternal = false, SUMOVehicleClass svc = SVC_IGNORING) const;
102
103 bool contains(const MSEdge* const edge) const {
104 return std::find(myEdges.begin(), myEdges.end(), edge) != myEdges.end();
105 }
106
107 bool containsAnyOf(const MSEdgeVector& edgelist) const;
108
109 const MSEdge* operator[](int index) const;
110
113
118 static void dict_saveState(OutputDevice& out);
119
121 static void dict_clearState();
123
125 return myEdges;
126 }
127
141 double getDistanceBetween(double fromPos, double toPos, const MSEdge* fromEdge, const MSEdge* toEdge, bool includeInternal = true, int routePosition = 0) const;
142
154 double getDistanceBetween(double fromPos, double toPos, const MSRouteIterator& fromEdge, const MSRouteIterator& toEdge, bool includeInternal = true) const;
155
157 const RGBColor& getColor() const;
158
161 return myPeriod;
162 }
163
168 double getCosts() const {
169 return myCosts;
170 }
171
176 double getSavings() const {
177 return mySavings;
178 }
179
182 return myReplacedTime;
183 }
184
186 int getReplacedIndex() const {
187 return myReplacedIndex;
188 }
189
191 void setPeriod(SUMOTime period) {
192 myPeriod = period;
193 }
194
199 void setCosts(double costs) {
200 myCosts = costs;
201 }
206 void setSavings(double savings) {
207 mySavings = savings;
208 }
209
210 bool mustReroute() const {
211 return myReroute;
212 }
213
214 void setReroute(bool reroute = true) {
215 myReroute = reroute;
216 }
217
219 const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
220
221public:
231 static bool dictionary(const std::string& id, ConstMSRoutePtr route);
232
243 static bool dictionary(const std::string& id, RandomDistributor<ConstMSRoutePtr>* const routeDist, const bool permanent = true);
244
253 static ConstMSRoutePtr dictionary(const std::string& id, SumoRNG* rng = 0);
254
256 static bool hasRoute(const std::string& id);
257
265 static RandomDistributor<ConstMSRoutePtr>* distDictionary(const std::string& id);
266
268 static void clear();
269
271 static void checkDist(const std::string& id);
272
273 static void insertIDs(std::vector<std::string>& into);
274
275private:
278
280 const bool myAmPermanent;
281
283 const RGBColor* const myColor;
284
287
289 double myCosts;
290
292 double mySavings;
293
296
298 std::vector<SUMOVehicleParameter::Stop> myStops;
299
302
305
306private:
308 typedef std::map<std::string, ConstMSRoutePtr> RouteDict;
309
312
314 typedef std::map<std::string, std::pair<RandomDistributor<ConstMSRoutePtr>*, bool> > RouteDistDict;
315
318
319#ifdef HAVE_FOX
321 static FXMutex myDictMutex;
322#endif
323private:
326
327};
long long int SUMOTime
Definition: GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSRoute.h:54
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:56
std::vector< MSEdge * > MSEdgeVector
Definition: MSRoute.h:55
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition: MSRoute.h:57
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
static void dict_clearState()
Decrement all route references before quick-loading state.
Definition: MSRoute.cpp:297
bool myReroute
Whether this route is incomplete and requires rerouting.
Definition: MSRoute.h:295
double myCosts
The assigned or calculated costs.
Definition: MSRoute.h:289
void setReroute(bool reroute=true)
Definition: MSRoute.h:214
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:85
static RouteDistDict myDistDict
The dictionary container.
Definition: MSRoute.h:317
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition: MSRoute.cpp:257
const RGBColor *const myColor
The color.
Definition: MSRoute.h:283
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:124
static RouteDict myDict
The dictionary container.
Definition: MSRoute.h:311
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: MSRoute.h:298
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:406
int getReplacedIndex() const
Returns the index at which this route was replaced.
Definition: MSRoute.h:186
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:215
void setCosts(double costs)
Sets the costs of the route.
Definition: MSRoute.h:199
double getSavings() const
Returns the estimated savings due to using this route (compare to the route before rerouting)
Definition: MSRoute.h:176
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:308
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:251
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:103
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:301
SUMOTime myPeriod
The period when repeating this route.
Definition: MSRoute.h:286
ConstMSEdgeVector myEdges
The list of edges to pass.
Definition: MSRoute.h:277
static void insertIDs(std::vector< std::string > &into)
Definition: MSRoute.cpp:200
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes....
Definition: MSRoute.cpp:307
bool containsAnyOf(const MSEdgeVector &edgelist) const
Definition: MSRoute.cpp:239
int myReplacedIndex
The index where this route was replaced with an alternative route.
Definition: MSRoute.h:304
std::map< std::string, std::pair< RandomDistributor< ConstMSRoutePtr > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition: MSRoute.h:314
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:397
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:191
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:73
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
Definition: MSRoute.h:280
SUMOTime getReplacedTime() const
Returns the time at which this route was replaced (or -1)
Definition: MSRoute.h:181
bool mustReroute() const
Definition: MSRoute.h:210
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:292
MSRoute(const std::string &id, const ConstMSEdgeVector &edges, const bool isPermanent, const RGBColor *const c, const std::vector< SUMOVehicleParameter::Stop > &stops, SUMOTime replacedTime=-1, int replacedIndex=0)
Constructor.
Definition: MSRoute.cpp:49
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:160
void setSavings(double savings)
Sets the savings of the route.
Definition: MSRoute.h:206
double getCosts() const
Returns the costs of the route.
Definition: MSRoute.h:168
Base class for objects which have an id.
Definition: Named.h:54
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
An upper class for objects with additional parameters.
Definition: Parameterised.h:41