Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // Information about vehicles ahead (may be multiple vehicles if
16 // lateral-resolution is active)
17 /****************************************************************************/
18 #ifndef MSLeaderInfo_h
19 #define MSLeaderInfo_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <vector>
29 
30 
31 // ===========================================================================
32 // class declarations
33 // ===========================================================================
34 class MSVehicle;
35 class MSLane;
36 
37 
38 // ===========================================================================
39 // types definitions
40 // ===========================================================================
41 typedef std::pair<const MSVehicle*, double> CLeaderDist;
42 typedef std::pair<MSVehicle*, double> LeaderDist;
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
50 class MSLeaderInfo {
51 public:
53  MSLeaderInfo(const MSLane* lane, const MSVehicle* ego = 0, double latOffset = 0);
54 
56  virtual ~MSLeaderInfo();
57 
58  /* @brief adds this vehicle as a leader in the appropriate sublanes
59  * @param[in] veh The vehicle to add
60  * @param[in] beyond Whether the vehicle is beyond the existing leaders (and thus may be shadowed by them)
61  * @param[in] latOffset The lateral offset that must be added to the position of veh
62  * @return The number of free sublanes
63  */
64  virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0);
65 
67  virtual void clear();
68 
69  /* @brief returns sublanes occupied by veh
70  * @param[in] veh The vehicle to check
71  * @param[in] latOffset The offset value to add to the vehicle position
72  * @param[out] rightmost The rightmost sublane occupied by veh
73  * @param[out] leftmost The rightmost sublane occupied by veh
74  */
75  void getSubLanes(const MSVehicle* veh, double latOffset, int& rightmost, int& leftmost) const;
76 
77  /* @brief returns the sublane boundaries of the ith sublane
78  * @param[in] sublane The sublane to check
79  * @param[in] latOffset The offset value to add to the result
80  * @param[out] rightSide The right border of the given sublane
81  * @param[out] leftSide The left border of the given sublane
82  */
83  void getSublaneBorders(int sublane, double latOffset, double& rightSide, double& leftSide) const;
84 
86  const MSVehicle* operator[](int sublane) const;
87 
88  int numSublanes() const {
89  return (int)myVehicles.size();
90  }
91 
92  int numFreeSublanes() const {
93  return myFreeSublanes;
94  }
95 
96  bool hasVehicles() const {
97  return myHasVehicles;
98  }
99 
100  const std::vector<const MSVehicle*>& getVehicles() const {
101  return myVehicles;
102  }
103 
105  bool hasStoppedVehicle() const;
106 
108  virtual std::string toString() const;
109 
110 protected:
111 
113  // @note: not const to simplify assignment
114  double myWidth;
115 
116  std::vector<const MSVehicle*> myVehicles;
117 
119  // if an ego vehicle is given in the constructor, the number of free
120  // sublanes of those covered by ego
122 
126 
128 
129 };
130 
131 
134 public:
136  MSLeaderDistanceInfo(const MSLane* lane, const MSVehicle* ego, double latOffset);
137 
139  MSLeaderDistanceInfo(const CLeaderDist& cLeaderDist, const MSLane* dummy);
140 
142  virtual ~MSLeaderDistanceInfo();
143 
144  /* @brief adds this vehicle as a leader in the appropriate sublanes
145  * @param[in] veh The vehicle to add
146  * @param[in] gap The gap between the egoFront+minGap to the back of veh
147  * or from the back of ego to the front+minGap of veh
148  * @param[in] latOffset The lateral offset that must be added to the position of veh
149  * @param[in] sublane The single sublane to which this leader shall be checked (-1 means: check for all)
150  * @return The number of free sublanes
151  */
152  virtual int addLeader(const MSVehicle* veh, double gap, double latOffset = 0, int sublane = -1);
153 
154  virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0) {
155  UNUSED_PARAMETER(veh);
156  UNUSED_PARAMETER(beyond);
157  UNUSED_PARAMETER(latOffset);
158  throw ProcessError("Method not supported");
159  }
160 
162  virtual void clear();
163 
165  CLeaderDist operator[](int sublane) const;
166 
168  virtual std::string toString() const;
169 
170  const std::vector<double>& getDistances() const {
171  return myDistances;
172  }
173 
174 protected:
175 
176  std::vector<double> myDistances;
177 
178 };
179 
180 
181 /* @brief saves follower vehicles and their distances as well as their required gap relative to an ego vehicle
182  * when adding new followers, the one with the largest required gap is recored
183  * (rather than the one with the smallest gap) */
185 public:
187  MSCriticalFollowerDistanceInfo(const MSLane* lane, const MSVehicle* ego, double latOffset);
188 
191 
192  /* @brief adds this vehicle as a follower in the appropriate sublanes
193  * @param[in] veh The vehicle to add
194  * @param[in] ego The vehicle which is being followed
195  * @param[in] gap The distance from the back of ego to the follower
196  * @param[in] latOffset The lateral offset that must be added to the position of veh
197  * @param[in] sublane The single sublane to which this leader shall be checked (-1 means: check for all)
198  * @return The number of free sublanes
199  */
200  int addFollower(const MSVehicle* veh, const MSVehicle* ego, double gap, double latOffset = 0, int sublane = -1);
201 
202  virtual int addLeader(const MSVehicle* veh, double gap, double latOffset = 0, int sublane = -1) {
203  UNUSED_PARAMETER(veh);
204  UNUSED_PARAMETER(gap);
205  UNUSED_PARAMETER(latOffset);
206  UNUSED_PARAMETER(sublane);
207  throw ProcessError("Method not supported");
208  }
209 
210  virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0) {
211  UNUSED_PARAMETER(veh);
212  UNUSED_PARAMETER(beyond);
213  UNUSED_PARAMETER(latOffset);
214  throw ProcessError("Method not supported");
215  }
216 
218  void clear();
219 
221  std::string toString() const;
222 
223 protected:
224 
225  // @brief the differences between requriedGap and actual gap for each of the followers
226  std::vector<double> myMissingGaps;
227 
228 };
229 
230 #endif
231 
232 /****************************************************************************/
233 
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:133
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
int myFreeSublanes
the number of free sublanes
Definition: MSLeaderInfo.h:121
virtual void clear()
discard all information
int egoRightMost
borders of the ego vehicle for filtering of free sublanes
Definition: MSLeaderInfo.h:124
double myWidth
the width of the lane to which this instance applies
Definition: MSLeaderInfo.h:114
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:32
virtual int addLeader(const MSVehicle *veh, double gap, double latOffset=0, int sublane=-1)
Definition: MSLeaderInfo.h:202
std::vector< double > myDistances
Definition: MSLeaderInfo.h:176
std::vector< double > myMissingGaps
Definition: MSLeaderInfo.h:226
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:116
bool hasStoppedVehicle() const
whether a stopped vehicle is leader
virtual std::string toString() const
print a debugging representation
bool myHasVehicles
Definition: MSLeaderInfo.h:127
const std::vector< const MSVehicle * > & getVehicles() const
Definition: MSLeaderInfo.h:100
std::pair< const MSVehicle *, double > CLeaderDist
Definition: MSLeaderInfo.h:35
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
Definition: MSLeaderInfo.h:154
void getSublaneBorders(int sublane, double latOffset, double &rightSide, double &leftSide) const
bool hasVehicles() const
Definition: MSLeaderInfo.h:96
int numSublanes() const
Definition: MSLeaderInfo.h:88
int numFreeSublanes() const
Definition: MSLeaderInfo.h:92
std::pair< MSVehicle *, double > LeaderDist
Definition: MSLeaderInfo.h:42
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
Definition: MSLeaderInfo.h:210
MSLeaderInfo(const MSLane *lane, const MSVehicle *ego=0, double latOffset=0)
Constructor.
const std::vector< double > & getDistances() const
Definition: MSLeaderInfo.h:170
Representation of a lane in the micro simulation.
Definition: MSLane.h:83