Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MEVehicle.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 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/****************************************************************************/
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 <limits>
26#include <vector>
28#include <microsim/MSEdge.h>
30#include "MESegment.h"
31
32class MSLane;
33class MSLink;
34
35// ===========================================================================
36// class definitions
37// ===========================================================================
42class MEVehicle : public MSBaseVehicle {
43public:
52 MSVehicleType* type, const double speedFactor);
53
54
58 double getPositionOnLane() const;
59
60
64 double getBackPositionOnLane(const MSLane* lane) const;
65
66
70 double getAngle() const;
71
72
76 double getSlope() const;
77
81 const MSEdge* getCurrentEdge() const;
82
86 const MSLane* getLane() const {
87 return nullptr;
88 }
89
90 const MSLane* getBackLane() const {
91 return nullptr;
92 }
93
101 Position getPosition(const double offset = 0) const;
102
104 PositionVector getBoundingBox(double offset = 0) const;
105
110 double getSpeed() const;
111
116 double getAverageSpeed() const;
117
119 double estimateLeaveSpeed(const MSLink* link) const;
120
121
127 double getConservativeSpeed(SUMOTime& earliestArrival) const;
128
130
131
141
142
146 bool moveRoutePointer();
147
151 bool hasArrived() const;
152
156 bool isOnRoad() const;
157
161 virtual bool isIdling() const;
162
163
168 void setApproaching(MSLink* link);
169
172 return 0;
173 }
174
175 bool instantStopping() const {
176 return true;
177 }
178
180 bool endTriggeredStop();
181
183 void processStop();
184
190
195 bool resumeFromStopping();
196
198 double getBrakeGap(bool delayed = false) const {
199 UNUSED_PARAMETER(delayed);
200 return mySegment == nullptr || myQueIndex == MESegment::PARKING_QUEUE ? 0 : mySegment->getLength();
201 }
202
206 inline void setEventTime(SUMOTime t, bool hasDelay = true) {
207 assert(t > myLastEntryTime);
208 if (hasDelay && mySegment != nullptr) {
210 }
211 myEventTime = t;
212 }
213
214
218 inline SUMOTime getEventTime() const {
219 return myEventTime;
220 }
221
223 inline void setEventIndex(long long int index) {
224 myEventIndex = index;
225 }
226
228 inline long long int getEventIndex() const {
229 return myEventIndex;
230 }
231
237 }
242 return myUnqueuedEventTime;
243 }
244
245
250 inline virtual void setSegment(MESegment* s, int idx = 0) {
253 }
255 mySegment = s;
256 myQueIndex = idx;
259 }
260 }
261
262
266 inline MESegment* getSegment() const {
267 return mySegment;
268 }
269
270 int getSegmentIndex() const;
271
275 inline int getQueIndex() const {
276 return myQueIndex;
277 }
278
280 double getMesoPosition() const {
281 return myMesoPosition;
282 }
283
285 void setMesoPosition(double pos, int overlap) {
286 myMesoPosition = pos;
287 myMesoPositionOverlap = overlap;
288 }
289
293 }
294
297 myMesoPosition = -std::numeric_limits<double>::max();
298 }
299
305 double getRightSideOnEdge(const MSLane* /*lane*/) const;
306
310 inline void setLastEntryTime(SUMOTime t) {
311 myLastEntryTime = t;
312 }
313
314
319 return myLastEntryTime;
320 }
321
326 return SIMSTEP;
327 }
328
332 inline void setBlockTime(const SUMOTime t) {
333 assert(t > myLastEntryTime);
334 myBlockTime = t;
335 }
336
337
341 inline SUMOTime getBlockTime() const {
342 return myBlockTime;
343 }
344
345
347 inline SUMOTime getWaitingTime(const bool accumulated = false) const {
348 UNUSED_PARAMETER(accumulated);
349 return MAX2(SUMOTime(0), myEventTime - myBlockTime);
350 }
351
355 }
356
357 inline SUMOTime getTimeLoss() const {
358 // slow-downs while driving are not modelled
359 return getWaitingTime();
360 }
361
363 double getEventTimeSeconds() const {
364 return STEPS2TIME(getEventTime());
365 }
366
368 double getLastEntryTimeSeconds() const {
370 }
371
373 double getBlockTimeSeconds() const {
374 return STEPS2TIME(getBlockTime());
375 }
376
378 double getCurrentLinkPenaltySeconds() const;
379
381 double getCurrentStoppingTimeSeconds() const;
382
384 bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addRouteStops = true, bool removeStops = true, std::string* msgReturn = nullptr);
385
389 int mayProceed();
390
393 void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
394
397 void updateDetectors(const SUMOTime currentTime, const SUMOTime exitTime, const bool isLeave,
399
405 BaseInfluencer& getBaseInfluencer();
406
407 const BaseInfluencer* getBaseInfluencer() const;
408
409 bool hasInfluencer() const {
410 return myInfluencer != nullptr;
411 }
412
413 void markJammed(bool jammed) {
414 myWasJammed = jammed;
415 }
416
417 bool wasJammed() const {
418 return myWasJammed;
419 }
420
422
423
425 void saveState(OutputDevice& out);
426
429 void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
431
432
433protected:
436
439
442
444 long long int myEventIndex;
445
448
451
454
457
459 double myMesoPosition = -std::numeric_limits<double>::max();
460
463
466
467};
long long int SUMOTime
Definition GUI.h:36
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SIMSTEP
Definition SUMOTime.h:69
T MAX2(T a, T b)
Definition StdDefs.h:86
A single mesoscopic segment (cell)
Definition MESegment.h:50
static const int PARKING_QUEUE
Definition MESegment.h:53
double getLength() const
Returns the length of the segment in meters.
Definition MESegment.h:282
void invalidateMesoPositions() const
Invalidate the cached interpolated positions.
Definition MESegment.h:253
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition MESegment.h:405
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
Definition MESegment.h:498
A vehicle from the mesoscopic point of view.
Definition MEVehicle.h:42
double getConservativeSpeed(SUMOTime &earliestArrival) const
Returns the vehicle's estimated speed taking into account delays.
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition MEVehicle.h:368
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition MEVehicle.h:373
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
Definition MEVehicle.h:409
double getAverageSpeed() const
Returns the vehicle's estimated average speed on the segment assuming no further delays.
SUMOTime getLastActionTime() const
Returns the time of the vehicle's last action point.
Definition MEVehicle.h:325
double getAngle() const
Returns the vehicle's direction in degrees.
Definition MEVehicle.cpp:91
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
Definition MEVehicle.cpp:72
int myMesoPositionOverlap
The lateral offset used to visualize overlapping mesoscopic vehicles.
Definition MEVehicle.h:462
bool replaceRoute(ConstMSRoutePtr route, const std::string &info, bool onInit=false, int offset=0, bool addRouteStops=true, bool removeStops=true, std::string *msgReturn=nullptr)
Replaces the current route by the given one.
SUMOTime myEventTime
The (planned) time of leaving the segment (cell)
Definition MEVehicle.h:441
const MSLane * getBackLane() const
Returns the lane the where the rear of the object is currently at.
Definition MEVehicle.h:90
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
BaseInfluencer & getBaseInfluencer()
Returns the velocity/lane influencer.
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
void markJammed(bool jammed)
Definition MEVehicle.h:413
double getBrakeGap(bool delayed=false) const
get distance for coming to a stop (used for rerouting checks)
Definition MEVehicle.h:198
long long int myEventIndex
The index of the vehicle's event (orders events with the same time)
Definition MEVehicle.h:444
double estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving across the link.
void processStop()
ends the current stop and performs loading/unloading
SUMOTime getWaitingTime(const bool accumulated=false) const
Returns the duration for which the vehicle was blocked.
Definition MEVehicle.h:347
bool hasArrived() const
Returns whether this vehicle has already arrived (reached the arrivalPosition on its final edge)
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
double getMesoPosition() const
Returns the cached interpolated mesoscopic position.
Definition MEVehicle.h:280
long long int getEventIndex() const
Returns the index of the vehicle's event.
Definition MEVehicle.h:228
int myQueIndex
Index of the que the vehicle is in (important for multiqueue extension)
Definition MEVehicle.h:438
bool instantStopping() const
whether instant stopping is permitted
Definition MEVehicle.h:175
int getMesoPositionOverlap() const
Returns the lateral offset used to visualize overlapping mesoscopic vehicles.
Definition MEVehicle.h:291
void updateDetectors(const SUMOTime currentTime, const SUMOTime exitTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
SUMOTime checkStop(SUMOTime time)
Returns until when to stop at the current segment and sets the information that the stop has been rea...
void setUnqueuedEventTime(SUMOTime t)
Sets the minimum time at which the vehicle leaves its current segment (this includes planned stops)
Definition MEVehicle.h:235
virtual bool isIdling() const
Returns whether the vehicle is trying to re-enter the net.
double myMesoPosition
The interpolated mesoscopic position on the current edge (-maxdouble when invalid)
Definition MEVehicle.h:459
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition MEVehicle.h:318
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition MEVehicle.cpp:78
SUMOTime myLastEntryTime
The time the vehicle entered its current segment.
Definition MEVehicle.h:447
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves its current segment.
Definition MEVehicle.h:206
BaseInfluencer * myInfluencer
An instance of a velocity/lane influencing instance; built in "getInfluencer".
Definition MEVehicle.h:465
SUMOTime getQueuingTimeLoss() const
Returns the time lost compare to free flow.
Definition MEVehicle.h:353
void setMesoPosition(double pos, int overlap)
Sets the interpolated position and lateral overlap offset.
Definition MEVehicle.h:285
void setApproaching(MSLink *link)
registers vehicle with the given link
bool endTriggeredStop()
process triggered stops and return true if all stops on the current segment are completed
void saveState(OutputDevice &out)
Saves the states of a vehicle.
SUMOTime getTimeLoss() const
Definition MEVehicle.h:357
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition MEVehicle.h:266
const MSEdge * getCurrentEdge() const
Returns the edge the vehicle is currently at (possibly an internal edge)
bool wasJammed() const
Definition MEVehicle.h:417
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition MEVehicle.h:310
MESegment * mySegment
The segment the vehicle is at.
Definition MEVehicle.h:435
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition MEVehicle.h:275
int getSegmentIndex() const
void setEventIndex(long long int index)
Sets the index of the vehicle's event (orders events with the same time)
Definition MEVehicle.h:223
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MEVehicle.h:86
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition MEVehicle.h:250
bool myWasJammed
Whether this vehicle was jammed on it's previous normal segment.
Definition MEVehicle.h:456
SUMOTime remainingStopDuration() const
Returns the remaining stop duration for a stopped vehicle or 0.
Definition MEVehicle.h:171
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
int mayProceed()
Returns whether the vehicle is allowed to pass the next junction, checks also for triggered stops.
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves its current segment.
Definition MEVehicle.h:218
void invalidateMesoPosition()
Invalidates the cached interpolated position.
Definition MEVehicle.h:296
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition MEVehicle.h:332
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
SUMOTime myUnqueuedEventTime
The expected time of leaving the segment when following the leader at free-flow headway.
Definition MEVehicle.h:453
bool resumeFromStopping()
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
PositionVector getBoundingBox(double offset=0) const
get bounding rectangle
SUMOTime getUnqueuedEventTime() const
Returns the minimum time at which the vehicle leaves its current segment.
Definition MEVehicle.h:241
double getSlope() const
Returns the slope of the road at vehicle's position in degrees.
Definition MEVehicle.cpp:98
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition MEVehicle.h:363
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition MEVehicle.h:450
double getRightSideOnEdge(const MSLane *) const
Get the vehicle's lateral position on the edge of the given lane (or its current edge if lane == 0)
SUMOTime getBlockTime() const
Returns the time at which the vehicle was blocked.
Definition MEVehicle.h:341
The base class for microscopic and mesoscopic vehicles.
A road/street connecting two junctions.
Definition MSEdge.h:78
void markDelayed() const
Definition MSEdge.h:751
Representation of a lane in the micro simulation.
Definition MSLane.h:84
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
The car-following model and parameter.
Static storage of an output device and its base (abstract) implementation.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
Encapsulated SAX-Attributes.
Structure representing possible vehicle parameter.
#define UNUSED_PARAMETER(x)