SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSLeaderInfo.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // Information about vehicles ahead (may be multiple vehicles if
8 // lateral-resolution is active)
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2002-2016 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef MSLeaderInfo_h
22 #define MSLeaderInfo_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <vector>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class MSVehicle;
42 class MSLane;
43 
44 
45 // ===========================================================================
46 // types definitions
47 // ===========================================================================
48 typedef std::pair<const MSVehicle*, SUMOReal> CLeaderDist;
49 typedef std::pair<MSVehicle*, SUMOReal> LeaderDist;
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
57 class MSLeaderInfo {
58 public:
60  MSLeaderInfo(const MSLane* lane, const MSVehicle* ego = 0, SUMOReal latOffset = 0);
61 
63  virtual ~MSLeaderInfo();
64 
65  /* @brief adds this vehicle as a leader in the appropriate sublanes
66  * @param[in] veh The vehicle to add
67  * @param[in] beyond Whether the vehicle is beyond the existing leaders (and thus may be shadowed by them)
68  * @param[in] latOffset The lateral offset that must be added to the position of veh
69  * @return The number of free sublanes
70  */
71  virtual int addLeader(const MSVehicle* veh, bool beyond, SUMOReal latOffset = 0);
72 
74  virtual void clear();
75 
76  /* @brief adds this vehicle as a leader in the appropriate sublanes
77  * @param[in] veh The vehicle to check
78  * @param[out] rightmost The rightmost sublane occupied by veh
79  * @param[out] leftmost The rightmost sublane occupied by veh
80  */
81  void getSubLanes(const MSVehicle* veh, SUMOReal latOffset, int& rightmost, int& leftmost) 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 
99  bool hasStoppedVehicle() const;
100 
102  virtual std::string toString() const;
103 
104 protected:
105 
107  // @note: not const to simplify assignment
109 
110  std::vector<const MSVehicle*> myVehicles;
111 
113  // if an ego vehicle is given in the constructor, the number of free
114  // sublanes of those covered by ego
116 
120 
122 
123 };
124 
125 
128 public:
130  MSLeaderDistanceInfo(const MSLane* lane, const MSVehicle* ego, SUMOReal latOffset);
131 
133  virtual ~MSLeaderDistanceInfo();
134 
135  /* @brief adds this vehicle as a leader in the appropriate sublanes
136  * @param[in] veh The vehicle to add
137  * @param[in] gap The gap between the egoFront+minGap to the back of veh
138  * or from the back of ego to the front+minGap of veh
139  * @param[in] latOffset The lateral offset that must be added to the position of veh
140  * @param[in] sublane The single sublane to which this leader shall be checked (-1 means: check for all)
141  * @return The number of free sublanes
142  */
143  virtual int addLeader(const MSVehicle* veh, SUMOReal gap, SUMOReal latOffset = 0, int sublane = -1);
144 
145  virtual int addLeader(const MSVehicle* veh, bool beyond, SUMOReal latOffset = 0) {
146  UNUSED_PARAMETER(veh);
147  UNUSED_PARAMETER(beyond);
148  UNUSED_PARAMETER(latOffset);
149  throw ProcessError("Method not supported");
150  }
151 
153  virtual void clear();
154 
156  CLeaderDist operator[](int sublane) const;
157 
159  virtual std::string toString() const;
160 
161 protected:
162 
163  std::vector<SUMOReal> myDistances;
164 
165 };
166 
167 
168 /* @brief saves follower vehicles and their distances as well as their required gap relative to an ego vehicle
169  * when adding new followers, the one with the largest required gap is recored
170  * (rather than the one with the smallest gap) */
172 public:
174  MSCriticalFollowerDistanceInfo(const MSLane* lane, const MSVehicle* ego, SUMOReal latOffset);
175 
178 
179  /* @brief adds this vehicle as a follower in the appropriate sublanes
180  * @param[in] veh The vehicle to add
181  * @param[in] ego The vehicle which is being followed
182  * @param[in] gap The distance from the back of ego to the follower
183  * @param[in] latOffset The lateral offset that must be added to the position of veh
184  * @param[in] sublane The single sublane to which this leader shall be checked (-1 means: check for all)
185  * @return The number of free sublanes
186  */
187  int addFollower(const MSVehicle* veh, const MSVehicle* ego, SUMOReal gap, SUMOReal latOffset = 0, int sublane = -1);
188 
189  virtual int addLeader(const MSVehicle* veh, SUMOReal gap, SUMOReal latOffset = 0, int sublane = -1) {
190  UNUSED_PARAMETER(veh);
191  UNUSED_PARAMETER(gap);
192  UNUSED_PARAMETER(latOffset);
193  UNUSED_PARAMETER(sublane);
194  throw ProcessError("Method not supported");
195  }
196 
197  virtual int addLeader(const MSVehicle* veh, bool beyond, SUMOReal latOffset = 0) {
198  UNUSED_PARAMETER(veh);
199  UNUSED_PARAMETER(beyond);
200  UNUSED_PARAMETER(latOffset);
201  throw ProcessError("Method not supported");
202  }
203 
205  void clear();
206 
208  std::string toString() const;
209 
210 protected:
211 
212  // @brief the differences between requriedGap and actual gap for each of the followers
213  std::vector<SUMOReal> myMissingGaps;
214 
215 };
216 
217 #endif
218 
219 /****************************************************************************/
220 
std::vector< SUMOReal > myDistances
Definition: MSLeaderInfo.h:163
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:127
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
virtual std::string toString() const
print a debugging representation
std::pair< MSVehicle *, SUMOReal > LeaderDist
Definition: MSLeaderInfo.h:49
int numSublanes() const
Definition: MSLeaderInfo.h:86
virtual ~MSCriticalFollowerDistanceInfo()
Destructor.
virtual std::string toString() const
print a debugging representation
int myFreeSublanes
the number of free sublanes
Definition: MSLeaderInfo.h:115
virtual void clear()
discard all information
MSLeaderInfo(const MSLane *lane, const MSVehicle *ego=0, SUMOReal latOffset=0)
Constructor.
std::pair< const MSVehicle *, SUMOReal > CLeaderDist
Definition: MSLeaderInfo.h:42
virtual int addLeader(const MSVehicle *veh, SUMOReal gap, SUMOReal latOffset=0, int sublane=-1)
Definition: MSLeaderInfo.h:189
int egoRightMost
borders of the ego vehicle for filtering of free sublanes
Definition: MSLeaderInfo.h:118
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
bool hasVehicles() const
Definition: MSLeaderInfo.h:94
bool hasStoppedVehicle() const
whether a stopped vehicle is leader
CLeaderDist operator[](int sublane) const
return the vehicle and its distance for the given sublane
int numFreeSublanes() const
Definition: MSLeaderInfo.h:90
std::vector< SUMOReal > myMissingGaps
Definition: MSLeaderInfo.h:213
virtual ~MSLeaderInfo()
Destructor.
virtual void clear()
discard all information
const MSVehicle * operator[](int sublane) const
return the vehicle for the given sublane
virtual int addLeader(const MSVehicle *veh, bool beyond, SUMOReal latOffset=0)
Definition: MSLeaderInfo.h:197
virtual int addLeader(const MSVehicle *veh, bool beyond, SUMOReal latOffset=0)
void clear()
discard all information
virtual int addLeader(const MSVehicle *veh, SUMOReal gap, SUMOReal latOffset=0, int sublane=-1)
virtual ~MSLeaderDistanceInfo()
Destructor.
void getSubLanes(const MSVehicle *veh, SUMOReal latOffset, int &rightmost, int &leftmost) const
std::vector< const MSVehicle * > myVehicles
Definition: MSLeaderInfo.h:110
int addFollower(const MSVehicle *veh, const MSVehicle *ego, SUMOReal gap, SUMOReal latOffset=0, int sublane=-1)
MSCriticalFollowerDistanceInfo(const MSLane *lane, const MSVehicle *ego, SUMOReal latOffset)
Constructor.
bool myHasVehicles
Definition: MSLeaderInfo.h:121
SUMOReal myWidth
the width of the lane to which this instance applies
Definition: MSLeaderInfo.h:108
#define SUMOReal
Definition: config.h:214
std::string toString() const
print a debugging representation
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
virtual int addLeader(const MSVehicle *veh, bool beyond, SUMOReal latOffset=0)
Definition: MSLeaderInfo.h:145
MSLeaderDistanceInfo(const MSLane *lane, const MSVehicle *ego, SUMOReal latOffset)
Constructor.