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 
188  bool replaceParkingArea(MSParkingArea* /* parkingArea = 0 */, std::string& /*errorMsg*/) {
189  throw ProcessError("parkingZoneReroute not implemented for meso");
190  }
191 
195  throw ProcessError("parkingZoneReroute not implemented for meso");
196  }
197 
201  inline void setEventTime(SUMOTime t, bool hasDelay = true) {
202  assert(t > myLastEntryTime);
203  if (hasDelay && mySegment != 0) {
205  }
206  myEventTime = t;
207  }
208 
209 
213  inline SUMOTime getEventTime() const {
214  return myEventTime;
215  }
216 
217 
222  inline virtual void setSegment(MESegment* s, int idx = 0) {
223  mySegment = s;
224  myQueIndex = idx;
225  }
226 
227 
231  inline MESegment* getSegment() const {
232  return mySegment;
233  }
234 
235 
239  inline int getQueIndex() const {
240  return myQueIndex;
241  }
242 
243 
247  inline void setLastEntryTime(SUMOTime t) {
248  myLastEntryTime = t;
249  }
250 
251 
256  return myLastEntryTime;
257  }
258 
259 
263  inline void setBlockTime(const SUMOTime t) {
264  assert(t > myLastEntryTime);
265  myBlockTime = t;
266  }
267 
268 
272  inline SUMOTime getBlockTime() const {
273  return myBlockTime;
274  }
275 
276 
278  inline SUMOTime getWaitingTime() const {
279  return MAX2(SUMOTime(0), myEventTime - myBlockTime);
280  }
281 
284  return getWaitingTime();
285  }
286 
287 
294  double getWaitingSeconds() const {
295  return STEPS2TIME(getWaitingTime());
296  }
297 
298 
300  double getEventTimeSeconds() const {
301  return STEPS2TIME(getEventTime());
302  }
303 
305  double getLastEntryTimeSeconds() const {
306  return STEPS2TIME(getLastEntryTime());
307  }
308 
310  double getBlockTimeSeconds() const {
311  return STEPS2TIME(getBlockTime());
312  }
313 
315  double getCurrentLinkPenaltySeconds() const;
316 
318  double getCurrentStoppingTimeSeconds() const;
319 
321  bool replaceRoute(const MSRoute* route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true);
322 
326  bool mayProceed() const;
327 
330  void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
331 
334  void updateDetectors(SUMOTime currentTime, const bool isLeave,
336 
338 
339 
341  void saveState(OutputDevice& out);
342 
345  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
347 
348 
349 protected:
352 
355 
358 
361 
364 
366  std::map<const MESegment* const, std::vector<SUMOVehicleParameter::Stop> > myStops;
367 
370 
371 };
372 
373 #endif
374 
375 /****************************************************************************/
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:310
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:222
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:366
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:255
SUMOTime getAccumulatedWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:283
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:278
T MAX2(T a, T b)
Definition: StdDefs.h:68
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:213
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:354
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:50
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:300
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:263
The car-following model and parameter.
Definition: MSVehicleType.h:66
MSParkingArea * getNextParkingArea()
get the current parking area stop
Definition: MEVehicle.h:194
double getCurrentStoppingTimeSeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:271
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:231
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:247
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:360
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:239
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:351
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:139
void markDelayed() const
Definition: MSEdge.h:622
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:369
Structure representing possible vehicle parameter.
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:305
bool replaceParkingArea(MSParkingArea *, std::string &)
replace the current parking area stop with a new stop with merge duration
Definition: MEVehicle.h:188
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:201
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:357
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:363
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:264
Representation of a lane in the micro simulation.
Definition: MSLane.h:71
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:272
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:294