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-2018 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(double pos) const;
173 
179  SUMOTime getStoptime(const MESegment* const seg, SUMOTime time) const;
180 
181 
184  const ConstMSEdgeVector getStopEdges() const;
185 
186 
188  double getBrakeGap() const {
189  return 0;
190  }
191 
194  bool replaceParkingArea(MSParkingArea* /* parkingArea = 0 */, std::string& /*errorMsg*/) {
195  throw ProcessError("parkingZoneReroute not implemented for meso");
196  }
197 
201  throw ProcessError("parkingZoneReroute not 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 
290  return getWaitingTime();
291  }
292 
293 
300  double getWaitingSeconds() const {
301  return STEPS2TIME(getWaitingTime());
302  }
303 
304 
306  double getEventTimeSeconds() const {
307  return STEPS2TIME(getEventTime());
308  }
309 
311  double getLastEntryTimeSeconds() const {
312  return STEPS2TIME(getLastEntryTime());
313  }
314 
316  double getBlockTimeSeconds() const {
317  return STEPS2TIME(getBlockTime());
318  }
319 
321  double getCurrentLinkPenaltySeconds() const;
322 
324  double getCurrentStoppingTimeSeconds() const;
325 
327  bool replaceRoute(const MSRoute* route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true);
328 
332  bool mayProceed() const;
333 
336  void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
337 
340  void updateDetectors(SUMOTime currentTime, const bool isLeave,
342 
344 
345 
347  void saveState(OutputDevice& out);
348 
351  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
353 
354 
355 protected:
358 
361 
364 
367 
370 
372  std::map<const MESegment* const, std::vector<SUMOVehicleParameter::Stop> > myStops;
373 
376 
377 };
378 
379 #endif
380 
381 /****************************************************************************/
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:316
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
Definition: MEVehicle.cpp:331
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:410
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition: MEVehicle.h:228
double getAngle() const
Returns the vehicle&#39;s direction in degrees.
Definition: MEVehicle.cpp:86
long long int SUMOTime
Definition: SUMOTime.h:36
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:372
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:261
SUMOTime getAccumulatedWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:289
The vehicle arrived at a junction.
bool mayProceed() const
Returns whether the vehicle is allowed to pass the next junction.
Definition: MEVehicle.cpp:315
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:284
T MAX2(T a, T b)
Definition: StdDefs.h:76
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:219
bool isStoppedInRange(double pos) const
return whether the given position is within range of the current stop
Definition: MEVehicle.cpp:248
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:72
int myQueIndex
Index of the que the vehicle is in (important for multiqueue extension)
Definition: MEVehicle.h:360
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:306
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:269
The car-following model and parameter.
Definition: MSVehicleType.h:66
MSParkingArea * getNextParkingArea()
get the current parking area stop
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:271
double getBrakeGap() const
get distance for coming to a stop (used for rerouting checks)
Definition: MEVehicle.h:188
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:237
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:253
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:236
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
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:284
SUMOTime myLastEntryTime
The time the vehicle entered its current segment.
Definition: MEVehicle.h:366
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:245
void saveState(OutputDevice &out)
Saves the states of a vehicle.
Definition: MEVehicle.cpp:383
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:357
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:139
void markDelayed() const
Definition: MSEdge.h:627
SUMOTime getStoptime(const MESegment *const seg, SUMOTime time) const
Returns until when to stop at the given segment.
Definition: MEVehicle.cpp:255
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
ConstMSEdgeVector myStopEdges
edges to stop
Definition: MEVehicle.h:375
Structure representing possible vehicle parameter.
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:311
bool replaceParkingArea(MSParkingArea *, std::string &)
replace the current parking area stop with a new stop with merge duration
Definition: MEVehicle.h:194
A single mesoscopic segment (cell)
Definition: MESegment.h:50
Definition of vehicle stop (position and duration)
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:349
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:207
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:363
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:321
double getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:107
const ConstMSEdgeVector getStopEdges() const
Returns the list of still pending stop edges.
Definition: MEVehicle.cpp:277
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
Definition: MEVehicle.cpp:242
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition: MEVehicle.h:369
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:78
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:278
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:300