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