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 /****************************************************************************/
15 // A vehicle from the mesoscopic point of view
16 /****************************************************************************/
17 #ifndef MEVehicle_h
18 #define MEVehicle_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <iostream>
27 #include <cassert>
28 #include <map>
29 #include <vector>
30 #include <microsim/MSBaseVehicle.h>
31 #include <microsim/MSEdge.h>
32 #include <utils/common/StdDefs.h>
33 #include "MESegment.h"
34 
35 class MSLane;
36 class MSLink;
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
45 class MEVehicle : public MSBaseVehicle {
46 public:
54  MEVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
55  MSVehicleType* type, const double speedFactor);
56 
57 
61  double getPositionOnLane() const;
62 
63 
67  double getBackPositionOnLane(const MSLane* lane) const;
68 
69 
73  double getAngle() const;
74 
75 
79  double getSlope() const;
80 
84  MSLane* getLane() const {
85  return 0;
86  }
87 
95  Position getPosition(const double offset = 0) const;
96 
97 
102  double getSpeed() const;
103 
108  double getAverageSpeed() const;
109 
111  double estimateLeaveSpeed(const MSLink* link) const;
112 
113 
119  double getConservativeSpeed(SUMOTime& earliestArrival) const;
120 
121 
125  bool moveRoutePointer();
126 
130  bool hasArrived() const;
131 
135  bool isOnRoad() const;
136 
140  bool isParking() const;
141 
148  bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0, bool collision = false,
149  MSRouteIterator* searchStart = 0);
150 
151 
155  bool isStopped() const;
156 
159  return 0;
160  }
161 
163  void processStop();
164 
168  bool isStoppedTriggered() const;
169 
172  bool isStoppedInRange(const double pos, const double tolerance) const;
173 
175  bool stopsAt(MSStoppingPlace* /*stop*/) const {
176  return false;
177  };
178 
184  SUMOTime getStoptime(const MESegment* const seg, SUMOTime time) const;
185 
186 
189  const ConstMSEdgeVector getStopEdges(double& firstPos, double& lastPos) const;
190 
192  std::vector<std::pair<int, double> > getStopIndices() const;
193 
195  double getBrakeGap() const {
196  return 0;
197  }
198 
201  bool replaceParkingArea(MSParkingArea* /* parkingArea = 0 */, std::string& /*errorMsg*/) {
202  throw ProcessError("parkingZoneReroute not implemented for meso");
203  }
204 
208  throw ProcessError("parkingZoneReroute not implemented for meso");
209  }
210 
214  inline void setEventTime(SUMOTime t, bool hasDelay = true) {
215  assert(t > myLastEntryTime);
216  if (hasDelay && mySegment != 0) {
218  }
219  myEventTime = t;
220  }
221 
222 
226  inline SUMOTime getEventTime() const {
227  return myEventTime;
228  }
229 
230 
235  inline virtual void setSegment(MESegment* s, int idx = 0) {
236  mySegment = s;
237  myQueIndex = idx;
238  }
239 
240 
244  inline MESegment* getSegment() const {
245  return mySegment;
246  }
247 
248 
252  inline int getQueIndex() const {
253  return myQueIndex;
254  }
255 
256 
260  inline void setLastEntryTime(SUMOTime t) {
261  myLastEntryTime = t;
262  }
263 
264 
269  return myLastEntryTime;
270  }
271 
272 
276  inline void setBlockTime(const SUMOTime t) {
277  assert(t > myLastEntryTime);
278  myBlockTime = t;
279  }
280 
281 
285  inline SUMOTime getBlockTime() const {
286  return myBlockTime;
287  }
288 
289 
291  inline SUMOTime getWaitingTime() const {
292  return MAX2(SUMOTime(0), myEventTime - myBlockTime);
293  }
294 
297  return getWaitingTime();
298  }
299 
300 
307  double getWaitingSeconds() const {
308  return STEPS2TIME(getWaitingTime());
309  }
310 
311 
313  double getEventTimeSeconds() const {
314  return STEPS2TIME(getEventTime());
315  }
316 
318  double getLastEntryTimeSeconds() const {
319  return STEPS2TIME(getLastEntryTime());
320  }
321 
323  double getBlockTimeSeconds() const {
324  return STEPS2TIME(getBlockTime());
325  }
326 
328  double getCurrentLinkPenaltySeconds() const;
329 
331  double getCurrentStoppingTimeSeconds() const;
332 
334  bool replaceRoute(const MSRoute* route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true);
335 
339  bool mayProceed() const;
340 
343  void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
344 
347  void updateDetectors(SUMOTime currentTime, const bool isLeave,
349 
351 
352 
354  void saveState(OutputDevice& out);
355 
358  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
360 
361 
362 protected:
365 
368 
371 
374 
377 
379  std::map<const MESegment* const, std::vector<SUMOVehicleParameter::Stop> > myStops;
380 
383 
384 };
385 
386 #endif
387 
388 /****************************************************************************/
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:66
MEVehicle::getAccumulatedWaitingTime
SUMOTime getAccumulatedWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:296
MEVehicle
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:45
MSStoppingPlace
A lane area vehicles can halt at.
Definition: MSStoppingPlace.h:60
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:313
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
MESegment
A single mesoscopic segment (cell)
Definition: MESegment.h:50
MEVehicle::updateDetectorForWriting
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
Definition: MEVehicle.cpp:379
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
MSRouteIterator
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:58
MEVehicle::getAverageSpeed
double getAverageSpeed() const
Returns the vehicle's estimated average speed on the segment assuming no further delays.
Definition: MEVehicle.cpp:117
MEVehicle::stopsAt
bool stopsAt(MSStoppingPlace *) const
Returns whether the vehicle stops at the given stopping place.
Definition: MEVehicle.h:175
MEVehicle::saveState
void saveState(OutputDevice &out)
Saves the states of a vehicle.
Definition: MEVehicle.cpp:431
MEVehicle::myStopEdges
ConstMSEdgeVector myStopEdges
edges to stop
Definition: MEVehicle.h:382
MESegment::getEdge
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:266
MEVehicle::setLastEntryTime
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition: MEVehicle.h:260
MEVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MEVehicle.cpp:78
MEVehicle::getLastEntryTime
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition: MEVehicle.h:268
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
MEVehicle::getPosition
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MEVehicle.cpp:100
ConstMSEdgeVector
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:73
MEVehicle::myBlockTime
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition: MEVehicle.h:376
MEVehicle::getCurrentStoppingTimeSeconds
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:276
MEVehicle::getBrakeGap
double getBrakeGap() const
get distance for coming to a stop (used for rerouting checks)
Definition: MEVehicle.h:195
SUMOVehicleParameter
Structure representing possible vehicle parameter.
Definition: SUMOVehicleParameter.h:291
MSEdge.h
MEVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MEVehicle.h:84
MEVehicle::setEventTime
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:214
MSRoute
Definition: MSRoute.h:67
MEVehicle::moveRoutePointer
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:139
MSMoveReminder
Something on a lane to be noticed about vehicle movement.
Definition: MSMoveReminder.h:64
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:397
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:80
MEVehicle::getBlockTime
SUMOTime getBlockTime() const
Returns the time at which the vehicle was blocked.
Definition: MEVehicle.h:285
MEVehicle::getEventTime
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:226
MEVehicle::getWaitingSeconds
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:307
MEVehicle::getSlope
double getSlope() const
Returns the slope of the road at vehicle's position.
Definition: MEVehicle.cpp:93
MEVehicle::isStopped
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:242
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:221
MEVehicle::loadState
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
Definition: MEVehicle.cpp:459
MEVehicle::myQueIndex
int myQueIndex
Index of the que the vehicle is in (important for multiqueue extension)
Definition: MEVehicle.h:367
MEVehicle::getAngle
double getAngle() const
Returns the vehicle's direction in degrees.
Definition: MEVehicle.cpp:86
MEVehicle::mayProceed
bool mayProceed() const
Returns whether the vehicle is allowed to pass the next junction.
Definition: MEVehicle.cpp:363
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
MEVehicle::setBlockTime
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition: MEVehicle.h:276
MEVehicle::getBlockTimeSeconds
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:323
MEVehicle::isStoppedTriggered
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
Definition: MEVehicle.cpp:248
MEVehicle::getBackPositionOnLane
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
Definition: MEVehicle.cpp:72
ProcessError
Definition: UtilExceptions.h:40
MEVehicle::getStoptime
SUMOTime getStoptime(const MESegment *const seg, SUMOTime time) const
Returns until when to stop at the given segment.
Definition: MEVehicle.cpp:260
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
MEVehicle::isOnRoad
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MEVehicle.cpp:166
MEVehicle::MEVehicle
MEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
Definition: MEVehicle.cpp:51
MEVehicle::processStop
void processStop()
ends the current stop and performs loading/unloading
Definition: MEVehicle.cpp:307
MEVehicle::getStopIndices
std::vector< std::pair< int, double > > getStopIndices() const
return list of route indices for the remaining stops
Definition: MEVehicle.cpp:293
MEVehicle::replaceParkingArea
bool replaceParkingArea(MSParkingArea *, std::string &)
replace the current parking area stop with a new stop with merge duration
Definition: MEVehicle.h:201
MEVehicle::estimateLeaveSpeed
double estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving accross the link.
Definition: MEVehicle.cpp:123
MSBaseVehicle::addStops
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Definition: MSBaseVehicle.cpp:559
MEVehicle::getWaitingTime
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:291
MSEdge::markDelayed
void markDelayed() const
Definition: MSEdge.h:641
MEVehicle::getCurrentLinkPenaltySeconds
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:369
MEVehicle::getSegment
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:244
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:178
MEVehicle::mySegment
MESegment * mySegment
The segment the vehicle is at.
Definition: MEVehicle.h:364
MEVehicle::myLastEntryTime
SUMOTime myLastEntryTime
The time the vehicle entered its current segment.
Definition: MEVehicle.h:373
MEVehicle::isParking
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:172
MEVehicle::getSpeed
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
Definition: MEVehicle.cpp:107
MEVehicle::getConservativeSpeed
double getConservativeSpeed(SUMOTime &earliestArrival) const
Returns the vehicle's estimated speed taking into account delays.
Definition: MEVehicle.cpp:132
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:254
MEVehicle::hasArrived
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge)
Definition: MEVehicle.cpp:157
MEVehicle::remainingStopDuration
SUMOTime remainingStopDuration() const
Returns the remaining stop duration for a stopped vehicle or 0.
Definition: MEVehicle.h:158
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:235
MEVehicle::getStopEdges
const ConstMSEdgeVector getStopEdges(double &firstPos, double &lastPos) const
Returns the list of still pending stop edges.
Definition: MEVehicle.cpp:282
MSBaseVehicle
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
MEVehicle::getQueIndex
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition: MEVehicle.h:252
config.h
StdDefs.h
MSBaseVehicle.h
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:57
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:89
MSMoveReminder::NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
Definition: MSMoveReminder.h:93
MEVehicle::myStops
std::map< const MESegment *const, std::vector< SUMOVehicleParameter::Stop > > myStops
where to stop
Definition: MEVehicle.h:379
MEVehicle::myEventTime
SUMOTime myEventTime
The (planned) time of leaving the segment (cell)
Definition: MEVehicle.h:370
MEVehicle::getLastEntryTimeSeconds
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:318
MEVehicle::getNextParkingArea
MSParkingArea * getNextParkingArea()
get the current parking area stop
Definition: MEVehicle.h:207
SUMOVehicleParameter::Stop
Definition of vehicle stop (position and duration)
Definition: SUMOVehicleParameter.h:566