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.org/sumo
3 // Copyright (C) 2001-2020 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:
51  MEVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
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 
94 
99  double getSpeed() const;
100 
105  double getAverageSpeed() const;
106 
108  double estimateLeaveSpeed(const MSLink* link) const;
109 
110 
116  double getConservativeSpeed(SUMOTime& earliestArrival) const;
117 
119 
120 
130 
131 
135  bool moveRoutePointer();
136 
140  bool hasArrived() const;
141 
145  bool isOnRoad() const;
146 
150  virtual bool isIdling() const;
151 
152 
157  void setApproaching(MSLink* link);
158 
161  return 0;
162  }
163 
165  void processStop();
166 
168  bool stopsAt(MSStoppingPlace* /*stop*/) const {
169  return false;
170  }
171 
172  bool stopsAtEdge(const MSEdge* /*edge*/) const {
173  return false;
174  }
175 
181 
182 
184  double getBrakeGap() const {
185  return 0;
186  }
187 
190  bool replaceParkingArea(MSParkingArea* /* parkingArea = 0 */, std::string& /*errorMsg*/) {
191  throw ProcessError("parkingZoneReroute not implemented for meso");
192  }
193 
197  throw ProcessError("parkingZoneReroute not implemented for meso");
198  }
199 
201  throw ProcessError("stop retrieval not yet implemented for meso");
202  }
203 
207  inline void setEventTime(SUMOTime t, bool hasDelay = true) {
208  assert(t > myLastEntryTime);
209  if (hasDelay && mySegment != 0) {
211  }
212  myEventTime = t;
213  }
214 
215 
219  inline SUMOTime getEventTime() const {
220  return myEventTime;
221  }
222 
223 
228  inline virtual void setSegment(MESegment* s, int idx = 0) {
229  mySegment = s;
230  myQueIndex = idx;
231  }
232 
233 
237  inline MESegment* getSegment() const {
238  return mySegment;
239  }
240 
241 
245  inline int getQueIndex() const {
246  return myQueIndex;
247  }
248 
249 
253  inline void setLastEntryTime(SUMOTime t) {
254  myLastEntryTime = t;
255  }
256 
257 
262  return myLastEntryTime;
263  }
264 
265 
269  inline void setBlockTime(const SUMOTime t) {
270  assert(t > myLastEntryTime);
271  myBlockTime = t;
272  }
273 
274 
278  inline SUMOTime getBlockTime() const {
279  return myBlockTime;
280  }
281 
282 
284  inline SUMOTime getWaitingTime() const {
285  return MAX2(SUMOTime(0), myEventTime - myBlockTime);
286  }
287 
288  inline SUMOTime getTimeLoss() const {
289  // slow-downs while driving are not modelled
290  return getWaitingTime();
291  }
292 
295  return getWaitingTime();
296  }
297 
298 
305  double getWaitingSeconds() const {
306  return STEPS2TIME(getWaitingTime());
307  }
308 
309 
311  double getEventTimeSeconds() const {
312  return STEPS2TIME(getEventTime());
313  }
314 
316  double getLastEntryTimeSeconds() const {
317  return STEPS2TIME(getLastEntryTime());
318  }
319 
321  double getBlockTimeSeconds() const {
322  return STEPS2TIME(getBlockTime());
323  }
324 
326  double getCurrentLinkPenaltySeconds() const;
327 
329  double getCurrentStoppingTimeSeconds() const;
330 
332  bool replaceRoute(const MSRoute* route, const std::string& info, bool onInit = false, int offset = 0, bool addRouteStops = true, bool removeStops = true);
333 
337  bool mayProceed() const;
338 
341  void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
342 
345  void updateDetectors(SUMOTime currentTime, const bool isLeave,
347 
353  BaseInfluencer& getBaseInfluencer();
354 
355  const BaseInfluencer* getBaseInfluencer() const;
356 
357  bool hasInfluencer() const {
358  return myInfluencer != nullptr;
359  }
360 
362 
363 
365  void saveState(OutputDevice& out);
366 
369  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
371 
372 
373 protected:
376 
379 
382 
385 
388 
391 
392 };
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
long long int SUMOTime
Definition: SUMOTime.h:31
T MAX2(T a, T b)
Definition: StdDefs.h:79
A single mesoscopic segment (cell)
Definition: MESegment.h:47
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:325
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:132
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:316
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:321
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MEVehicle.cpp:100
bool hasInfluencer() const
Definition: MEVehicle.h:357
double getAverageSpeed() const
Returns the vehicle's estimated average speed on the segment assuming no further delays.
Definition: MEVehicle.cpp:117
double getAngle() const
Returns the vehicle's direction in degrees.
Definition: MEVehicle.cpp:86
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
Definition: MEVehicle.cpp:72
bool mayProceed() const
Returns whether the vehicle is allowed to pass the next junction.
Definition: MEVehicle.cpp:289
double getBrakeGap() const
get distance for coming to a stop (used for rerouting checks)
Definition: MEVehicle.h:184
SUMOTime myEventTime
The (planned) time of leaving the segment (cell)
Definition: MEVehicle.h:381
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MEVehicle.cpp:375
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
Definition: MEVehicle.cpp:305
BaseInfluencer & getBaseInfluencer()
Returns the velocity/lane influencer.
Definition: MEVehicle.cpp:360
const SUMOVehicleParameter::Stop * getNextStopParameter() const
Returns parameters of the next stop or nullptr.
Definition: MEVehicle.h:200
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:235
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:305
SUMOTime getAccumulatedWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:294
double estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving accross the link.
Definition: MEVehicle.cpp:123
void processStop()
ends the current stop and performs loading/unloading
Definition: MEVehicle.cpp:254
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge)
Definition: MEVehicle.cpp:157
MEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
Definition: MEVehicle.cpp:50
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:139
int myQueIndex
Index of the que the vehicle is in (important for multiqueue extension)
Definition: MEVehicle.h:378
bool stopsAtEdge(const MSEdge *) const
Returns whether the vehicle stops at the given edge.
Definition: MEVehicle.h:172
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:213
void updateDetectors(SUMOTime currentTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
Definition: MEVehicle.cpp:323
virtual bool isIdling() const
Returns whether the vehicle is trying to re-enter the net.
Definition: MEVehicle.cpp:173
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition: MEVehicle.h:261
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:384
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:207
BaseInfluencer * myInfluencer
An instance of a velocity/lane influencing instance; built in "getInfluencer".
Definition: MEVehicle.h:390
void setApproaching(MSLink *link)
registers vehicle with the given link
Definition: MEVehicle.cpp:179
bool replaceRoute(const MSRoute *route, const std::string &info, bool onInit=false, int offset=0, bool addRouteStops=true, bool removeStops=true)
Replaces the current route by the given one.
Definition: MEVehicle.cpp:193
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:237
void saveState(OutputDevice &out)
Saves the states of a vehicle.
Definition: MEVehicle.cpp:381
SUMOTime getTimeLoss() const
Definition: MEVehicle.h:288
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition: MEVehicle.h:253
MESegment * mySegment
The segment the vehicle is at.
Definition: MEVehicle.h:375
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition: MEVehicle.h:245
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:284
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
Definition: MEVehicle.cpp:419
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition: MEVehicle.h:228
SUMOTime remainingStopDuration() const
Returns the remaining stop duration for a stopped vehicle or 0.
Definition: MEVehicle.h:160
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:295
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 his current cell.
Definition: MEVehicle.h:219
bool stopsAt(MSStoppingPlace *) const
Returns whether the vehicle stops at the given stopping place.
Definition: MEVehicle.h:168
MSParkingArea * getNextParkingArea()
get the current parking area stop
Definition: MEVehicle.h:196
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition: MEVehicle.h:269
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MEVehicle.cpp:167
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
Definition: MEVehicle.cpp:107
double getSlope() const
Returns the slope of the road at vehicle's position in degrees.
Definition: MEVehicle.cpp:93
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:311
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition: MEVehicle.h:387
bool replaceParkingArea(MSParkingArea *, std::string &)
replace the current parking area stop with a new stop with merge duration
Definition: MEVehicle.h:190
SUMOTime getBlockTime() const
Returns the time at which the vehicle was blocked.
Definition: MEVehicle.h:278
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:51
A road/street connecting two junctions.
Definition: MSEdge.h:77
void markDelayed() const
Definition: MSEdge.h:682
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
A lane area vehicles can halt at.
Definition: MSParkingArea.h:57
A lane area vehicles can halt at.
The car-following model and parameter.
Definition: MSVehicleType.h:62
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
Encapsulated SAX-Attributes.
Definition of vehicle stop (position and duration)
Structure representing possible vehicle parameter.