SUMO - Simulation of Urban MObility
MSLCM_LC2013.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013
22 /****************************************************************************/
23 #ifndef MSLCM_LC2013_h
24 #define MSLCM_LC2013_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
37 #include <vector>
38 
39 // INVALID_SPEED should be used when the construction of upper bound for the speed
40 // leads to no restrictions, e.g. during LC-messaging to followers or leaders.
41 // Currently either std::numeric_limits<...>.max() or -1 is used for this purpose in many places.
42 // TODO: implement this everywhere and remove workarounds for ballistic update in cases of possible '-1'-returns. Refs. #2577
43 #define INVALID_SPEED 299792458 + 1 // nothing can go faster than the speed of light!
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
55 public:
56 
57  enum MyLCAEnum {
60  LCA_MRIGHT = 1 << 18,
61  LCA_MLEFT = 1 << 19,
62  // !!! never set LCA_UNBLOCK = 1 << 20,
64  // !!! never used LCA_AMBLOCKINGSECONDFOLLOWER = 1 << 22,
65  LCA_CHANGE_TO_HELP = 1 << 23,
66  // !!! never read LCA_KEEP1 = 1 << 24,
67  // !!! never used LCA_KEEP2 = 1 << 25,
68  LCA_AMBACKBLOCKER = 1 << 26,
70  };
71 
72 
74 
75  virtual ~MSLCM_LC2013();
76 
78  void initDerivedParameters();
79 
80  bool debugVehicle() const;
81 
90  int wantsChange(
91  int laneOffset,
92  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
93  const std::pair<MSVehicle*, double>& leader,
94  const std::pair<MSVehicle*, double>& neighLead,
95  const std::pair<MSVehicle*, double>& neighFollow,
96  const MSLane& neighLane,
97  const std::vector<MSVehicle::LaneQ>& preb,
98  MSVehicle** lastBlocked,
99  MSVehicle** firstBlocked);
100 
101  void* inform(void* info, MSVehicle* sender);
102 
113  double patchSpeed(const double min, const double wanted, const double max,
114  const MSCFModel& cfModel);
116  double _patchSpeed(const double min, const double wanted, const double max,
117  const MSCFModel& cfModel);
118 
119  void changed();
120 
121  void prepareStep();
122 
124  std::string getParameter(const std::string& key) const;
125 
127  void setParameter(const std::string& key, const std::string& value);
128 
129 protected:
130 
132  int _wantsChange(
133  int laneOffset,
134  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
135  const std::pair<MSVehicle*, double>& leader,
136  const std::pair<MSVehicle*, double>& neighLead,
137  const std::pair<MSVehicle*, double>& neighFollow,
138  const MSLane& neighLane,
139  const std::vector<MSVehicle::LaneQ>& preb,
140  MSVehicle** lastBlocked,
141  MSVehicle** firstBlocked);
142 
143  /* @brief decide whether we will overtake or follow a blocking leader
144  * and inform it accordingly
145  * If we decide to follow, myVSafes will be extended
146  * returns the planned speed if following or -1 if overtaking */
148  int blocked, int dir,
149  const std::pair<MSVehicle*, double>& neighLead,
150  double remainingSeconds);
151 
154  int blocked, int dir,
155  const std::pair<MSVehicle*, double>& neighFollow,
156  double remainingSeconds,
157  double plannedSpeed);
158 
159 
160  /* @brief compute the distance to cover until a safe gap to the vehicle v in front is reached
161  * assuming constant velocities
162  * @param[in] follower the vehicle which overtakes
163  * @param[in] leader the vehicle to be overtaken
164  * @param[in] gap initial distance between front of follower and back of leader
165  * @param[in] leaderSpeed an assumed speed for the leader (default uses the current speed)
166  * @param[in] followerSpeed an assumed speed for the follower (default uses the current speed)
167  * @return the distance that the relative positions would have to change.
168  */
169  static double overtakeDistance(const MSVehicle* follower, const MSVehicle* leader, const double gap, double followerSpeed = INVALID_SPEED, double leaderSpeed = INVALID_SPEED);
170 
172  int slowDownForBlocked(MSVehicle** blocked, int state);
173 
174 
175  // XXX: consider relocation of the roundabout functions (perhaps to MSVehicle or the abstract LC Model...) (Leo)
185  static void
186  getRoundaboutAheadInfo(const MSLCM_LC2013* lcm, const MSVehicle::LaneQ& curr, const MSVehicle::LaneQ& neigh,
187  double& roundaboutDistanceAhead, double& roundaboutDistanceAheadNeigh, int& roundaboutEdgesAhead, int& roundaboutEdgesAheadNeigh);
188 
195  double
196  roundaboutDistBonus(double roundaboutDistAhead, int roundaboutEdgesAhead) const;
197 
203  static double
204  distanceAlongNextRoundabout(double position, const MSLane* initialLane, const std::vector<MSLane*>& continuationLanes);
205 
207  void saveBlockerLength(MSVehicle* blocker, int lcaCounter);
208 
210  void adaptSpeedToPedestrians(const MSLane* lane, double& v);
211 
213  inline void saveBlockerLength(double length) {
215  };
216 
217  inline bool amBlockingLeader() {
218  return (myOwnState & LCA_AMBLOCKINGLEADER) != 0;
219  }
220  inline bool amBlockingFollower() {
221  return (myOwnState & LCA_AMBLOCKINGFOLLOWER) != 0;
222  }
223  inline bool amBlockingFollowerNB() {
225  }
226  inline bool amBlockingFollowerPlusNB() {
228  }
229  inline bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist) {
230  return dist / (abs(laneOffset)) < lookForwardDist;
231  }
232  inline bool currentDistAllows(double dist, int laneOffset, double lookForwardDist) {
233  return dist / abs(laneOffset) > lookForwardDist;
234  }
235 
242  void addLCSpeedAdvice(const double vSafe);
243 
244 protected:
245 
247  typedef std::pair<double, int> Info;
248 
251  /* @brief a value for tracking the probability of following the/"Rechtsfahrgebot"
252  * A larger negative value indicates higher probability for moving to the
253  * right (as in mySpeedGainProbability) */
255 
257  double myLeftSpace;
258 
259  /*@brief the speed to use when computing the look-ahead distance for
260  * determining urgency of strategic lane changes */
262 
265  std::vector<double> myLCAccelerationAdvices;
266 
267  bool myDontBrake; // XXX: myDontBrake is initialized as false and seems not to be changed anywhere... What's its purpose???
268 
270 
272  double myCooperativeParam; // in [0,1]
275 
276  // @brief the factor by which the lookahead distance to the left differs from the lookahead to the right
278  // @brief the factor by which the speedGain-threshold for the leftdiffers from the threshold for the right
280 
281  const double myExperimentalParam1; // for feature testing
283 
285 
286  // @brief willingness to encroach on other vehicles laterally (pushing them around)
290 };
291 
292 
293 #endif
294 
295 /****************************************************************************/
296 
double myLeadingBlockerLength
Definition: MSLCM_LC2013.h:256
double patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)
Called to adapt the speed in order to allow a lane change. It uses information on LC-related desired ...
void saveBlockerLength(MSVehicle *blocker, int lcaCounter)
save space for vehicles which need to counter-lane-change
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
MSLCM_LC2013(MSVehicle &v)
bool amBlockingFollower()
Definition: MSLCM_LC2013.h:220
bool amBlockingFollowerNB()
Definition: MSLCM_LC2013.h:223
double myKeepRightProbability
Definition: MSLCM_LC2013.h:254
The car-following model abstraction.
Definition: MSCFModel.h:59
void addLCSpeedAdvice(const double vSafe)
Takes a vSafe (speed advice for speed in the next simulation step), converts it into an acceleration ...
double myChangeProbThresholdLeft
Definition: MSLCM_LC2013.h:288
double myLookAheadSpeed
Definition: MSLCM_LC2013.h:261
double myStrategicParam
Definition: MSLCM_LC2013.h:271
int _wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, double > &leader, const std::pair< MSVehicle *, double > &neighLead, const std::pair< MSVehicle *, double > &neighFollow, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked)
helper function for doing the actual work
double myKeepRightParam
Definition: MSLCM_LC2013.h:274
void initDerivedParameters()
init cached parameters derived directly from model parameters
T MAX2(T a, T b)
Definition: StdDefs.h:73
double _patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)
std::pair< double, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
Definition: MSLCM_LC2013.h:247
bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_LC2013.h:229
static double distanceAlongNextRoundabout(double position, const MSLane *initialLane, const std::vector< MSLane *> &continuationLanes)
compute the distance on the next upcoming roundabout along a given sequence of lanes.
bool debugVehicle() const
whether the current vehicles shall be debugged
A class responsible for exchanging messages between cars involved in lane-change interaction.
static double overtakeDistance(const MSVehicle *follower, const MSVehicle *leader, const double gap, double followerSpeed=INVALID_SPEED, double leaderSpeed=INVALID_SPEED)
A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013...
Definition: MSLCM_LC2013.h:54
double mySpeedGainParam
Definition: MSLCM_LC2013.h:273
double mySpeedGainProbability
a value for tracking the probability that a change to the offset with the same sign is beneficial ...
Definition: MSLCM_LC2013.h:250
void informFollower(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, double > &neighFollow, double remainingSeconds, double plannedSpeed)
decide whether we will try cut in before the follower or allow to be overtaken
double mySpeedGainRight
Definition: MSLCM_LC2013.h:279
bool currentDistAllows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_LC2013.h:232
const double myExperimentalParam1
Definition: MSLCM_LC2013.h:281
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
int wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, double > &leader, const std::pair< MSVehicle *, double > &neighLead, const std::pair< MSVehicle *, double > &neighFollow, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked)
Called to examine whether the vehicle wants to change using the given laneOffset. This method gets th...
A structure representing the best lanes for continuing the current route starting at &#39;lane&#39;...
Definition: MSVehicle.h:799
int myOwnState
The current state of the vehicle.
std::vector< double > myLCAccelerationAdvices
vector of LC-related acceleration recommendations Filled in wantsChange() and applied in patchSpeed()...
Definition: MSLCM_LC2013.h:265
double myLeftSpace
Definition: MSLCM_LC2013.h:257
double myLookaheadLeft
Definition: MSLCM_LC2013.h:277
double myChangeProbThresholdRight
Definition: MSLCM_LC2013.h:287
static void getRoundaboutAheadInfo(const MSLCM_LC2013 *lcm, const MSVehicle::LaneQ &curr, const MSVehicle::LaneQ &neigh, double &roundaboutDistanceAhead, double &roundaboutDistanceAheadNeigh, int &roundaboutEdgesAhead, int &roundaboutEdgesAheadNeigh)
computes the distance and number of edges in the next upcoming roundabout along the lane continuation...
void adaptSpeedToPedestrians(const MSLane *lane, double &v)
react to pedestrians on the given lane
void saveBlockerLength(double length)
reserve space at the end of the lane to avoid dead locks
Definition: MSLCM_LC2013.h:213
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this laneChangeModel. Throw exception for unsupported key ...
double myCooperativeParam
Definition: MSLCM_LC2013.h:272
virtual ~MSLCM_LC2013()
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key ...
bool amBlockingFollowerPlusNB()
Definition: MSLCM_LC2013.h:226
double informLeader(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, double > &neighLead, double remainingSeconds)
void * inform(void *info, MSVehicle *sender)
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
#define INVALID_SPEED
Definition: MSLCM_LC2013.h:43
Interface for lane-change models.
bool amBlockingLeader()
Definition: MSLCM_LC2013.h:217
double roundaboutDistBonus(double roundaboutDistAhead, int roundaboutEdgesAhead) const
Computes the artificial bonus distance for roundabout lanes this additional distance reduces the sens...