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 /****************************************************************************/
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:323
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
Definition: MEVehicle.cpp:379
A lane area vehicles can halt at.
Definition: MSParkingArea.h:59
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
Definition: MEVehicle.cpp:459
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition: MEVehicle.h:235
double getAngle() const
Returns the vehicle&#39;s direction in degrees.
Definition: MEVehicle.cpp:86
long long int SUMOTime
Definition: SUMOTime.h:35
std::vector< std::pair< int, double > > getStopIndices() const
return list of route indices for the remaining stops
Definition: MEVehicle.cpp:293
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:45
std::map< const MESegment *const, std::vector< SUMOVehicleParameter::Stop > > myStops
where to stop
Definition: MEVehicle.h:379
A lane area vehicles can halt at.
double estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle&#39;s estimated speed after driving accross the link.
Definition: MEVehicle.cpp:123
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition: MEVehicle.h:268
SUMOTime getAccumulatedWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:296
The vehicle arrived at a junction.
bool mayProceed() const
Returns whether the vehicle is allowed to pass the next junction.
Definition: MEVehicle.cpp:363
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MEVehicle.cpp:100
double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MEVehicle.cpp:93
SUMOTime remainingStopDuration() const
Returns the remaining stop duration for a stopped vehicle or 0.
Definition: MEVehicle.h:158
Notification
Definition of a vehicle state.
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:291
T MAX2(T a, T b)
Definition: StdDefs.h:80
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:226
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:73
int myQueIndex
Index of the que the vehicle is in (important for multiqueue extension)
Definition: MEVehicle.h:367
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
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:313
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MEVehicle.cpp:166
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition: MEVehicle.h:276
The car-following model and parameter.
Definition: MSVehicleType.h:66
MSParkingArea * getNextParkingArea()
get the current parking area stop
Definition: MEVehicle.h:207
const ConstMSEdgeVector getStopEdges(double &firstPos, double &lastPos) const
Returns the list of still pending stop edges.
Definition: MEVehicle.cpp:282
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:276
double getBrakeGap() const
get distance for coming to a stop (used for rerouting checks)
Definition: MEVehicle.h:195
Encapsulated SAX-Attributes.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:244
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
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:58
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition: MEVehicle.h:260
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:242
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge) ...
Definition: MEVehicle.cpp:157
void processStop()
ends the current stop and performs loading/unloading
Definition: MEVehicle.cpp:307
SUMOTime myLastEntryTime
The time the vehicle entered its current segment.
Definition: MEVehicle.h:373
Something on a lane to be noticed about vehicle movement.
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition: MEVehicle.h:252
void saveState(OutputDevice &out)
Saves the states of a vehicle.
Definition: MEVehicle.cpp:431
double getConservativeSpeed(SUMOTime &earliestArrival) const
Returns the vehicle&#39;s estimated speed taking into account delays.
Definition: MEVehicle.cpp:132
MESegment * mySegment
The segment the vehicle is at.
Definition: MEVehicle.h:364
Definition of vehicle stop (position and duration)
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:139
void markDelayed() const
Definition: MSEdge.h:641
SUMOTime getStoptime(const MESegment *const seg, SUMOTime time) const
Returns until when to stop at the given segment.
Definition: MEVehicle.cpp:260
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
ConstMSEdgeVector myStopEdges
edges to stop
Definition: MEVehicle.h:382
Structure representing possible vehicle parameter.
bool stopsAt(MSStoppingPlace *) const
Returns whether the vehicle stops at the given stopping place.
Definition: MEVehicle.h:175
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:318
bool replaceParkingArea(MSParkingArea *, std::string &)
replace the current parking area stop with a new stop with merge duration
Definition: MEVehicle.h:201
A single mesoscopic segment (cell)
Definition: MESegment.h:50
MEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
Definition: MEVehicle.cpp:51
void updateDetectors(SUMOTime currentTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
Definition: MEVehicle.cpp:397
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
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:214
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:172
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MEVehicle.cpp:78
SUMOTime myEventTime
The (planned) time of leaving the segment (cell)
Definition: MEVehicle.h:370
double getAverageSpeed() const
Returns the vehicle&#39;s estimated average speed on the segment assuming no further delays.
Definition: MEVehicle.cpp:117
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:369
double getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:107
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
Definition: MEVehicle.cpp:248
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition: MEVehicle.h:376
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:266
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MEVehicle.h:84
SUMOTime getBlockTime() const
Returns the time at which the vehicle was blocked.
Definition: MEVehicle.h:285
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle&#39;s position relative to the given lane.
Definition: MEVehicle.cpp:72
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:307