Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/vehicle/SUMOVehicle.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-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
/****************************************************************************/
14
/// @file SUMOVehicle.h
15
/// @author Michael Behrisch
16
/// @author Daniel Krajzewicz
17
/// @author Jakob Erdmann
18
/// @date Tue, 17 Feb 2009
19
///
20
// Abstract base class for vehicle representations
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <vector>
26
#include <typeinfo>
27
#include <utils/common/SUMOTime.h>
28
#include <utils/common/Named.h>
29
#include <utils/router/SUMOAbstractRouter.h>
30
#include <utils/vehicle/SUMOVehicleParameter.h>
31
#include <utils/vehicle/SUMOTrafficObject.h>
32
#include <utils/iodevices/OutputDevice.h>
33
34
35
// ===========================================================================
36
// class declarations
37
// ===========================================================================
38
class MSRoute;
39
class MSEdge;
40
class MSLane;
41
class MSPerson;
42
class MSStop;
43
class MSTransportable;
44
class MSParkingArea;
45
class MSChargingStation;
46
class MSStoppingPlace;
47
class MSVehicleDevice;
48
class SUMOSAXAttributes;
49
class EnergyParams;
50
class PositionVector;
51
52
typedef std::vector<const MSEdge*> ConstMSEdgeVector;
53
54
55
// ===========================================================================
56
// class definitions
57
// ===========================================================================
58
/**
59
* @class SUMOVehicle
60
* @brief Representation of a vehicle
61
*/
62
class SUMOVehicle : public SUMOTrafficObject {
63
public:
64
65
/// @brief Constructor
66
SUMOVehicle(const std::string& id) : SUMOTrafficObject(id) {}
67
68
/// @brief Destructor
69
virtual ~SUMOVehicle() {}
70
71
/** @brief Get the vehicle's lateral position on the lane
72
* @return The lateral position of the vehicle (in m relative to the
73
* centerline of the lane)
74
*/
75
virtual double getLateralPositionOnLane() const = 0;
76
77
/** @brief Get the vehicle's angle
78
* @return The angle of the vehicle (in degree)
79
*/
80
virtual double getAngle() const = 0;
81
82
/// Returns the current route
83
virtual const MSRoute& getRoute() const = 0;
84
85
/// Returns the current route
86
virtual ConstMSRoutePtr getRoutePtr() const = 0;
87
88
/** @brief Returns the nSuccs'th successor of edge the vehicle is currently at
89
*
90
* If the rest of the route (counted from the current edge) than nSuccs,
91
* 0 is returned.
92
* @param[in] nSuccs The number of edge to look forward
93
* @return The nSuccs'th following edge in the vehicle's route
94
*/
95
virtual const MSEdge* succEdge(int nSuccs) const = 0;
96
97
/** @brief Returns the starting point for reroutes (usually the current edge)
98
*
99
* This differs from myCurrEdge depending on braking distance and rail signals
100
* @return The rerouting start point
101
*/
102
virtual ConstMSEdgeVector::const_iterator getRerouteOrigin() const = 0;
103
104
/** @brief Replaces the current route by the given edges
105
*
106
* It is possible that the new route is not accepted, if a) it does not
107
* contain the vehicle's current edge, or b) something fails on insertion
108
* into the routes container (see in-line comments).
109
*
110
* @param[in] edges The new list of edges to pass
111
* @param[in] onInit Whether the vehicle starts with this route
112
* @param[in] check Whether the route should be checked for validity
113
* @param[in] removeStops Whether stops should be removed if they do not fit onto the new route
114
* @return Whether the new route was accepted
115
*/
116
virtual bool replaceRouteEdges(ConstMSEdgeVector& edges, double cost, double savings, const std::string& info, bool onInit = false, bool check = false, bool removeStops = true, std::string* msgReturn = nullptr) = 0;
117
118
/** @brief Performs a rerouting using the given router
119
*
120
* Tries to find a new route between the current edge and the destination edge, first.
121
* Tries to replace the current route by the new one using replaceRoute.
122
*
123
* @param[in] t The time for which the route is computed
124
* @param[in] router The router to use
125
* @return whether a valid route was found
126
* @see replaceRoute
127
*/
128
virtual bool reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false, const bool silent = false, const MSEdge* sink = nullptr) = 0;
129
130
/** @brief Validates the current or given route
131
* @param[out] msg Description why the route is not valid (if it is the case)
132
* @param[in] route The route to check (or 0 if the current route shall be checked)
133
* @return Whether the vehicle's current route is valid
134
*/
135
virtual bool hasValidRoute(std::string& msg, ConstMSRoutePtr route = 0) const = 0;
136
/// @brief checks wether the vehicle can depart on the first edge
137
virtual bool hasValidRouteStart(std::string& msg) = 0;
138
139
/// @brief computes validity attributes for the current route
140
virtual int getRouteValidity(bool update = true, bool silent = false, std::string* msgReturn = nullptr) = 0;
141
142
/** @brief Returns an iterator pointing to the current edge in this vehicles route
143
* @return The current route pointer
144
*/
145
virtual const ConstMSEdgeVector::const_iterator& getCurrentRouteEdge() const = 0;
146
147
/** @brief Returns the vehicle's emission model parameter
148
*
149
* @return The vehicle's emission parameters
150
*/
151
virtual EnergyParams* getEmissionParameters() const = 0;
152
153
/** @brief Replaces the vehicle's parameter
154
*/
155
virtual void replaceParameter(const SUMOVehicleParameter* newParameter) = 0;
156
157
/** @brief Called when the vehicle is inserted into the network
158
*
159
* Sets optional information about departure time, informs the vehicle
160
* control about a further running vehicle.
161
*/
162
virtual void onDepart() = 0;
163
164
/** @brief Returns the information whether the vehicle is on a road (is simulated)
165
* @return Whether the vehicle is simulated
166
*/
167
virtual bool isOnRoad() const = 0;
168
169
/** @brief Returns whether the vehicle is idling (waiting to re-enter the net
170
* @return true if the vehicle is waiting to enter the net (eg after parking)
171
*/
172
virtual bool isIdling() const = 0;
173
174
/** @brief Returns the information whether the front of the vehhicle is on the given lane
175
* @return Whether the vehicle's front is on that lane
176
*/
177
virtual bool isFrontOnLane(const MSLane*) const = 0;
178
179
/** @brief Returns the information whether the vehicle is parked
180
* @return Whether the vehicle is parked
181
*/
182
virtual bool isParking() const = 0;
183
184
/** @brief Returns the information whether the vehicle is fully controlled
185
* via TraCI
186
* @return Whether the vehicle is remote-controlled
187
*/
188
virtual bool isRemoteControlled() const = 0;
189
190
/** @brief Returns the information whether the vehicle is fully controlled
191
* via TraCI
192
* @return Whether the vehicle was remote-controlled within the given time range
193
*/
194
virtual bool wasRemoteControlled(SUMOTime lookBack = DELTA_T) const = 0;
195
196
/** @brief Returns this vehicle's real departure time
197
* @return This vehicle's real departure time
198
*/
199
virtual SUMOTime getDeparture() const = 0;
200
201
/** @brief Returns this vehicle's real departure position
202
* @return This vehicle's real departure position
203
*/
204
virtual double getDepartPos() const = 0;
205
206
/** @brief Returns this vehicle's desired arrivalPos for its current route
207
* (may change on reroute)
208
* @return This vehicle's real arrivalPos
209
*/
210
virtual double getArrivalPos() const = 0;
211
212
/** @brief Sets this vehicle's desired arrivalPos for its current route
213
*/
214
virtual void setArrivalPos(double arrivalPos) = 0;
215
216
/** @brief Returns whether this vehicle has departed
217
*/
218
virtual bool hasDeparted() const = 0;
219
220
/** @brief Returns the edge on which this vehicle shall depart
221
*/
222
virtual int getDepartEdge() const = 0;
223
224
/** @brief Returns the distance that was already driven by this vehicle
225
* @return the distance driven [m]
226
*/
227
virtual double getOdometer() const = 0;
228
229
/** @brief Returns the number of new routes this vehicle got
230
* @return the number of new routes this vehicle got
231
*/
232
virtual int getNumberReroutes() const = 0;
233
234
/// @brief whether the given transportable is allowed to board this vehicle
235
virtual bool allowsBoarding(const MSTransportable* t) const = 0;
236
237
/** @brief Adds a person or container to this vehicle
238
*
239
* @param[in] transportable The person/container to add
240
*/
241
virtual void addTransportable(MSTransportable* transportable) = 0;
242
243
/** @brief Returns the number of persons
244
* @return The number of passengers on-board
245
*/
246
virtual int getPersonNumber() const = 0;
247
248
/** @brief Returns the list of persons
249
* @return The list of passengers on-board
250
*/
251
virtual std::vector<std::string> getPersonIDList() const = 0;
252
253
/** @brief Returns the number of containers
254
* @return The number of contaiers on-board
255
*/
256
virtual int getContainerNumber() const = 0;
257
258
/// @brief removes a person or container
259
virtual void removeTransportable(MSTransportable* t) = 0;
260
261
/// @brief retrieve riding persons
262
virtual const std::vector<MSTransportable*>& getPersons() const = 0;
263
264
/// @brief retrieve riding containers
265
virtual const std::vector<MSTransportable*>& getContainers() const = 0;
266
267
/** @brief Adds a stop
268
*
269
* The stop is put into the sorted list.
270
* @param[in] stop The stop to add
271
* @return Whether the stop could be added
272
*/
273
virtual bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0,
274
ConstMSEdgeVector::const_iterator* searchStart = 0) = 0;
275
276
/// @brief return list of route indices and stop positions for the remaining stops
277
virtual std::vector<std::pair<int, double> > getStopIndices() const = 0;
278
279
/// @brief returns whether the vehicle serves a public transport line that serves the given stop
280
virtual bool isLineStop(double position) const = 0;
281
282
/// @brief deletes the next stop at the given index if it exists
283
virtual bool abortNextStop(int nextStopIndex = 0) = 0;
284
285
286
/**
287
* returns the next imminent stop in the stop queue
288
* @return the upcoming stop
289
*/
290
virtual MSParkingArea* getNextParkingArea() = 0;
291
292
/** @brief Replaces a stop
293
*
294
* The stop replace the next stop into the sorted list.
295
* @param[in] stop The stop to add
296
* @return Whether the stop could be added
297
*/
298
virtual bool replaceParkingArea(MSParkingArea* parkingArea, std::string& errorMsg) = 0;
299
300
virtual const std::vector<std::string>& getParkingBadges() const = 0;
301
302
/// @brief Returns the remaining stop duration for a stopped vehicle or 0
303
virtual SUMOTime remainingStopDuration() const = 0;
304
305
/** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue
306
*/
307
virtual bool isStopped() const = 0;
308
/** @brief Returns whether the vehicle is at a stop and waiting for a person or container to continue
309
*/
310
virtual bool isStoppedTriggered() const = 0;
311
312
/** @brief Returns whether the vehicle is at a stop and parking
313
*/
314
virtual bool isStoppedParking() const = 0;
315
316
/** @brief Returns whether the vehicle is stopped in the range of the given position */
317
virtual bool isStoppedInRange(const double pos, const double tolerance, bool checkFuture = false) const = 0;
318
319
/** @brief Returns whether the vehicle stops at the given stopping place */
320
virtual bool stopsAt(MSStoppingPlace* stop) const = 0;
321
322
/** @brief Returns whether the vehicle stops at the given edge */
323
virtual bool stopsAtEdge(const MSEdge* edge) const = 0;
324
325
/** @brief Returns whether the vehicle has to stop somewhere
326
* @return Whether the vehicle has to stop somewhere
327
*/
328
virtual bool hasStops() const = 0;
329
330
/**
331
* returns the list of stops not yet reached in the stop queue
332
* @return the list of upcoming stops
333
*/
334
virtual const std::list<MSStop>& getStops() const = 0;
335
336
/**
337
* returns the next imminent stop in the stop queue
338
* @return the upcoming stop
339
*/
340
virtual const MSStop& getNextStop() const = 0;
341
342
/**
343
* returns the next imminent stop in the stop queue
344
* @return the upcoming stop
345
*/
346
virtual MSStop& getNextStopMutable() = 0;
347
348
/// @brief mark vehicle as active
349
virtual void unregisterWaiting() = 0;
350
351
/** @brief Returns parameters of the next stop or nullptr **/
352
virtual const SUMOVehicleParameter::Stop* getNextStopParameter() const = 0;
353
354
/// @brief get remaining stop duration or 0 if the vehicle isn't stopped
355
virtual SUMOTime getStopDuration() const = 0;
356
357
/**
358
* schedule a new stop for the vehicle; each time a stop is reached, the vehicle
359
* will wait for the given duration before continuing on its route
360
* @param[in] stop Stop parameters
361
* @param[out] errorMsg returned error message
362
*/
363
virtual bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string& errorMsg) = 0;
364
365
virtual void setChosenSpeedFactor(const double factor) = 0;
366
367
virtual SUMOTime getDepartDelay() const = 0;
368
369
virtual SUMOTime getTimeLoss() const = 0;
370
371
/// @brief get distance for coming to a stop (used for rerouting checks)
372
virtual double getBrakeGap(bool delayed = false) const = 0;
373
374
/// @brief Returns this vehicles impatience
375
virtual double getImpatience() const = 0;
376
377
/** @brief Returns this vehicle's devices
378
* @return This vehicle's devices
379
*/
380
virtual const std::vector<MSVehicleDevice*>& getDevices() const = 0;
381
382
/// @brief Returns the vehicles's length
383
virtual double getLength() const = 0;
384
385
/* @brief Return whether this vehicle must be treated like a railway vehicle
386
* either due to its vClass or the vClass of it's edge */
387
virtual bool isRail() const = 0;
388
389
virtual SUMOTime getLastActionTime() const = 0;
390
391
/// @brief get bounding rectangle
392
virtual PositionVector getBoundingBox(double offset = 0) const = 0;
393
394
/// @name parking memory io
395
//@{
396
virtual void rememberBlockedParkingArea(const MSStoppingPlace* pa, bool local) = 0;
397
virtual SUMOTime sawBlockedParkingArea(const MSStoppingPlace* pa, bool local) const = 0;
398
virtual void rememberParkingAreaScore(const MSStoppingPlace* pa, const std::string& score) = 0;
399
virtual void resetParkingAreaScores() = 0;
400
virtual int getNumberParkingReroutes() const = 0;
401
virtual void setNumberParkingReroutes(int value) = 0;
402
403
virtual void rememberBlockedChargingStation(const MSStoppingPlace* cs, bool local) = 0;
404
virtual SUMOTime sawBlockedChargingStation(const MSStoppingPlace* cs, bool local) const = 0;
405
virtual void rememberChargingStationScore(const MSStoppingPlace* cs, const std::string& score) = 0;
406
virtual void resetChargingStationScores() = 0;
407
//@}
408
409
/// @name state io
410
//@{
411
412
/// Saves the states of a vehicle
413
virtual void saveState(OutputDevice& out) = 0;
414
415
/** @brief Loads the state of this vehicle from the given description
416
*/
417
virtual void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset) = 0;
418
//@}
419
};
420
421