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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // A vehicle from the mesoscopic point of view
15 /****************************************************************************/
16 #ifndef MEVehicle_h
17 #define MEVehicle_h
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <iostream>
26 #include <cassert>
27 #include <map>
28 #include <vector>
29 #include <microsim/MSBaseVehicle.h>
30 #include <microsim/MSEdge.h>
31 #include <utils/common/StdDefs.h>
32 #include "MESegment.h"
33 
34 class MSLane;
35 class MSLink;
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
44 class MEVehicle : public MSBaseVehicle {
45 public:
53  MEVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
54  MSVehicleType* type, const double speedFactor);
55 
56 
60  double getPositionOnLane() const;
61 
62 
66  double getBackPositionOnLane(const MSLane* lane) const;
67 
68 
72  double getAngle() const;
73 
74 
78  double getSlope() const;
79 
83  MSLane* getLane() const {
84  return 0;
85  }
86 
94  Position getPosition(const double offset = 0) const;
95 
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 
120 
124  bool moveRoutePointer();
125 
129  bool hasArrived() const;
130 
134  bool isOnRoad() const;
135 
139  bool isParking() const;
140 
147  bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0, bool collision = false,
148  MSRouteIterator* searchStart = 0);
149 
150 
154  bool isStopped() const;
155 
158  return 0;
159  }
160 
162  void processStop();
163 
167  bool isStoppedTriggered() const;
168 
171  bool isStoppedInRange(const double pos, const double tolerance) const;
172 
174  bool stopsAt(MSStoppingPlace* /*stop*/) const {
175  return false;
176  };
177 
178  bool stopsAtEdge(const MSEdge* /*edge*/) const {
179  return false;
180  };
181 
187  SUMOTime getStoptime(const MESegment* const seg, SUMOTime time) const;
188 
189 
192  const ConstMSEdgeVector getStopEdges(double& firstPos, double& lastPos) const;
193 
195  std::vector<std::pair<int, double> > getStopIndices() const;
196 
198  double getBrakeGap() const {
199  return 0;
200  }
201 
204  bool replaceParkingArea(MSParkingArea* /* parkingArea = 0 */, std::string& /*errorMsg*/) {
205  throw ProcessError("parkingZoneReroute not implemented for meso");
206  }
207 
211  throw ProcessError("parkingZoneReroute not implemented for meso");
212  }
213 
217  inline void setEventTime(SUMOTime t, bool hasDelay = true) {
218  assert(t > myLastEntryTime);
219  if (hasDelay && mySegment != 0) {
221  }
222  myEventTime = t;
223  }
224 
225 
229  inline SUMOTime getEventTime() const {
230  return myEventTime;
231  }
232 
233 
238  inline virtual void setSegment(MESegment* s, int idx = 0) {
239  mySegment = s;
240  myQueIndex = idx;
241  }
242 
243 
247  inline MESegment* getSegment() const {
248  return mySegment;
249  }
250 
251 
255  inline int getQueIndex() const {
256  return myQueIndex;
257  }
258 
259 
263  inline void setLastEntryTime(SUMOTime t) {
264  myLastEntryTime = t;
265  }
266 
267 
272  return myLastEntryTime;
273  }
274 
275 
279  inline void setBlockTime(const SUMOTime t) {
280  assert(t > myLastEntryTime);
281  myBlockTime = t;
282  }
283 
284 
288  inline SUMOTime getBlockTime() const {
289  return myBlockTime;
290  }
291 
292 
294  inline SUMOTime getWaitingTime() const {
295  return MAX2(SUMOTime(0), myEventTime - myBlockTime);
296  }
297 
300  return getWaitingTime();
301  }
302 
303 
310  double getWaitingSeconds() const {
311  return STEPS2TIME(getWaitingTime());
312  }
313 
314 
316  double getEventTimeSeconds() const {
317  return STEPS2TIME(getEventTime());
318  }
319 
321  double getLastEntryTimeSeconds() const {
322  return STEPS2TIME(getLastEntryTime());
323  }
324 
326  double getBlockTimeSeconds() const {
327  return STEPS2TIME(getBlockTime());
328  }
329 
331  double getCurrentLinkPenaltySeconds() const;
332 
334  double getCurrentStoppingTimeSeconds() const;
335 
337  bool replaceRoute(const MSRoute* route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true);
338 
342  bool mayProceed() const;
343 
346  void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
347 
350  void updateDetectors(SUMOTime currentTime, const bool isLeave,
352 
354 
355 
357  void saveState(OutputDevice& out);
358 
361  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
363 
364 
365 protected:
368 
371 
374 
377 
380 
382  std::map<const MESegment* const, std::vector<SUMOVehicleParameter::Stop> > myStops;
383 
386 
387 };
388 
389 #endif
390 
391 /****************************************************************************/
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:65
MEVehicle::getAccumulatedWaitingTime
SUMOTime getAccumulatedWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:299
MEVehicle
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:44
MSStoppingPlace
A lane area vehicles can halt at.
Definition: MSStoppingPlace.h:59
MSParkingArea
A lane area vehicles can halt at.
Definition: MSParkingArea.h:59
MEVehicle::getEventTimeSeconds
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:316
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MESegment
A single mesoscopic segment (cell)
Definition: MESegment.h:49
MEVehicle::updateDetectorForWriting
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
Definition: MEVehicle.cpp:378
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MSRouteIterator
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:57
MEVehicle::getAverageSpeed
double getAverageSpeed() const
Returns the vehicle's estimated average speed on the segment assuming no further delays.
Definition: MEVehicle.cpp:116
MEVehicle::stopsAt
bool stopsAt(MSStoppingPlace *) const
Returns whether the vehicle stops at the given stopping place.
Definition: MEVehicle.h:174
MEVehicle::saveState
void saveState(OutputDevice &out)
Saves the states of a vehicle.
Definition: MEVehicle.cpp:433
MEVehicle::myStopEdges
ConstMSEdgeVector myStopEdges
edges to stop
Definition: MEVehicle.h:385
MESegment::getEdge
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:265
MEVehicle::setLastEntryTime
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition: MEVehicle.h:263
MEVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MEVehicle.cpp:77
MEVehicle::getLastEntryTime
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition: MEVehicle.h:271
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MEVehicle::getPosition
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MEVehicle.cpp:99
ConstMSEdgeVector
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:75
MEVehicle::myBlockTime
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition: MEVehicle.h:379
MEVehicle::getCurrentStoppingTimeSeconds
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:275
MEVehicle::getBrakeGap
double getBrakeGap() const
get distance for coming to a stop (used for rerouting checks)
Definition: MEVehicle.h:198
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:297
MSEdge.h
MEVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MEVehicle.h:83
MEVehicle::setEventTime
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:217
MSRoute
Definition: MSRoute.h:66
MEVehicle::moveRoutePointer
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:138
MSMoveReminder
Something on a lane to be noticed about vehicle movement.
Definition: MSMoveReminder.h:66
MESegment.h
MEVehicle::updateDetectors
void updateDetectors(SUMOTime currentTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
Definition: MEVehicle.cpp:396
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
MEVehicle::getBlockTime
SUMOTime getBlockTime() const
Returns the time at which the vehicle was blocked.
Definition: MEVehicle.h:288
MEVehicle::getEventTime
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:229
MEVehicle::getWaitingSeconds
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:310
MEVehicle::getSlope
double getSlope() const
Returns the slope of the road at vehicle's position.
Definition: MEVehicle.cpp:92
MEVehicle::isStopped
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:241
MEVehicle::addStop
bool addStop(const SUMOVehicleParameter::Stop &stopPar, std::string &errorMsg, SUMOTime untilOffset=0, bool collision=false, MSRouteIterator *searchStart=0)
Adds a stop.
Definition: MEVehicle.cpp:220
MEVehicle::loadState
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
Definition: MEVehicle.cpp:465
MEVehicle::myQueIndex
int myQueIndex
Index of the que the vehicle is in (important for multiqueue extension)
Definition: MEVehicle.h:370
MEVehicle::getAngle
double getAngle() const
Returns the vehicle's direction in degrees.
Definition: MEVehicle.cpp:85
MEVehicle::mayProceed
bool mayProceed() const
Returns whether the vehicle is allowed to pass the next junction.
Definition: MEVehicle.cpp:362
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
MEVehicle::setBlockTime
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition: MEVehicle.h:279
MEVehicle::getBlockTimeSeconds
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:326
MEVehicle::isStoppedTriggered
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
Definition: MEVehicle.cpp:247
MEVehicle::getBackPositionOnLane
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
Definition: MEVehicle.cpp:71
ProcessError
Definition: UtilExceptions.h:39
MEVehicle::getStoptime
SUMOTime getStoptime(const MESegment *const seg, SUMOTime time) const
Returns until when to stop at the given segment.
Definition: MEVehicle.cpp:259
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
MEVehicle::isOnRoad
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MEVehicle.cpp:165
MEVehicle::MEVehicle
MEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
Definition: MEVehicle.cpp:50
MEVehicle::processStop
void processStop()
ends the current stop and performs loading/unloading
Definition: MEVehicle.cpp:306
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
MEVehicle::getStopIndices
std::vector< std::pair< int, double > > getStopIndices() const
return list of route indices for the remaining stops
Definition: MEVehicle.cpp:292
MEVehicle::replaceParkingArea
bool replaceParkingArea(MSParkingArea *, std::string &)
replace the current parking area stop with a new stop with merge duration
Definition: MEVehicle.h:204
MEVehicle::estimateLeaveSpeed
double estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving accross the link.
Definition: MEVehicle.cpp:122
MSBaseVehicle::addStops
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Definition: MSBaseVehicle.cpp:593
MEVehicle::getWaitingTime
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:294
MSEdge::markDelayed
void markDelayed() const
Definition: MSEdge.h:648
MEVehicle::getCurrentLinkPenaltySeconds
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:368
MEVehicle::getSegment
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:247
MEVehicle::replaceRoute
bool replaceRoute(const MSRoute *route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true)
Replaces the current route by the given one.
Definition: MEVehicle.cpp:177
MEVehicle::mySegment
MESegment * mySegment
The segment the vehicle is at.
Definition: MEVehicle.h:367
MEVehicle::myLastEntryTime
SUMOTime myLastEntryTime
The time the vehicle entered its current segment.
Definition: MEVehicle.h:376
MEVehicle::isParking
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:171
MEVehicle::getSpeed
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
Definition: MEVehicle.cpp:106
MEVehicle::getConservativeSpeed
double getConservativeSpeed(SUMOTime &earliestArrival) const
Returns the vehicle's estimated speed taking into account delays.
Definition: MEVehicle.cpp:131
MEVehicle::isStoppedInRange
bool isStoppedInRange(const double pos, const double tolerance) const
return whether the given position is within range of the current stop
Definition: MEVehicle.cpp:253
MEVehicle::hasArrived
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge)
Definition: MEVehicle.cpp:156
MEVehicle::remainingStopDuration
SUMOTime remainingStopDuration() const
Returns the remaining stop duration for a stopped vehicle or 0.
Definition: MEVehicle.h:157
MEVehicle::setSegment
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition: MEVehicle.h:238
MEVehicle::getStopEdges
const ConstMSEdgeVector getStopEdges(double &firstPos, double &lastPos) const
Returns the list of still pending stop edges.
Definition: MEVehicle.cpp:281
MEVehicle::stopsAtEdge
bool stopsAtEdge(const MSEdge *) const
Returns whether the vehicle stops at the given edge.
Definition: MEVehicle.h:178
MSBaseVehicle
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:51
MEVehicle::getQueIndex
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition: MEVehicle.h:255
config.h
StdDefs.h
MSBaseVehicle.h
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:56
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:91
MSMoveReminder::NOTIFICATION_JUNCTION
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
Definition: MSMoveReminder.h:95
MEVehicle::myStops
std::map< const MESegment *const, std::vector< SUMOVehicleParameter::Stop > > myStops
where to stop
Definition: MEVehicle.h:382
MEVehicle::myEventTime
SUMOTime myEventTime
The (planned) time of leaving the segment (cell)
Definition: MEVehicle.h:373
MEVehicle::getLastEntryTimeSeconds
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:321
MEVehicle::getNextParkingArea
MSParkingArea * getNextParkingArea()
get the current parking area stop
Definition: MEVehicle.h:210
SUMOVehicleParameter::Stop
Definition of vehicle stop (position and duration)
Definition: SUMOVehicleParameter.h:572