SUMO - Simulation of Urban MObility
MSLeaderInfo.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-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 // Information about vehicles ahead (may be multiple vehicles if
18 // lateral-resolution is active)
19 /****************************************************************************/
20 #ifndef MSLeaderInfo_h
21 #define MSLeaderInfo_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 <string>
34 #include <vector>
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class MSVehicle;
41 class MSLane;
42 
43 
44 // ===========================================================================
45 // types definitions
46 // ===========================================================================
47 typedef std::pair<const MSVehicle*, double> CLeaderDist;
48 typedef std::pair<MSVehicle*, double> LeaderDist;
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
56 class MSLeaderInfo {
57 public:
59  MSLeaderInfo(const MSLane* lane, const MSVehicle* ego = 0, double latOffset = 0);
60 
62  virtual ~MSLeaderInfo();
63 
64  /* @brief adds this vehicle as a leader in the appropriate sublanes
65  * @param[in] veh The vehicle to add
66  * @param[in] beyond Whether the vehicle is beyond the existing leaders (and thus may be shadowed by them)
67  * @param[in] latOffset The lateral offset that must be added to the position of veh
68  * @return The number of free sublanes
69  */
70  virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0);
71 
73  virtual void clear();
74 
75  /* @brief returns sublanes occupied by veh
76  * @param[in] veh The vehicle to check
77  * @param[in] latOffset The offset value to add to the vehicle position
78  * @param[out] rightmost The rightmost sublane occupied by veh
79  * @param[out] leftmost The rightmost sublane occupied by veh
80  */
81  void getSubLanes(const MSVehicle* veh, double latOffset, int& rightmost, int& leftmost) const;
82 
83  /* @brief returns the sublane boundaries of the ith sublane
84  * @param[in] sublane The sublane to check
85  * @param[in] latOffset The offset value to add to the result
86  * @param[out] rightSide The right border of the given sublane
87  * @param[out] leftSide The left border of the given sublane
88  */
89  void getSublaneBorders(int sublane, double latOffset, double& rightSide, double& leftSide) const;
90 
92  const MSVehicle* operator[](int sublane) const;
93 
94  int numSublanes() const {
95  return (int)myVehicles.size();
96  }
97 
98  int numFreeSublanes() const {
99  return myFreeSublanes;
100  }
101 
102  bool hasVehicles() const {
103  return myHasVehicles;
104  }
105 
107  bool hasStoppedVehicle() const;
108 
110  virtual std::string toString() const;
111 
112 protected:
113 
115  // @note: not const to simplify assignment
116  double myWidth;
117 
118  std::vector<const MSVehicle*> myVehicles;
119 
121  // if an ego vehicle is given in the constructor, the number of free
122  // sublanes of those covered by ego
124 
128 
130 
131 };
132 
133 
136 public:
138  MSLeaderDistanceInfo(const MSLane* lane, const MSVehicle* ego, double latOffset);
139 
141  MSLeaderDistanceInfo(const CLeaderDist& cLeaderDist, const MSLane* dummy);
142 
144  virtual ~MSLeaderDistanceInfo();
145 
146  /* @brief adds this vehicle as a leader in the appropriate sublanes
147  * @param[in] veh The vehicle to add
148  * @param[in] gap The gap between the egoFront+minGap to the back of veh
149  * or from the back of ego to the front+minGap of veh
150  * @param[in] latOffset The lateral offset that must be added to the position of veh
151  * @param[in] sublane The single sublane to which this leader shall be checked (-1 means: check for all)
152  * @return The number of free sublanes
153  */
154  virtual int addLeader(const MSVehicle* veh, double gap, double latOffset = 0, int sublane = -1);
155 
156  virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0) {
157  UNUSED_PARAMETER(veh);
158  UNUSED_PARAMETER(beyond);
159  UNUSED_PARAMETER(latOffset);
160  throw ProcessError("Method not supported");
161  }
162 
164  virtual void clear();
165 
167  CLeaderDist operator[](int sublane) const;
168 
170  virtual std::string toString() const;
171 
172 protected:
173 
174  std::vector<double> myDistances;
175 
176 };
177 
178 
179 /* @brief saves follower vehicles and their distances as well as their required gap relative to an ego vehicle
180  * when adding new followers, the one with the largest required gap is recored
181  * (rather than the one with the smallest gap) */
183 public:
185  MSCriticalFollowerDistanceInfo(const MSLane* lane, const MSVehicle* ego, double latOffset);
186 
189 
190  /* @brief adds this vehicle as a follower in the appropriate sublanes
191  * @param[in] veh The vehicle to add
192  * @param[in] ego The vehicle which is being followed
193  * @param[in] gap The distance from the back of ego to the follower
194  * @param[in] latOffset The lateral offset that must be added to the position of veh
195  * @param[in] sublane The single sublane to which this leader shall be checked (-1 means: check for all)
196  * @return The number of free sublanes
197  */
198  int addFollower(const MSVehicle* veh, const MSVehicle* ego, double gap, double latOffset = 0, int sublane = -1);
199 
200  virtual int addLeader(const MSVehicle* veh, double gap, double latOffset = 0, int sublane = -1) {
201  UNUSED_PARAMETER(veh);
202  UNUSED_PARAMETER(gap);
203  UNUSED_PARAMETER(latOffset);
204  UNUSED_PARAMETER(sublane);
205  throw ProcessError("Method not supported");
206  }
207 
208  virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0) {
209  UNUSED_PARAMETER(veh);
210  UNUSED_PARAMETER(beyond);
211  UNUSED_PARAMETER(latOffset);
212  throw ProcessError("Method not supported");
213  }
214 
216  void clear();
217 
219  std::string toString() const;
220 
221 protected:
222 
223  // @brief the differences between requriedGap and actual gap for each of the followers
224  std::vector<double> myMissingGaps;
225 
226 };
227 
228 #endif
229 
230 /****************************************************************************/
231 
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:135
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
int myFreeSublanes
the number of free sublanes
Definition: MSLeaderInfo.h:123
virtual void clear()
discard all information
int egoRightMost
borders of the ego vehicle for filtering of free sublanes
Definition: MSLeaderInfo.h:126
double myWidth
the width of the lane to which this instance applies
Definition: MSLeaderInfo.h:116
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
virtual int addLeader(const MSVehicle *veh, double gap, double latOffset=0, int sublane=-1)
Definition: MSLeaderInfo.h:200
std::vector< double > myDistances
Definition: MSLeaderInfo.h:174
std::vector< double > myMissingGaps
Definition: MSLeaderInfo.h:224
virtual ~MSLeaderInfo()
Destructor.
const MSVehicle * operator[](int sublane) const
return the vehicle for the given sublane
void getSubLanes(const MSVehicle *veh, double latOffset, int &rightmost, int &leftmost) const
std::vector< const MSVehicle * > myVehicles
Definition: MSLeaderInfo.h:118
bool hasStoppedVehicle() const
whether a stopped vehicle is leader
virtual std::string toString() const
print a debugging representation
bool myHasVehicles
Definition: MSLeaderInfo.h:129
std::pair< const MSVehicle *, double > CLeaderDist
Definition: MSLeaderInfo.h:41
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
Definition: MSLeaderInfo.h:156
void getSublaneBorders(int sublane, double latOffset, double &rightSide, double &leftSide) const
bool hasVehicles() const
Definition: MSLeaderInfo.h:102
int numSublanes() const
Definition: MSLeaderInfo.h:94
int numFreeSublanes() const
Definition: MSLeaderInfo.h:98
std::pair< MSVehicle *, double > LeaderDist
Definition: MSLeaderInfo.h:48
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
Definition: MSLeaderInfo.h:208
MSLeaderInfo(const MSLane *lane, const MSVehicle *ego=0, double latOffset=0)
Constructor.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77