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-2018 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 
101  bool hasStoppedVehicle() const;
102 
104  virtual std::string toString() const;
105 
106 protected:
107 
109  // @note: not const to simplify assignment
110  double myWidth;
111 
112  std::vector<const MSVehicle*> myVehicles;
113 
115  // if an ego vehicle is given in the constructor, the number of free
116  // sublanes of those covered by ego
118 
122 
124 
125 };
126 
127 
130 public:
132  MSLeaderDistanceInfo(const MSLane* lane, const MSVehicle* ego, double latOffset);
133 
135  MSLeaderDistanceInfo(const CLeaderDist& cLeaderDist, const MSLane* dummy);
136 
138  virtual ~MSLeaderDistanceInfo();
139 
140  /* @brief adds this vehicle as a leader in the appropriate sublanes
141  * @param[in] veh The vehicle to add
142  * @param[in] gap The gap between the egoFront+minGap to the back of veh
143  * or from the back of ego to the front+minGap of veh
144  * @param[in] latOffset The lateral offset that must be added to the position of veh
145  * @param[in] sublane The single sublane to which this leader shall be checked (-1 means: check for all)
146  * @return The number of free sublanes
147  */
148  virtual int addLeader(const MSVehicle* veh, double gap, double latOffset = 0, int sublane = -1);
149 
150  virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0) {
151  UNUSED_PARAMETER(veh);
152  UNUSED_PARAMETER(beyond);
153  UNUSED_PARAMETER(latOffset);
154  throw ProcessError("Method not supported");
155  }
156 
158  virtual void clear();
159 
161  CLeaderDist operator[](int sublane) const;
162 
164  virtual std::string toString() const;
165 
166 protected:
167 
168  std::vector<double> myDistances;
169 
170 };
171 
172 
173 /* @brief saves follower vehicles and their distances as well as their required gap relative to an ego vehicle
174  * when adding new followers, the one with the largest required gap is recored
175  * (rather than the one with the smallest gap) */
177 public:
179  MSCriticalFollowerDistanceInfo(const MSLane* lane, const MSVehicle* ego, double latOffset);
180 
183 
184  /* @brief adds this vehicle as a follower in the appropriate sublanes
185  * @param[in] veh The vehicle to add
186  * @param[in] ego The vehicle which is being followed
187  * @param[in] gap The distance from the back of ego to the follower
188  * @param[in] latOffset The lateral offset that must be added to the position of veh
189  * @param[in] sublane The single sublane to which this leader shall be checked (-1 means: check for all)
190  * @return The number of free sublanes
191  */
192  int addFollower(const MSVehicle* veh, const MSVehicle* ego, double gap, double latOffset = 0, int sublane = -1);
193 
194  virtual int addLeader(const MSVehicle* veh, double gap, double latOffset = 0, int sublane = -1) {
195  UNUSED_PARAMETER(veh);
196  UNUSED_PARAMETER(gap);
197  UNUSED_PARAMETER(latOffset);
198  UNUSED_PARAMETER(sublane);
199  throw ProcessError("Method not supported");
200  }
201 
202  virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0) {
203  UNUSED_PARAMETER(veh);
204  UNUSED_PARAMETER(beyond);
205  UNUSED_PARAMETER(latOffset);
206  throw ProcessError("Method not supported");
207  }
208 
210  void clear();
211 
213  std::string toString() const;
214 
215 protected:
216 
217  // @brief the differences between requriedGap and actual gap for each of the followers
218  std::vector<double> myMissingGaps;
219 
220 };
221 
222 #endif
223 
224 /****************************************************************************/
225 
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:129
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
int myFreeSublanes
the number of free sublanes
Definition: MSLeaderInfo.h:117
virtual void clear()
discard all information
int egoRightMost
borders of the ego vehicle for filtering of free sublanes
Definition: MSLeaderInfo.h:120
double myWidth
the width of the lane to which this instance applies
Definition: MSLeaderInfo.h:110
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:33
virtual int addLeader(const MSVehicle *veh, double gap, double latOffset=0, int sublane=-1)
Definition: MSLeaderInfo.h:194
std::vector< double > myDistances
Definition: MSLeaderInfo.h:168
std::vector< double > myMissingGaps
Definition: MSLeaderInfo.h:218
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:112
bool hasStoppedVehicle() const
whether a stopped vehicle is leader
virtual std::string toString() const
print a debugging representation
bool myHasVehicles
Definition: MSLeaderInfo.h:123
std::pair< const MSVehicle *, double > CLeaderDist
Definition: MSLeaderInfo.h:35
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
Definition: MSLeaderInfo.h:150
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:202
MSLeaderInfo(const MSLane *lane, const MSVehicle *ego=0, double latOffset=0)
Constructor.
Representation of a lane in the micro simulation.
Definition: MSLane.h:78