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 /****************************************************************************/ 10 /// @file MSLeaderInfo.h 11 /// @author Jakob Erdmann 12 /// @date Oct 2015 13 /// @version $Id$ 14 /// 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 // =========================================================================== 47 /** 48 * @class MSLeaderInfo 49 */ 50 class MSLeaderInfo { 51 public: 52 /// Constructor 53 MSLeaderInfo(const MSLane* lane, const MSVehicle* ego = 0, double latOffset = 0); 54 55 /// Destructor 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 66 /// @brief discard all information 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 85 /// @brief return the vehicle for the given sublane 86 const MSVehicle* operator[](int sublane) const; 87 numSublanes()88 int numSublanes() const { 89 return (int)myVehicles.size(); 90 } 91 numFreeSublanes()92 int numFreeSublanes() const { 93 return myFreeSublanes; 94 } 95 hasVehicles()96 bool hasVehicles() const { 97 return myHasVehicles; 98 } 99 getVehicles()100 const std::vector<const MSVehicle*>& getVehicles() const { 101 return myVehicles; 102 } 103 104 /// @brief whether a stopped vehicle is leader 105 bool hasStoppedVehicle() const; 106 107 /// @brief print a debugging representation 108 virtual std::string toString() const; 109 110 protected: 111 112 /// @brief the width of the lane to which this instance applies 113 // @note: not const to simplify assignment 114 double myWidth; 115 116 std::vector<const MSVehicle*> myVehicles; 117 118 /// @brief the number of free sublanes 119 // if an ego vehicle is given in the constructor, the number of free 120 // sublanes of those covered by ego 121 int myFreeSublanes; 122 123 /// @brief borders of the ego vehicle for filtering of free sublanes 124 int egoRightMost; 125 int egoLeftMost; 126 127 bool myHasVehicles; 128 129 }; 130 131 132 /// @brief saves leader/follower vehicles and their distances relative to an ego vehicle 133 class MSLeaderDistanceInfo : public MSLeaderInfo { 134 public: 135 /// Constructor 136 MSLeaderDistanceInfo(const MSLane* lane, const MSVehicle* ego, double latOffset); 137 138 /// @brief Construct for the non-sublane-case 139 MSLeaderDistanceInfo(const CLeaderDist& cLeaderDist, const MSLane* dummy); 140 141 /// Destructor 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 161 /// @brief discard all information 162 virtual void clear(); 163 164 /// @brief return the vehicle and its distance for the given sublane 165 CLeaderDist operator[](int sublane) const; 166 167 /// @brief print a debugging representation 168 virtual std::string toString() const; 169 getDistances()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) */ 184 class MSCriticalFollowerDistanceInfo : public MSLeaderDistanceInfo { 185 public: 186 /// Constructor 187 MSCriticalFollowerDistanceInfo(const MSLane* lane, const MSVehicle* ego, double latOffset); 188 189 /// Destructor 190 virtual ~MSCriticalFollowerDistanceInfo(); 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 217 /// @brief discard all information 218 void clear(); 219 220 /// @brief print a debugging representation 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 234