Eclipse SUMO - Simulation of Urban MObility
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-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 /****************************************************************************/
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 // ===========================================================================
42 class MEVehicle : public MSBaseVehicle {
43 public:
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 MSLane* getLane() const {
82  return nullptr;
83  }
84 
92  Position getPosition(const double offset = 0) const;
93 
95  PositionVector getBoundingBox(double offset = 0) const;
96 
101  double getSpeed() const;
102 
107  double getAverageSpeed() const;
108 
110  double estimateLeaveSpeed(const MSLink* link) const;
111 
112 
118  double getConservativeSpeed(SUMOTime& earliestArrival) const;
119 
121 
122 
132 
133 
137  bool moveRoutePointer();
138 
142  bool hasArrived() const;
143 
147  bool isOnRoad() const;
148 
152  virtual bool isIdling() const;
153 
154 
159  void setApproaching(MSLink* link);
160 
163  return 0;
164  }
165 
167  void processStop();
168 
174 
179  bool resumeFromStopping();
180 
182  double getBrakeGap(bool delayed = false) const {
183  UNUSED_PARAMETER(delayed);
184  return mySegment == nullptr || myQueIndex == MESegment::PARKING_QUEUE ? 0 : mySegment->getLength();
185  }
186 
190  inline void setEventTime(SUMOTime t, bool hasDelay = true) {
191  assert(t > myLastEntryTime);
192  if (hasDelay && mySegment != nullptr) {
194  }
195  myEventTime = t;
196  }
197 
198 
202  inline SUMOTime getEventTime() const {
203  return myEventTime;
204  }
205 
206 
211  inline virtual void setSegment(MESegment* s, int idx = 0) {
212  mySegment = s;
213  myQueIndex = idx;
214  }
215 
216 
220  inline MESegment* getSegment() const {
221  return mySegment;
222  }
223 
224 
228  inline int getQueIndex() const {
229  return myQueIndex;
230  }
231 
237  double getRightSideOnEdge(const MSLane* /*lane*/) const;
238 
242  inline void setLastEntryTime(SUMOTime t) {
243  myLastEntryTime = t;
244  }
245 
246 
251  return myLastEntryTime;
252  }
253 
258  return SIMSTEP;
259  }
260 
264  inline void setBlockTime(const SUMOTime t) {
265  assert(t > myLastEntryTime);
266  myBlockTime = t;
267  }
268 
269 
273  inline SUMOTime getBlockTime() const {
274  return myBlockTime;
275  }
276 
277 
279  inline SUMOTime getWaitingTime(const bool accumulated = false) const {
280  UNUSED_PARAMETER(accumulated);
281  return MAX2(SUMOTime(0), myEventTime - myBlockTime);
282  }
283 
284  inline SUMOTime getTimeLoss() const {
285  // slow-downs while driving are not modelled
286  return getWaitingTime();
287  }
288 
290  double getEventTimeSeconds() const {
291  return STEPS2TIME(getEventTime());
292  }
293 
295  double getLastEntryTimeSeconds() const {
296  return STEPS2TIME(getLastEntryTime());
297  }
298 
300  double getBlockTimeSeconds() const {
301  return STEPS2TIME(getBlockTime());
302  }
303 
305  double getCurrentLinkPenaltySeconds() const;
306 
308  double getCurrentStoppingTimeSeconds() const;
309 
311  bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addRouteStops = true, bool removeStops = true, std::string* msgReturn = nullptr);
312 
316  bool mayProceed();
317 
320  void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
321 
324  void updateDetectors(SUMOTime currentTime, const bool isLeave,
326 
332  BaseInfluencer& getBaseInfluencer();
333 
334  const BaseInfluencer* getBaseInfluencer() const;
335 
336  bool hasInfluencer() const {
337  return myInfluencer != nullptr;
338  }
339 
341 
342 
344  void saveState(OutputDevice& out);
345 
348  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
350 
351 
352 protected:
355 
358 
361 
364 
367 
370 
371 };
long long int SUMOTime
Definition: GUI.h:35
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition: Route.h:31
#define STEPS2TIME(x)
Definition: SUMOTime.h:55
#define SIMSTEP
Definition: SUMOTime.h:61
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
T MAX2(T a, T b)
Definition: StdDefs.h:82
A single mesoscopic segment (cell)
Definition: MESegment.h:49
static const int PARKING_QUEUE
Definition: MESegment.h:52
double getLength() const
Returns the length of the segment in meters.
Definition: MESegment.h:242
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:359
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.
Definition: MEVehicle.cpp:149
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:295
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:300
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MEVehicle.cpp:94
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
Definition: MEVehicle.h:336
double getAverageSpeed() const
Returns the vehicle's estimated average speed on the segment assuming no further delays.
Definition: MEVehicle.cpp:129
SUMOTime getLastActionTime() const
Returns the time of the vehicle's last action point.
Definition: MEVehicle.h:257
double getAngle() const
Returns the vehicle's direction in degrees.
Definition: MEVehicle.cpp:80
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
Definition: MEVehicle.cpp:66
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.
Definition: MEVehicle.cpp:210
SUMOTime myEventTime
The (planned) time of leaving the segment (cell)
Definition: MEVehicle.h:360
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MEVehicle.cpp:514
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
Definition: MEVehicle.cpp:444
MEVehicle(SUMOVehicleParameter *pars, ConstMSRoutePtr route, MSVehicleType *type, const double speedFactor)
Constructor.
Definition: MEVehicle.cpp:53
BaseInfluencer & getBaseInfluencer()
Returns the velocity/lane influencer.
Definition: MEVehicle.cpp:499
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:317
double getBrakeGap(bool delayed=false) const
get distance for coming to a stop (used for rerouting checks)
Definition: MEVehicle.h:182
bool mayProceed()
Returns whether the vehicle is allowed to pass the next junction, checks also for triggered stops.
Definition: MEVehicle.cpp:366
double estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving accross the link.
Definition: MEVehicle.cpp:140
void processStop()
ends the current stop and performs loading/unloading
Definition: MEVehicle.cpp:336
SUMOTime getWaitingTime(const bool accumulated=false) const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:279
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge)
Definition: MEVehicle.cpp:174
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:156
int myQueIndex
Index of the que the vehicle is in (important for multiqueue extension)
Definition: MEVehicle.h:357
SUMOTime checkStop(SUMOTime time)
Returns until when to stop at the current segment and sets the information that the stop has been rea...
Definition: MEVehicle.cpp:230
void updateDetectors(SUMOTime currentTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
Definition: MEVehicle.cpp:462
virtual bool isIdling() const
Returns whether the vehicle is trying to re-enter the net.
Definition: MEVehicle.cpp:190
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition: MEVehicle.h:250
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MEVehicle.cpp:72
SUMOTime myLastEntryTime
The time the vehicle entered its current segment.
Definition: MEVehicle.h:363
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves its current segment.
Definition: MEVehicle.h:190
BaseInfluencer * myInfluencer
An instance of a velocity/lane influencing instance; built in "getInfluencer".
Definition: MEVehicle.h:369
void setApproaching(MSLink *link)
registers vehicle with the given link
Definition: MEVehicle.cpp:196
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:220
void saveState(OutputDevice &out)
Saves the states of a vehicle.
Definition: MEVehicle.cpp:531
SUMOTime getTimeLoss() const
Definition: MEVehicle.h:284
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition: MEVehicle.h:242
MESegment * mySegment
The segment the vehicle is at.
Definition: MEVehicle.h:354
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition: MEVehicle.h:228
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
Definition: MEVehicle.cpp:575
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition: MEVehicle.h:211
SUMOTime remainingStopDuration() const
Returns the remaining stop duration for a stopped vehicle or 0.
Definition: MEVehicle.h:162
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:434
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MEVehicle.h:81
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves its current segment.
Definition: MEVehicle.h:202
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition: MEVehicle.h:264
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MEVehicle.cpp:184
bool resumeFromStopping()
Definition: MEVehicle.cpp:285
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
Definition: MEVehicle.cpp:119
PositionVector getBoundingBox(double offset=0) const
get bounding rectangle
Definition: MEVehicle.cpp:100
double getSlope() const
Returns the slope of the road at vehicle's position in degrees.
Definition: MEVehicle.cpp:87
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:290
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition: MEVehicle.h:366
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)
Definition: MEVehicle.cpp:520
SUMOTime getBlockTime() const
Returns the time at which the vehicle was blocked.
Definition: MEVehicle.h:273
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:57
void markDelayed() const
Definition: MSEdge.h:714
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.
Definition: MSVehicleType.h:63
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
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.