SUMO - Simulation of Urban MObility
MEVehicle.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // A vehicle from the mesoscopic point of view
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 #ifndef MEVehicle_h
21 #define MEVehicle_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <iostream>
34 #include <cassert>
35 #include <map>
36 #include <vector>
37 #include <microsim/MSBaseVehicle.h>
38 #include <microsim/MSEdge.h>
39 #include <utils/common/StdDefs.h>
40 #include "MESegment.h"
41 
42 class MSLane;
43 class MSLink;
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
52 class MEVehicle : public MSBaseVehicle {
53 public:
61  MEVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
62  const MSVehicleType* type, const SUMOReal speedFactor);
63 
64 
69 
70 
74  SUMOReal getAngle() const;
75 
76 
80  SUMOReal getSlope() const;
81 
85  MSLane* getLane() const {
86  return 0;
87  }
88 
96  Position getPosition(const SUMOReal offset = 0) const;
97 
98 
103  SUMOReal getSpeed() const;
104 
109  SUMOReal getAverageSpeed() const;
110 
112  SUMOReal estimateLeaveSpeed(const MSLink* link) const;
113 
114 
120  SUMOReal getConservativeSpeed(SUMOTime& earliestArrival) const;
121 
122 
126  bool moveRoutePointer();
127 
131  bool hasArrived() const;
132 
136  bool isOnRoad() const;
137 
141  bool isParking() const;
142 
149  bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0);
150 
151 
155  bool isStopped() const;
156 
157 
161  bool isStoppedTriggered() const;
162 
167  SUMOTime getStoptime(const MESegment* const seg) const;
168 
169 
172  const ConstMSEdgeVector getStopEdges() const;
173 
177  inline void setEventTime(SUMOTime t, bool hasDelay = true) {
178  assert(t > myLastEntryTime);
179  if (hasDelay && mySegment != 0) {
181  }
182  myEventTime = t;
183  }
184 
185 
189  inline SUMOTime getEventTime() const {
190  return myEventTime;
191  }
192 
193 
198  inline virtual void setSegment(MESegment* s, size_t idx = 0) {
199  mySegment = s;
200  myQueIndex = idx;
201  }
202 
203 
207  inline MESegment* getSegment() const {
208  return mySegment;
209  }
210 
211 
215  inline size_t getQueIndex() const {
216  return myQueIndex;
217  }
218 
219 
223  inline void setLastEntryTime(SUMOTime t) {
224  myLastEntryTime = t;
225  }
226 
227 
232  return myLastEntryTime;
233  }
234 
235 
239  inline void setBlockTime(const SUMOTime t) {
240  assert(t > myLastEntryTime);
241  myBlockTime = t;
242  }
243 
244 
248  inline SUMOTime getBlockTime() const {
249  return myBlockTime;
250  }
251 
252 
254  inline SUMOTime getWaitingTime() const {
255  return MAX2(SUMOTime(0), myEventTime - myBlockTime);
256  }
257 
258 
266  return STEPS2TIME(getWaitingTime());
267  }
268 
269 
272  return STEPS2TIME(getEventTime());
273  }
274 
277  return STEPS2TIME(getLastEntryTime());
278  }
279 
282  return STEPS2TIME(getBlockTime());
283  }
284 
285 
287  bool replaceRoute(const MSRoute* route, bool onInit = false, int offset = 0);
288 
292  bool mayProceed() const;
293 
296  void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
297 
300  void updateDetectors(SUMOTime currentTime, const bool isLeave,
302 
304 
305 
307  void saveState(OutputDevice& out);
308 
311  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
313 
314 
315 protected:
318 
320  size_t myQueIndex;
321 
324 
327 
330 
332  std::map<const MESegment* const, SUMOTime> myStops;
333 
334 };
335 
336 #endif
337 
338 /****************************************************************************/
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
Definition: MEVehicle.cpp:261
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
Definition: MEVehicle.cpp:330
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:168
long long int SUMOTime
Definition: SUMOTime.h:43
bool addStop(const SUMOVehicleParameter::Stop &stopPar, std::string &errorMsg, SUMOTime untilOffset=0)
Adds a stop.
Definition: MEVehicle.cpp:214
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge) ...
Definition: MEVehicle.cpp:153
SUMOTime getBlockTime() const
Returns the time at which the vehicle was blocked.
Definition: MEVehicle.h:248
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:52
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MEVehicle.h:85
The vehicle arrived at a junction.
SUMOReal getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MEVehicle.cpp:93
SUMOTime getStoptime(const MESegment *const seg) const
Returns how long to stop at the given segment.
Definition: MEVehicle.cpp:236
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
Definition: MEVehicle.cpp:230
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:254
SUMOReal getSpeed() const
Returns the vehicle&#39;s estimated speed assuming no delays.
Definition: MEVehicle.cpp:107
Notification
Definition of a vehicle state.
T MAX2(T a, T b)
Definition: StdDefs.h:75
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:189
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition: MEVehicle.h:231
SUMOReal getAverageSpeed() const
Returns the vehicle&#39;s estimated average speed on the segment assuming no further delays.
Definition: MEVehicle.cpp:117
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:272
SUMOReal getConservativeSpeed(SUMOTime &earliestArrival) const
Returns the vehicle&#39;s estimated speed taking into account delays.
Definition: MEVehicle.cpp:132
SUMOReal getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:271
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition: MEVehicle.h:239
The car-following model and parameter.
Definition: MSVehicleType.h:74
SUMOReal getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:281
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:224
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MEVehicle.cpp:162
Encapsulated SAX-Attributes.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
SUMOReal getLastEntryTimeSeconds() const
Returns the entry time for the current segment.
Definition: MEVehicle.h:276
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition: MEVehicle.h:223
Position getPosition(const SUMOReal offset=0) const
Return current position (x/y, cartesian)
Definition: MEVehicle.cpp:100
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
void markDelayed() const
Definition: MSEdge.h:617
SUMOTime myLastEntryTime
The time the vehicle entered its current segment.
Definition: MEVehicle.h:326
Something on a lane to be noticed about vehicle movement.
void saveState(OutputDevice &out)
Saves the states of a vehicle.
Definition: MEVehicle.cpp:313
MESegment * mySegment
The segment the vehicle is at.
Definition: MEVehicle.h:317
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:139
Structure representing possible vehicle parameter.
bool replaceRoute(const MSRoute *route, bool onInit=false, int offset=0)
Replaces the current route by the given one.
Definition: MEVehicle.cpp:174
size_t getQueIndex() const
Returns the index of the que the vehicle is in.
Definition: MEVehicle.h:215
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:265
A single mesoscopic segment (cell)
Definition: MESegment.h:57
Definition of vehicle stop (position and duration)
void updateDetectors(SUMOTime currentTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
Definition: MEVehicle.cpp:279
SUMOReal getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MEVehicle.cpp:78
std::map< const MESegment *const, SUMOTime > myStops
where to stop
Definition: MEVehicle.h:332
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:177
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
SUMOTime myEventTime
The (planned) time of leaving the segment (cell)
Definition: MEVehicle.h:323
const ConstMSEdgeVector getStopEdges() const
Returns the list of still pending stop edges.
Definition: MEVehicle.cpp:245
size_t myQueIndex
Index of the que the vehicle is in (important for multiqueue extension)
Definition: MEVehicle.h:320
virtual void setSegment(MESegment *s, size_t idx=0)
Sets the current segment the vehicle is at together with its que.
Definition: MEVehicle.h:198
bool mayProceed() const
Returns whether the vehicle is allowed to pass the next junction.
Definition: MEVehicle.cpp:255
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition: MEVehicle.h:329
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:207
SUMOReal estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle&#39;s estimated speed after driving accross the link.
Definition: MEVehicle.cpp:123
SUMOReal getAngle() const
Returns the vehicle&#39;s direction in degrees.
Definition: MEVehicle.cpp:86
MEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, const MSVehicleType *type, const SUMOReal speedFactor)
Constructor.
Definition: MEVehicle.cpp:57