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