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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // Information about vehicles ahead (may be multiple vehicles if
19 // lateral-resolution is active)
20 /****************************************************************************/
21 #pragma once
22 #include <config.h>
23 
24 #include <string>
25 #include <vector>
26 #include <utils/common/StdDefs.h>
27 
28 // ===========================================================================
29 // class declarations
30 // ===========================================================================
31 class MSVehicle;
32 class MSLane;
33 
34 
35 // ===========================================================================
36 // types definitions
37 // ===========================================================================
38 typedef std::pair<const MSVehicle*, double> CLeaderDist;
39 typedef std::pair<MSVehicle*, double> LeaderDist;
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
47 class MSLeaderInfo {
48 public:
50  MSLeaderInfo(const MSLane* lane, const MSVehicle* ego = 0, double latOffset = 0);
51 
53  virtual ~MSLeaderInfo();
54 
55  /* @brief adds this vehicle as a leader in the appropriate sublanes
56  * @param[in] veh The vehicle to add
57  * @param[in] beyond Whether the vehicle is beyond the existing leaders (and thus may be shadowed by them)
58  * @param[in] latOffset The lateral offset that must be added to the position of veh
59  * @return The number of free sublanes
60  */
61  virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0);
62 
64  virtual void clear();
65 
66  /* @brief returns sublanes occupied by veh
67  * @param[in] veh The vehicle to check
68  * @param[in] latOffset The offset value to add to the vehicle position
69  * @param[out] rightmost The rightmost sublane occupied by veh
70  * @param[out] leftmost The rightmost sublane occupied by veh
71  */
72  void getSubLanes(const MSVehicle* veh, double latOffset, int& rightmost, int& leftmost) const;
73 
74  /* @brief returns the sublane boundaries of the ith sublane
75  * @param[in] sublane The sublane to check
76  * @param[in] latOffset The offset value to add to the result
77  * @param[out] rightSide The right border of the given sublane
78  * @param[out] leftSide The left border of the given sublane
79  */
80  void getSublaneBorders(int sublane, double latOffset, double& rightSide, double& leftSide) const;
81 
83  const MSVehicle* operator[](int sublane) const;
84 
85  int numSublanes() const {
86  return (int)myVehicles.size();
87  }
88 
89  int numFreeSublanes() const {
90  return myFreeSublanes;
91  }
92 
93  bool hasVehicles() const {
94  return myHasVehicles;
95  }
96 
97  const std::vector<const MSVehicle*>& getVehicles() const {
98  return myVehicles;
99  }
100 
102  bool hasStoppedVehicle() const;
103 
105  void removeOpposite(const MSLane* lane);
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 
175  void fixOppositeGaps(bool isFollower);
176 
178  CLeaderDist getClosest() const;
179 
180 protected:
181 
182  std::vector<double> myDistances;
183 
184 };
185 
186 
187 /* @brief saves follower vehicles and their distances as well as their required gap relative to an ego vehicle
188  * when adding new followers, the one with the largest required gap is recored
189  * (rather than the one with the smallest gap) */
191 public:
193  MSCriticalFollowerDistanceInfo(const MSLane* lane, const MSVehicle* ego, double latOffset, bool haveOppositeLeaders = false);
194 
197 
198  /* @brief adds this vehicle as a follower in the appropriate sublanes
199  * @param[in] veh The vehicle to add
200  * @param[in] ego The vehicle which is being followed
201  * @param[in] gap The distance from the back of ego to the follower
202  * @param[in] latOffset The lateral offset that must be added to the position of veh
203  * @param[in] sublane The single sublane to which this leader shall be checked (-1 means: check for all)
204  * @return The number of free sublanes
205  */
206  int addFollower(const MSVehicle* veh, const MSVehicle* ego, double gap, double latOffset = 0, int sublane = -1);
207 
208  virtual int addLeader(const MSVehicle* veh, double gap, double latOffset = 0, int sublane = -1) {
209  UNUSED_PARAMETER(veh);
210  UNUSED_PARAMETER(gap);
211  UNUSED_PARAMETER(latOffset);
212  UNUSED_PARAMETER(sublane);
213  throw ProcessError("Method not supported");
214  }
215 
216  virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0) {
217  UNUSED_PARAMETER(veh);
218  UNUSED_PARAMETER(beyond);
219  UNUSED_PARAMETER(latOffset);
220  throw ProcessError("Method not supported");
221  }
222 
224  void clear();
225 
227  std::string toString() const;
228 
229 protected:
230 
231  // @brief the differences between requriedGap and actual gap for each of the followers
232  std::vector<double> myMissingGaps;
233 
234  // @brief whether this Info objects tracks leaders instead of followers
236 
237 };
std::pair< MSVehicle *, double > LeaderDist
Definition: MSLeaderInfo.h:39
std::pair< const MSVehicle *, double > CLeaderDist
Definition: MSLeaderInfo.h:32
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
virtual int addLeader(const MSVehicle *veh, double gap, double latOffset=0, int sublane=-1)
Definition: MSLeaderInfo.h:208
std::vector< double > myMissingGaps
Definition: MSLeaderInfo.h:232
MSCriticalFollowerDistanceInfo(const MSLane *lane, const MSVehicle *ego, double latOffset, bool haveOppositeLeaders=false)
Constructor.
virtual ~MSCriticalFollowerDistanceInfo()
Destructor.
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
Definition: MSLeaderInfo.h:216
std::string toString() const
print a debugging representation
void clear()
discard all information
int addFollower(const MSVehicle *veh, const MSVehicle *ego, double gap, double latOffset=0, int sublane=-1)
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:133
const std::vector< double > & getDistances() const
Definition: MSLeaderInfo.h:170
virtual std::string toString() const
print a debugging representation
CLeaderDist getClosest() const
return vehicle with the smalles gap
virtual ~MSLeaderDistanceInfo()
Destructor.
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
Definition: MSLeaderInfo.h:154
CLeaderDist operator[](int sublane) const
return the vehicle and its distance for the given sublane
virtual void clear()
discard all information
std::vector< double > myDistances
Definition: MSLeaderInfo.h:182
void fixOppositeGaps(bool isFollower)
subtract vehicle length from all gaps if the leader vehicle is driving in the opposite direction
virtual int addLeader(const MSVehicle *veh, double gap, double latOffset=0, int sublane=-1)
MSLeaderDistanceInfo(const MSLane *lane, const MSVehicle *ego, double latOffset)
Constructor.
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
std::vector< const MSVehicle * > myVehicles
Definition: MSLeaderInfo.h:116
int myFreeSublanes
the number of free sublanes
Definition: MSLeaderInfo.h:121
bool hasStoppedVehicle() const
whether a stopped vehicle is leader
void removeOpposite(const MSLane *lane)
remove vehicles that are driving in the opposite direction (fully or partially) on the given lane
int egoRightMost
borders of the ego vehicle for filtering of free sublanes
Definition: MSLeaderInfo.h:124
int numFreeSublanes() const
Definition: MSLeaderInfo.h:89
void getSublaneBorders(int sublane, double latOffset, double &rightSide, double &leftSide) const
int numSublanes() const
Definition: MSLeaderInfo.h:85
MSLeaderInfo(const MSLane *lane, const MSVehicle *ego=0, double latOffset=0)
Constructor.
virtual std::string toString() const
print a debugging representation
virtual void clear()
discard all information
virtual ~MSLeaderInfo()
Destructor.
const MSVehicle * operator[](int sublane) const
return the vehicle for the given sublane
bool hasVehicles() const
Definition: MSLeaderInfo.h:93
void getSubLanes(const MSVehicle *veh, double latOffset, int &rightmost, int &leftmost) const
double myWidth
the width of the lane to which this instance applies
Definition: MSLeaderInfo.h:114
bool myHasVehicles
Definition: MSLeaderInfo.h:127
const std::vector< const MSVehicle * > & getVehicles() const
Definition: MSLeaderInfo.h:97
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:75