Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/mesosim/MEVehicle.h
169667 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 MEVehicle.h
15
/// @author Daniel Krajzewicz
16
/// @date Tue, May 2005
17
///
18
// A vehicle from the mesoscopic point of view
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <iostream>
24
#include <cassert>
25
#include <map>
26
#include <vector>
27
#include <microsim/MSBaseVehicle.h>
28
#include <microsim/MSEdge.h>
29
#include <utils/common/StdDefs.h>
30
#include "MESegment.h"
31
32
class MSLane;
33
class MSLink;
34
35
// ===========================================================================
36
// class definitions
37
// ===========================================================================
38
/**
39
* @class MEVehicle
40
* @brief A vehicle from the mesoscopic point of view
41
*/
42
class MEVehicle : public MSBaseVehicle {
43
public:
44
/** @brief Constructor
45
* @param[in] pars The vehicle description
46
* @param[in] route The vehicle's route
47
* @param[in] type The vehicle's type
48
* @param[in] speedFactor The factor for driven lane's speed limits
49
* @exception ProcessError If a value is wrong
50
*/
51
MEVehicle(SUMOVehicleParameter* pars, ConstMSRoutePtr route,
52
MSVehicleType* type, const double speedFactor);
53
54
55
/** @brief Get the vehicle's position along the lane
56
* @return The position of the vehicle (in m from the lane's begin)
57
*/
58
double getPositionOnLane() const;
59
60
61
/** @brief Get the vehicle's position relative to the given lane
62
* @return The back position of the vehicle (in m from the given lane's begin)
63
*/
64
double getBackPositionOnLane(const MSLane* lane) const;
65
66
67
/** @brief Returns the vehicle's direction in degrees
68
* @return The vehicle's current angle
69
*/
70
double getAngle() const;
71
72
73
/** @brief Returns the slope of the road at vehicle's position in degrees
74
* @return The slope
75
*/
76
double getSlope() const;
77
78
/** @brief Returns the lane the vehicle is on
79
* @return The vehicle's current lane
80
*/
81
const MSLane* getLane() const {
82
return nullptr;
83
}
84
85
const MSLane* getBackLane() const {
86
return nullptr;
87
}
88
89
/** @brief Return current position (x/y, cartesian)
90
*
91
* If the vehicle's myLane is 0, Position::INVALID.
92
* @param[in] offset optional offset in longitudinal direction
93
* @return The current position (in cartesian coordinates)
94
* @see myLane
95
*/
96
Position getPosition(const double offset = 0) const;
97
98
/// @brief get bounding rectangle
99
PositionVector getBoundingBox(double offset = 0) const;
100
101
/** @brief Returns the vehicle's estimated speed assuming no delays
102
* @return The vehicle's estimated speed
103
* @note This is only an upper bound. The speed will be lower if the preceding vehicle is delayed
104
*/
105
double getSpeed() const;
106
107
/** @brief Returns the vehicle's estimated average speed on the segment assuming no further delays
108
* @return The vehicle's estimated average speed
109
* @note This is only an upper bound. The speed will be lower if the preceding vehicle is delayed
110
*/
111
double getAverageSpeed() const;
112
113
/// @brief Returns the vehicle's estimated speed after driving across the link
114
double estimateLeaveSpeed(const MSLink* link) const;
115
116
117
/** @brief Returns the vehicle's estimated speed taking into account delays
118
* @return The vehicle's estimated speed
119
* @param[in, out] earliestArrival A lower bound on leaveTime, modified to contain new lower bound on leave Time
120
* @note This is only an upper bound. The speed may be even lower if there are further delays downstream
121
*/
122
double getConservativeSpeed(SUMOTime& earliestArrival) const;
123
124
/// @name insertion/removal
125
//@{
126
127
/** @brief Called when the vehicle is removed from the network.
128
*
129
* Moves along work reminders and
130
* informs all devices about quitting. Calls "leaveLane" then.
131
*
132
* @param[in] reason why the vehicle leaves (reached its destination, parking, teleport)
133
*/
134
void onRemovalFromNet(const MSMoveReminder::Notification reason);
135
//@}
136
137
138
/** @brief Update when the vehicle enters a new edge in the move step.
139
* @return Whether the vehicle's route has ended (due to vaporization, or because the destination was reached)
140
*/
141
bool moveRoutePointer();
142
143
/** @brief Returns whether this vehicle has already arrived
144
* (reached the arrivalPosition on its final edge)
145
*/
146
bool hasArrived() const;
147
148
/** @brief Returns the information whether the vehicle is on a road (is simulated)
149
* @return Whether the vehicle is simulated
150
*/
151
bool isOnRoad() const;
152
153
/** @brief Returns whether the vehicle is trying to re-enter the net
154
* @return true if the vehicle is trying to enter the net (eg after parking)
155
*/
156
virtual bool isIdling() const;
157
158
159
/** @brief registers vehicle with the given link
160
*
161
* @param[in] link the link on which the car shall register its approach
162
*/
163
void setApproaching(MSLink* link);
164
165
/// @brief Returns the remaining stop duration for a stopped vehicle or 0
166
SUMOTime remainingStopDuration() const {
167
return 0;
168
}
169
170
///@brief ends the current stop and performs loading/unloading
171
void processStop();
172
173
/** @brief Returns until when to stop at the current segment and sets the information that the stop has been reached
174
* @param[in] time the current time
175
* @return stop time for the segment
176
*/
177
SUMOTime checkStop(SUMOTime time);
178
179
/**
180
* resumes a vehicle from stopping
181
* @return true on success, the resuming fails if the vehicle wasn't parking in the first place
182
*/
183
bool resumeFromStopping();
184
185
/// @brief get distance for coming to a stop (used for rerouting checks)
186
double getBrakeGap(bool delayed = false) const {
187
UNUSED_PARAMETER(delayed);
188
return mySegment == nullptr || myQueIndex == MESegment::PARKING_QUEUE ? 0 : mySegment->getLength();
189
}
190
191
/** @brief Sets the (planned) time at which the vehicle leaves its current segment
192
* @param[in] t The leaving time
193
*/
194
inline void setEventTime(SUMOTime t, bool hasDelay = true) {
195
assert(t > myLastEntryTime);
196
if (hasDelay && mySegment != nullptr) {
197
mySegment->getEdge().markDelayed();
198
}
199
myEventTime = t;
200
}
201
202
203
/** @brief Returns the (planned) time at which the vehicle leaves its current segment
204
* @return The time the vehicle thinks it leaves its segment at
205
*/
206
inline SUMOTime getEventTime() const {
207
return myEventTime;
208
}
209
210
211
/** @brief Sets the current segment the vehicle is at together with its que
212
* @param[in] s The current segment
213
* @param[in] q The current que
214
*/
215
inline virtual void setSegment(MESegment* s, int idx = 0) {
216
mySegment = s;
217
myQueIndex = idx;
218
}
219
220
221
/** @brief Returns the current segment the vehicle is on
222
* @return The segment the vehicle is on
223
*/
224
inline MESegment* getSegment() const {
225
return mySegment;
226
}
227
228
int getSegmentIndex() const;
229
230
/** @brief Returns the index of the que the vehicle is in
231
* @return The que index
232
*/
233
inline int getQueIndex() const {
234
return myQueIndex;
235
}
236
237
/** @brief Get the vehicle's lateral position on the edge of the given lane
238
* (or its current edge if lane == 0)
239
* @return The lateral position of the vehicle (in m distance between right
240
* side of vehicle and ride side of edge
241
*/
242
double getRightSideOnEdge(const MSLane* /*lane*/) const;
243
244
/** @brief Sets the entry time for the current segment
245
* @param[in] t The entry time
246
*/
247
inline void setLastEntryTime(SUMOTime t) {
248
myLastEntryTime = t;
249
}
250
251
252
/** @brief Returns the time the vehicle entered the current segment
253
* @return The entry time
254
*/
255
SUMOTime getLastEntryTime() const {
256
return myLastEntryTime;
257
}
258
259
/** @brief Returns the time of the vehicle's last action point.
260
* @return The time of the last action point
261
*/
262
SUMOTime getLastActionTime() const {
263
return SIMSTEP;
264
}
265
266
/** @brief Sets the time at which the vehicle was blocked
267
* @param[in] t The blocking time
268
*/
269
inline void setBlockTime(const SUMOTime t) {
270
assert(t > myLastEntryTime);
271
myBlockTime = t;
272
}
273
274
275
/** @brief Returns the time at which the vehicle was blocked
276
* @return The blocking time
277
*/
278
inline SUMOTime getBlockTime() const {
279
return myBlockTime;
280
}
281
282
283
/// @brief Returns the duration for which the vehicle was blocked
284
inline SUMOTime getWaitingTime(const bool accumulated = false) const {
285
UNUSED_PARAMETER(accumulated);
286
return MAX2(SUMOTime(0), myEventTime - myBlockTime);
287
}
288
289
inline SUMOTime getTimeLoss() const {
290
// slow-downs while driving are not modelled
291
return getWaitingTime();
292
}
293
294
/// @brief Returns the earliest leave time for the current segment
295
double getEventTimeSeconds() const {
296
return STEPS2TIME(getEventTime());
297
}
298
299
/// @brief Returns the entry time for the current segment
300
double getLastEntryTimeSeconds() const {
301
return STEPS2TIME(getLastEntryTime());
302
}
303
304
/// @brief Returns the time at which the vehicle was blocked on the current segment
305
double getBlockTimeSeconds() const {
306
return STEPS2TIME(getBlockTime());
307
}
308
309
/// @brief Returns the delay that is accrued due to option --meso-tls-penalty or --meso-minor-penalty
310
double getCurrentLinkPenaltySeconds() const;
311
312
/// @brief Returns the delay that is accrued due to option --meso-tls-penalty or --meso-minor-penalty
313
double getCurrentStoppingTimeSeconds() const;
314
315
/// Replaces the current route by the given one
316
bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addRouteStops = true, bool removeStops = true, std::string* msgReturn = nullptr);
317
318
/** @brief Returns whether the vehicle is allowed to pass the next junction, checks also for triggered stops
319
* @return true iff the vehicle may drive over the next junction
320
*/
321
bool mayProceed();
322
323
/** @brief Updates a single vehicle detector if present
324
*/
325
void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
326
327
/** @brief Updates all vehicle detectors
328
*/
329
void updateDetectors(SUMOTime currentTime, const bool isLeave,
330
const MSMoveReminder::Notification reason = MSMoveReminder::NOTIFICATION_JUNCTION);
331
332
/** @brief Returns the velocity/lane influencer
333
*
334
* If no influencer was existing before, one is built, first
335
* @return Reference to this vehicle's speed influencer
336
*/
337
BaseInfluencer& getBaseInfluencer();
338
339
const BaseInfluencer* getBaseInfluencer() const;
340
341
bool hasInfluencer() const {
342
return myInfluencer != nullptr;
343
}
344
345
/// @name state io
346
//@{
347
348
/// Saves the states of a vehicle
349
void saveState(OutputDevice& out);
350
351
/** @brief Loads the state of this vehicle from the given description
352
*/
353
void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
354
//@}
355
356
357
protected:
358
/// @brief The segment the vehicle is at
359
MESegment* mySegment;
360
361
/// @brief Index of the que the vehicle is in (important for multiqueue extension)
362
int myQueIndex;
363
364
/// @brief The (planned) time of leaving the segment (cell)
365
SUMOTime myEventTime;
366
367
/// @brief The time the vehicle entered its current segment
368
SUMOTime myLastEntryTime;
369
370
/// @brief The time at which the vehicle was blocked on its current segment
371
SUMOTime myBlockTime;
372
373
/// @brief An instance of a velocity/lane influencing instance; built in "getInfluencer"
374
BaseInfluencer* myInfluencer;
375
376
};
377
378