SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 getBackPositionOnLane(const MSLane* lane) const;
75 
76 
80  SUMOReal getAngle() const;
81 
82 
86  SUMOReal getSlope() const;
87 
91  MSLane* getLane() const {
92  return 0;
93  }
94 
102  Position getPosition(const SUMOReal offset = 0) const;
103 
104 
109  SUMOReal getSpeed() const;
110 
115  SUMOReal getAverageSpeed() const;
116 
118  SUMOReal estimateLeaveSpeed(const MSLink* link) const;
119 
120 
126  SUMOReal 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);
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 
183  inline void setEventTime(SUMOTime t, bool hasDelay = true) {
184  assert(t > myLastEntryTime);
185  if (hasDelay && mySegment != 0) {
187  }
188  myEventTime = t;
189  }
190 
191 
195  inline SUMOTime getEventTime() const {
196  return myEventTime;
197  }
198 
199 
204  inline virtual void setSegment(MESegment* s, int idx = 0) {
205  mySegment = s;
206  myQueIndex = idx;
207  }
208 
209 
213  inline MESegment* getSegment() const {
214  return mySegment;
215  }
216 
217 
221  inline int getQueIndex() const {
222  return myQueIndex;
223  }
224 
225 
229  inline void setLastEntryTime(SUMOTime t) {
230  myLastEntryTime = t;
231  }
232 
233 
238  return myLastEntryTime;
239  }
240 
241 
245  inline void setBlockTime(const SUMOTime t) {
246  assert(t > myLastEntryTime);
247  myBlockTime = t;
248  }
249 
250 
254  inline SUMOTime getBlockTime() const {
255  return myBlockTime;
256  }
257 
258 
260  inline SUMOTime getWaitingTime() const {
261  return MAX2(SUMOTime(0), myEventTime - myBlockTime);
262  }
263 
264 
272  return STEPS2TIME(getWaitingTime());
273  }
274 
275 
278  return STEPS2TIME(getEventTime());
279  }
280 
283  return STEPS2TIME(getLastEntryTime());
284  }
285 
288  return STEPS2TIME(getBlockTime());
289  }
290 
293 
294 
296  bool replaceRoute(const MSRoute* route, bool onInit = false, int offset = 0);
297 
301  bool mayProceed() const;
302 
305  void updateDetectorForWriting(MSMoveReminder* rem, SUMOTime currentTime, SUMOTime exitTime);
306 
309  void updateDetectors(SUMOTime currentTime, const bool isLeave,
311 
313 
314 
316  void saveState(OutputDevice& out);
317 
320  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
322 
323 
324 protected:
327 
330 
333 
336 
339 
341  std::map<const MESegment* const, SUMOTime> myStops;
342 
343 };
344 
345 #endif
346 
347 /****************************************************************************/
void updateDetectorForWriting(MSMoveReminder *rem, SUMOTime currentTime, SUMOTime exitTime)
Updates a single vehicle detector if present.
Definition: MEVehicle.cpp:278
void loadState(const SUMOSAXAttributes &attrs, const SUMOTime offset)
Loads the state of this vehicle from the given description.
Definition: MEVehicle.cpp:347
bool isParking() const
Returns whether the vehicle is parking.
Definition: MEVehicle.cpp:174
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
Definition: MEVehicle.h:204
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:221
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge) ...
Definition: MEVehicle.cpp:159
SUMOTime getBlockTime() const
Returns the time at which the vehicle was blocked.
Definition: MEVehicle.h:254
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:91
The vehicle arrived at a junction.
SUMOReal getSlope() const
Returns the slope of the road at vehicle's position.
Definition: MEVehicle.cpp:99
SUMOTime getStoptime(const MESegment *const seg) const
Returns how long to stop at the given segment.
Definition: MEVehicle.cpp:243
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
Definition: MEVehicle.cpp:237
SUMOReal getCurrentTLSPenaltySeconds() const
Returns the delay that is accrued due to option –meso-tls-penalty.
Definition: MEVehicle.cpp:268
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
Definition: MEVehicle.h:260
SUMOReal getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
Definition: MEVehicle.cpp:113
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:195
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:329
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:56
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
Definition: MEVehicle.h:237
SUMOReal getAverageSpeed() const
Returns the vehicle's estimated average speed on the segment assuming no further delays.
Definition: MEVehicle.cpp:123
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
Definition: MESegment.h:272
SUMOReal getConservativeSpeed(SUMOTime &earliestArrival) const
Returns the vehicle's estimated speed taking into account delays.
Definition: MEVehicle.cpp:138
SUMOReal getEventTimeSeconds() const
Returns the earliest leave time for the current segment.
Definition: MEVehicle.h:277
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
Definition: MEVehicle.h:245
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:287
SUMOReal getBackPositionOnLane(const MSLane *lane) const
Get the vehicle's position relative to the given lane.
Definition: MEVehicle.cpp:78
bool isStopped() const
Returns whether the vehicle is at a stop.
Definition: MEVehicle.cpp:231
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MEVehicle.cpp:168
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:282
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
Definition: MEVehicle.h:229
Position getPosition(const SUMOReal offset=0) const
Return current position (x/y, cartesian)
Definition: MEVehicle.cpp:106
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
void markDelayed() const
Definition: MSEdge.h:646
SUMOTime myLastEntryTime
The time the vehicle entered its current segment.
Definition: MEVehicle.h:335
Something on a lane to be noticed about vehicle movement.
void saveState(OutputDevice &out)
Saves the states of a vehicle.
Definition: MEVehicle.cpp:330
MESegment * mySegment
The segment the vehicle is at.
Definition: MEVehicle.h:326
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Definition: MEVehicle.cpp:145
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:180
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:271
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:296
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition: MEVehicle.h:221
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MEVehicle.cpp:84
std::map< const MESegment *const, SUMOTime > myStops
where to stop
Definition: MEVehicle.h:341
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
Definition: MEVehicle.h:183
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:214
SUMOTime myEventTime
The (planned) time of leaving the segment (cell)
Definition: MEVehicle.h:332
const ConstMSEdgeVector getStopEdges() const
Returns the list of still pending stop edges.
Definition: MEVehicle.cpp:252
bool mayProceed() const
Returns whether the vehicle is allowed to pass the next junction.
Definition: MEVehicle.cpp:262
SUMOTime myBlockTime
The time at which the vehicle was blocked on its current segment.
Definition: MEVehicle.h:338
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
MESegment * getSegment() const
Returns the current segment the vehicle is on.
Definition: MEVehicle.h:213
SUMOReal estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving accross the link.
Definition: MEVehicle.cpp:129
SUMOReal getAngle() const
Returns the vehicle's direction in degrees.
Definition: MEVehicle.cpp:92
MEVehicle(SUMOVehicleParameter *pars, const MSRoute *route, const MSVehicleType *type, const SUMOReal speedFactor)
Constructor.
Definition: MEVehicle.cpp:57