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-2017 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 double speedFactor);
63 
64 
68  double getPositionOnLane() const;
69 
70 
74  double getBackPositionOnLane(const MSLane* lane) const;
75 
76 
80  double getAngle() const;
81 
82 
86  double getSlope() const;
87 
91  MSLane* getLane() const {
92  return 0;
93  }
94 
102  Position getPosition(const double offset = 0) const;
103 
104 
109  double getSpeed() const;
110 
115  double getAverageSpeed() const;
116 
118  double estimateLeaveSpeed(const MSLink* link) const;
119 
120 
126  double getConservativeSpeed(SUMOTime& earliestArrival) const;
127 
128 
132  bool moveRoutePointer();
133 
137  bool hasArrived() const;
138 
142  bool isOnRoad() const;
143 
147  bool isParking() const;
148 
155  bool addStop(const SUMOVehicleParameter::Stop& stopPar, std::string& errorMsg, SUMOTime untilOffset = 0, bool collision = false);
156 
157 
161  bool isStopped() const;
162 
163 
167  bool isStoppedTriggered() const;
168 
173  SUMOTime getStoptime(const MESegment* const seg) const;
174 
175 
178  const ConstMSEdgeVector getStopEdges() const;
179 
182  bool replaceParkingArea(MSParkingArea* /* parkingArea = 0 */, std::string& /*errorMsg*/) {
183  throw ProcessError("parkingZoneReroute not implemented for meso");
184  }
185 
189  throw ProcessError("parkingZoneReroute not implemented for meso");
190  }
191 
195  inline void setEventTime(SUMOTime t, bool hasDelay = true) {
196  assert(t > myLastEntryTime);
197  if (hasDelay && mySegment != 0) {
199  }
200  myEventTime = t;
201  }
202 
203 
207  inline SUMOTime getEventTime() const {
208  return myEventTime;
209  }
210 
211 
216  inline virtual void setSegment(MESegment* s, int idx = 0) {
217  mySegment = s;
218  myQueIndex = idx;
219  }
220 
221 
225  inline MESegment* getSegment() const {
226  return mySegment;
227  }
228 
229 
233  inline int getQueIndex() const {
234  return myQueIndex;
235  }
236 
237 
241  inline void setLastEntryTime(SUMOTime t) {
242  myLastEntryTime = t;
243  }
244 
245 
250  return myLastEntryTime;
251  }
252 
253 
257  inline void setBlockTime(const SUMOTime t) {
258  assert(t > myLastEntryTime);
259  myBlockTime = t;
260  }
261 
262 
266  inline SUMOTime getBlockTime() const {
267  return myBlockTime;
268  }
269 
270 
272  inline SUMOTime getWaitingTime() const {
273  return MAX2(SUMOTime(0), myEventTime - myBlockTime);
274  }
275 
276 
283  double getWaitingSeconds() const {
284  return STEPS2TIME(getWaitingTime());
285  }
286 
287 
289  double getEventTimeSeconds() const {
290  return STEPS2TIME(getEventTime());
291  }
292 
294  double getLastEntryTimeSeconds() const {
295  return STEPS2TIME(getLastEntryTime());
296  }
297 
299  double getBlockTimeSeconds() const {
300  return STEPS2TIME(getBlockTime());
301  }
302 
304  double getCurrentLinkPenaltySeconds() const;
305 
306 
308  bool replaceRoute(const MSRoute* route, bool onInit = false, int offset = 0, bool addStops = true);
309 
313  bool mayProceed() const;
314 
317  void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
318 
321  void updateDetectors(SUMOTime currentTime, const bool isLeave,
323 
325 
326 
328  void saveState(OutputDevice& out);
329 
332  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
334 
335 
336 protected:
339 
342 
345 
348 
351 
353  std::map<const MESegment* const, SUMOTime> myStops;
354 
355 };
356 
357 #endif
358 
359 /****************************************************************************/
double getBlockTimeSeconds() const
Returns the time at which the vehicle was blocked on the current segment.
Definition: MEVehicle.h:299
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
Definition: MEVehicle.cpp:275
A lane area vehicles can halt at.
Definition: MSParkingArea.h:66
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
Definition: MEVehicle.cpp:344
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition: MEVehicle.h:216
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:52
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:249
bool replaceRoute(const MSRoute *route, bool onInit=false, int offset=0, bool addStops=true)
Replaces the current route by the given one.
Definition: MEVehicle.cpp:176
The vehicle arrived at a junction.
bool mayProceed() const
Returns whether the vehicle is allowed to pass the next junction.
Definition: MEVehicle.cpp:259
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:272
T MAX2(T a, T b)
Definition: StdDefs.h:70
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:207
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:341
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:56
double getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:289
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MEVehicle.cpp:164
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition: MEVehicle.h:257
The car-following model and parameter.
Definition: MSVehicleType.h:74
MSParkingArea * getNextParkingArea()
get the current parking area stop
Definition: MEVehicle.h:188
Encapsulated SAX-Attributes.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:225
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition: MEVehicle.h:241
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:228
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge) ...
Definition: MEVehicle.cpp:155
SUMOTime myLastEntryTime
The time the vehicle entered its current segment.
Definition: MEVehicle.h:347
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:233
void saveState(OutputDevice &out)
Saves the states of a vehicle.
Definition: MEVehicle.cpp:327
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:338
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:240
void markDelayed() const
Definition: MSEdge.h:644
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:294
bool replaceParkingArea(MSParkingArea *, std::string &)
replace the current parking area stop with a new stop with merge duration
Definition: MEVehicle.h:182
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:293
std::map< const MESegment *const, SUMOTime > myStops
where to stop
Definition: MEVehicle.h:353
MEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, const MSVehicleType *type, const double speedFactor)
Constructor.
Definition: MEVehicle.cpp:53
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:195
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:170
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
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:344
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:52
double getCurrentLinkPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty or –meso-minor-penalty.
Definition: MEVehicle.cpp:265
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:249
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
Definition: MEVehicle.cpp:234
bool addStop(const SUMOVehicleParameter::Stop &stopPar, std::string &errorMsg, SUMOTime untilOffset=0, bool collision=false)
Adds a stop.
Definition: MEVehicle.cpp:218
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition: MEVehicle.h:350
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:271
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MEVehicle.h:91
SUMOTime getBlockTime() const
Returns the time at which the vehicle was blocked.
Definition: MEVehicle.h:266
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:283