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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A vehicle from the mesoscopic point of view
18 /****************************************************************************/
19 #ifndef MEVehicle_h
20 #define MEVehicle_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <iostream>
33 #include <cassert>
34 #include <map>
35 #include <vector>
36 #include <microsim/MSBaseVehicle.h>
37 #include <microsim/MSEdge.h>
38 #include <utils/common/StdDefs.h>
39 #include "MESegment.h"
40 
41 class MSLane;
42 class MSLink;
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
51 class MEVehicle : public MSBaseVehicle {
52 public:
60  MEVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
61  MSVehicleType* type, const double speedFactor);
62 
63 
67  double getPositionOnLane() const;
68 
69 
73  double getBackPositionOnLane(const MSLane* lane) const;
74 
75 
79  double getAngle() const;
80 
81 
85  double getSlope() const;
86 
90  MSLane* getLane() const {
91  return 0;
92  }
93 
101  Position getPosition(const double offset = 0) const;
102 
103 
108  double getSpeed() const;
109 
114  double getAverageSpeed() const;
115 
117  double estimateLeaveSpeed(const MSLink* link) const;
118 
119 
125  double getConservativeSpeed(SUMOTime& earliestArrival) const;
126 
127 
131  bool moveRoutePointer();
132 
136  bool hasArrived() const;
137 
141  bool isOnRoad() const;
142 
146  bool isParking() const;
147 
154  bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0, bool collision = false,
155  MSRouteIterator* searchStart = 0);
156 
157 
161  bool isStopped() const;
162 
163 
167  bool isStoppedTriggered() const;
168 
171  bool isStoppedInRange(double pos) const;
172 
177  SUMOTime getStoptime(const MESegment* const seg) const;
178 
179 
182  const ConstMSEdgeVector getStopEdges() const;
183 
186  bool replaceParkingArea(MSParkingArea* /* parkingArea = 0 */, std::string& /*errorMsg*/) {
187  throw ProcessError("parkingZoneReroute not implemented for meso");
188  }
189 
193  throw ProcessError("parkingZoneReroute not implemented for meso");
194  }
195 
199  inline void setEventTime(SUMOTime t, bool hasDelay = true) {
200  assert(t > myLastEntryTime);
201  if (hasDelay && mySegment != 0) {
203  }
204  myEventTime = t;
205  }
206 
207 
211  inline SUMOTime getEventTime() const {
212  return myEventTime;
213  }
214 
215 
220  inline virtual void setSegment(MESegment* s, int idx = 0) {
221  mySegment = s;
222  myQueIndex = idx;
223  }
224 
225 
229  inline MESegment* getSegment() const {
230  return mySegment;
231  }
232 
233 
237  inline int getQueIndex() const {
238  return myQueIndex;
239  }
240 
241 
245  inline void setLastEntryTime(SUMOTime t) {
246  myLastEntryTime = t;
247  }
248 
249 
254  return myLastEntryTime;
255  }
256 
257 
261  inline void setBlockTime(const SUMOTime t) {
262  assert(t > myLastEntryTime);
263  myBlockTime = t;
264  }
265 
266 
270  inline SUMOTime getBlockTime() const {
271  return myBlockTime;
272  }
273 
274 
276  inline SUMOTime getWaitingTime() const {
277  return MAX2(SUMOTime(0), myEventTime - myBlockTime);
278  }
279 
282  return getWaitingTime();
283  }
284 
285 
292  double getWaitingSeconds() const {
293  return STEPS2TIME(getWaitingTime());
294  }
295 
296 
298  double getEventTimeSeconds() const {
299  return STEPS2TIME(getEventTime());
300  }
301 
303  double getLastEntryTimeSeconds() const {
304  return STEPS2TIME(getLastEntryTime());
305  }
306 
308  double getBlockTimeSeconds() const {
309  return STEPS2TIME(getBlockTime());
310  }
311 
313  double getCurrentLinkPenaltySeconds() const;
314 
315 
317  bool replaceRoute(const MSRoute* route, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true);
318 
322  bool mayProceed() const;
323 
326  void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
327 
330  void updateDetectors(SUMOTime currentTime, const bool isLeave,
332 
334 
335 
337  void saveState(OutputDevice& out);
338 
341  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
343 
344 
345 protected:
348 
351 
354 
357 
360 
362  std::map<const MESegment* const, SUMOTime> myStops;
363 
364 };
365 
366 #endif
367 
368 /****************************************************************************/
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:308
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
Definition: MEVehicle.cpp:288
A lane area vehicles can halt at.
Definition: MSParkingArea.h:65
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
Definition: MEVehicle.cpp:369
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition: MEVehicle.h:220
double getAngle() const
Returns the vehicle&#39;s direction in degrees.
Definition: MEVehicle.cpp:88
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:51
double estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle&#39;s estimated speed after driving accross the link.
Definition: MEVehicle.cpp:125
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition: MEVehicle.h:253
SUMOTime getAccumulatedWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:281
The vehicle arrived at a junction.
bool mayProceed() const
Returns whether the vehicle is allowed to pass the next junction.
Definition: MEVehicle.cpp:272
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MEVehicle.cpp:102
double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MEVehicle.cpp:95
Notification
Definition of a vehicle state.
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:276
T MAX2(T a, T b)
Definition: StdDefs.h:73
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:211
bool isStoppedInRange(double pos) const
return whether the given position is within range of the current stop
Definition: MEVehicle.cpp:246
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
int myQueIndex
Index of the que the vehicle is in (important for multiqueue extension)
Definition: MEVehicle.h:350
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:55
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:298
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MEVehicle.cpp:168
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition: MEVehicle.h:261
The car-following model and parameter.
Definition: MSVehicleType.h:72
MSParkingArea * getNextParkingArea()
get the current parking area stop
Definition: MEVehicle.h:192
bool replaceRoute(const MSRoute *route, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true)
Replaces the current route by the given one.
Definition: MEVehicle.cpp:180
Encapsulated SAX-Attributes.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:229
bool addStop(const SUMOVehicleParameter::Stop &stopPar, std::string &errorMsg, SUMOTime untilOffset=0, bool collision=false, MSRouteIterator *searchStart=0)
Adds a stop.
Definition: MEVehicle.cpp:223
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:64
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition: MEVehicle.h:245
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:234
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge) ...
Definition: MEVehicle.cpp:159
SUMOTime myLastEntryTime
The time the vehicle entered its current segment.
Definition: MEVehicle.h:356
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:237
void saveState(OutputDevice &out)
Saves the states of a vehicle.
Definition: MEVehicle.cpp:340
double getConservativeSpeed(SUMOTime &earliestArrival) const
Returns the vehicle&#39;s estimated speed taking into account delays.
Definition: MEVehicle.cpp:134
MESegment * mySegment
The segment the vehicle is at.
Definition: MEVehicle.h:347
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:141
SUMOTime getStoptime(const MESegment *const seg) const
Returns how long to stop at the given segment.
Definition: MEVehicle.cpp:253
void markDelayed() const
Definition: MSEdge.h:627
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Structure representing possible vehicle parameter.
double getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:303
bool replaceParkingArea(MSParkingArea *, std::string &)
replace the current parking area stop with a new stop with merge duration
Definition: MEVehicle.h:186
A single mesoscopic segment (cell)
Definition: MESegment.h:56
Definition of vehicle stop (position and duration)
MEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
Definition: MEVehicle.cpp:53
void updateDetectors(SUMOTime currentTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
Definition: MEVehicle.cpp:306
std::map< const MESegment *const, SUMOTime > myStops
where to stop
Definition: MEVehicle.h:362
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:199
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:174
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MEVehicle.cpp:80
SUMOTime myEventTime
The (planned) time of leaving the segment (cell)
Definition: MEVehicle.h:353
double getAverageSpeed() const
Returns the vehicle&#39;s estimated average speed on the segment assuming no further delays.
Definition: MEVehicle.cpp:119
long long int SUMOTime
Definition: TraCIDefs.h:51
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:278
double getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:109
const ConstMSEdgeVector getStopEdges() const
Returns the list of still pending stop edges.
Definition: MEVehicle.cpp:262
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
Definition: MEVehicle.cpp:240
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition: MEVehicle.h:359
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:270
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MEVehicle.h:90
SUMOTime getBlockTime() const
Returns the time at which the vehicle was blocked.
Definition: MEVehicle.h:270
double getBackPositionOnLane(const MSLane *lane) const
Get the vehicle&#39;s position relative to the given lane.
Definition: MEVehicle.cpp:74
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:292