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>
27
28// ===========================================================================
29// class declarations
30// ===========================================================================
31class MSVehicle;
32class MSLane;
33
34
35// ===========================================================================
36// type definitions
37// ===========================================================================
38typedef std::pair<const MSVehicle*, double> CLeaderDist;
39typedef std::pair<MSVehicle*, double> LeaderDist;
40
41
42// ===========================================================================
43// class definitions
44// ===========================================================================
49public:
51 MSLeaderInfo(const double laneWidth, const MSVehicle* ego = nullptr, const double latOffset = 0.);
52
54 virtual ~MSLeaderInfo();
55
56 /* @brief adds this vehicle as a leader in the appropriate sublanes
57 * @param[in] veh The vehicle to add
58 * @param[in] beyond Whether the vehicle is beyond the existing leaders (and thus may be shadowed by them)
59 * @param[in] latOffset The lateral offset that must be added to the position of veh
60 * @return The number of free sublanes
61 */
62 virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0.);
63
65 virtual void clear();
66
67 /* @brief returns sublanes occupied by veh
68 * @param[in] veh The vehicle to check
69 * @param[in] latOffset The offset value to add to the vehicle position
70 * @param[out] rightmost The rightmost sublane occupied by veh
71 * @param[out] leftmost The rightmost sublane occupied by veh
72 */
73 void getSubLanes(const MSVehicle* veh, double latOffset, int& rightmost, int& leftmost) const;
74
75 /* @brief returns the sublane boundaries of the ith sublane
76 * @param[in] sublane The sublane to check
77 * @param[in] latOffset The offset value to add to the result
78 * @param[out] rightSide The right border of the given sublane
79 * @param[out] leftSide The left border of the given sublane
80 */
81 void getSublaneBorders(int sublane, double latOffset, double& rightSide, double& leftSide) const;
82
84 const MSVehicle* operator[](int sublane) const;
85
86 int numSublanes() const {
87 return (int)myVehicles.size();
88 }
89
90 int numFreeSublanes() const {
91 return myFreeSublanes;
92 }
93
94 bool hasVehicles() const {
95 return myHasVehicles;
96 }
97
98 const std::vector<const MSVehicle*>& getVehicles() const {
99 return myVehicles;
100 }
101
102 int getSublaneOffset() const {
103 return myOffset;
104 }
105
107 void setSublaneOffset(int offset);
108
110 bool hasStoppedVehicle() const;
111
113 void removeOpposite(const MSLane* lane);
114
116 virtual std::string toString() const;
117
118protected:
119
121 // @note: not const to simplify assignment
122 double myWidth;
123
126
127 std::vector<const MSVehicle*> myVehicles;
128
130 // if an ego vehicle is given in the constructor, the number of free
131 // sublanes of those covered by ego
133
137
139
140};
141
142
145public:
147 MSLeaderDistanceInfo(const double laneWidth, const MSVehicle* ego, const double latOffset);
148
150 MSLeaderDistanceInfo(const CLeaderDist& cLeaderDist, const double laneWidth);
151
153 virtual ~MSLeaderDistanceInfo();
154
155 /* @brief adds this vehicle as a leader in the appropriate sublanes
156 * @param[in] veh The vehicle to add
157 * @param[in] gap The gap between the egoFront+minGap to the back of veh
158 * or from the back of ego to the front+minGap of veh
159 * @param[in] latOffset The lateral offset that must be added to the position of veh
160 * @param[in] sublane The single sublane to which this leader shall be checked (-1 means: check for all)
161 * @return The number of free sublanes
162 */
163 virtual int addLeader(const MSVehicle* veh, double gap, double latOffset = 0, int sublane = -1);
164
165 virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0) {
166 UNUSED_PARAMETER(veh);
167 UNUSED_PARAMETER(beyond);
168 UNUSED_PARAMETER(latOffset);
169 throw ProcessError("Method not supported");
170 }
171
173 virtual void clear();
174
176 CLeaderDist operator[](int sublane) const;
177
179 virtual std::string toString() const;
180
181 const std::vector<double>& getDistances() const {
182 return myDistances;
183 }
184
186 void fixOppositeGaps(bool isFollower);
187
189 void patchGaps(double amount);
190
192 CLeaderDist getClosest() const;
193
194 void moveSamePosTo(const MSVehicle* ego, MSLeaderDistanceInfo& other);
195
196protected:
197
198 std::vector<double> myDistances;
199
200};
201
202
203/* @brief saves follower vehicles and their distances as well as their required gap relative to an ego vehicle
204 * when adding new followers, the one with the largest required gap is recored
205 * (rather than the one with the smallest gap) */
207public:
209 MSCriticalFollowerDistanceInfo(const double laneWidth, const MSVehicle* ego, const double latOffset, const bool haveOppositeLeaders = false);
210
213
214 /* @brief adds this vehicle as a follower in the appropriate sublanes
215 * @param[in] veh The vehicle to add
216 * @param[in] ego The vehicle which is being followed
217 * @param[in] gap The distance from the back of ego to the follower
218 * @param[in] latOffset The lateral offset that must be added to the position of veh
219 * @param[in] sublane The single sublane to which this leader shall be checked (-1 means: check for all)
220 * @return The number of free sublanes
221 */
222 int addFollower(const MSVehicle* veh, const MSVehicle* ego, double gap, double latOffset = 0, int sublane = -1);
223
224 virtual int addLeader(const MSVehicle* veh, double gap, double latOffset = 0, int sublane = -1) {
225 UNUSED_PARAMETER(veh);
226 UNUSED_PARAMETER(gap);
227 UNUSED_PARAMETER(latOffset);
228 UNUSED_PARAMETER(sublane);
229 throw ProcessError("Method not supported");
230 }
231
232 virtual int addLeader(const MSVehicle* veh, bool beyond, double latOffset = 0) {
233 UNUSED_PARAMETER(veh);
234 UNUSED_PARAMETER(beyond);
235 UNUSED_PARAMETER(latOffset);
236 throw ProcessError("Method not supported");
237 }
238
240 void clear();
241
243 std::string toString() const;
244
245protected:
246
247 // @brief the differences between requriedGap and actual gap for each of the followers
248 std::vector<double> myMissingGaps;
249
250 // @brief whether this Info objects tracks leaders instead of followers
252
253};
std::pair< MSVehicle *, double > LeaderDist
Definition: MSLeaderInfo.h:39
std::pair< const MSVehicle *, double > CLeaderDist
Definition: MSLeaderInfo.h:38
#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:224
std::vector< double > myMissingGaps
Definition: MSLeaderInfo.h:248
virtual ~MSCriticalFollowerDistanceInfo()
Destructor.
MSCriticalFollowerDistanceInfo(const double laneWidth, const MSVehicle *ego, const double latOffset, const bool haveOppositeLeaders=false)
Constructor.
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0)
Definition: MSLeaderInfo.h:232
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:84
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:144
virtual std::string toString() const
print a debugging representation
const std::vector< double > & getDistances() const
Definition: MSLeaderInfo.h:181
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:165
MSLeaderDistanceInfo(const double laneWidth, const MSVehicle *ego, const double latOffset)
Constructor.
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:198
void fixOppositeGaps(bool isFollower)
subtract vehicle length from all gaps if the leader vehicle is driving in the opposite direction
void patchGaps(double amount)
add given value to all gaps
virtual int addLeader(const MSVehicle *veh, double gap, double latOffset=0, int sublane=-1)
void moveSamePosTo(const MSVehicle *ego, MSLeaderDistanceInfo &other)
std::vector< const MSVehicle * > myVehicles
Definition: MSLeaderInfo.h:127
int myFreeSublanes
the number of free sublanes
Definition: MSLeaderInfo.h:132
int myOffset
an extra offset for shifting the interpretation of sublane borders (default [0,myWidth])
Definition: MSLeaderInfo.h:125
void setSublaneOffset(int offset)
set number of sublanes by which to shift positions
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:135
int numFreeSublanes() const
Definition: MSLeaderInfo.h:90
void getSublaneBorders(int sublane, double latOffset, double &rightSide, double &leftSide) const
int numSublanes() const
Definition: MSLeaderInfo.h:86
virtual int addLeader(const MSVehicle *veh, bool beyond, double latOffset=0.)
virtual std::string toString() const
print a debugging representation
virtual void clear()
discard all information
MSLeaderInfo(const double laneWidth, const MSVehicle *ego=nullptr, const double latOffset=0.)
Constructor.
virtual ~MSLeaderInfo()
Destructor.
const MSVehicle * operator[](int sublane) const
return the vehicle for the given sublane
bool hasVehicles() const
Definition: MSLeaderInfo.h:94
int getSublaneOffset() const
Definition: MSLeaderInfo.h:102
void getSubLanes(const MSVehicle *veh, double latOffset, int &rightmost, int &leftmost) const
const std::vector< const MSVehicle * > & getVehicles() const
Definition: MSLeaderInfo.h:98
double myWidth
the width of the lane to which this instance applies
Definition: MSLeaderInfo.h:122
bool myHasVehicles
Definition: MSLeaderInfo.h:138
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77