Eclipse 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-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 /****************************************************************************/
22 // A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013
23 /****************************************************************************/
24 #pragma once
25 #include <config.h>
26 
28 #include <vector>
29 
30 // INVALID_SPEED should be used when the construction of upper bound for the speed
31 // leads to no restrictions, e.g. during LC-messaging to followers or leaders.
32 // Currently either std::numeric_limits<...>.max() or -1 is used for this purpose in many places.
33 // TODO: implement this everywhere and remove workarounds for ballistic update in cases of possible '-1'-returns. Refs. #2577
34 #define INVALID_SPEED 299792458 + 1 // nothing can go faster than the speed of light!
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
46 public:
47 
49 
50  virtual ~MSLCM_LC2013();
51 
54  return LCM_LC2013;
55  }
56 
58  void initDerivedParameters();
59 
60  bool debugVehicle() const;
61 
70  int wantsChange(
71  int laneOffset,
72  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
73  const std::pair<MSVehicle*, double>& leader,
74  const std::pair<MSVehicle*, double>& neighLead,
75  const std::pair<MSVehicle*, double>& neighFollow,
76  const MSLane& neighLane,
77  const std::vector<MSVehicle::LaneQ>& preb,
78  MSVehicle** lastBlocked,
79  MSVehicle** firstBlocked);
80 
81  void* inform(void* info, MSVehicle* sender);
82 
93  double patchSpeed(const double min, const double wanted, const double max,
94  const MSCFModel& cfModel);
96  double _patchSpeed(const double min, const double wanted, const double max,
97  const MSCFModel& cfModel);
98 
99  void changed();
100 
101  double getSafetyFactor() const;
102 
103  double getOppositeSafetyFactor() const;
104 
105  void prepareStep();
106 
108  std::string getParameter(const std::string& key) const;
109 
111  void setParameter(const std::string& key, const std::string& value);
112 
114  double computeSpeedLat(double latDist, double& maneuverDist) const;
115 
119 
120 protected:
121 
123  int _wantsChange(
124  int laneOffset,
125  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
126  const std::pair<MSVehicle*, double>& leader,
127  const std::pair<MSVehicle*, double>& neighLead,
128  const std::pair<MSVehicle*, double>& neighFollow,
129  const MSLane& neighLane,
130  const std::vector<MSVehicle::LaneQ>& preb,
131  MSVehicle** lastBlocked,
132  MSVehicle** firstBlocked);
133 
134  /* @brief decide whether we will overtake or follow a blocking leader
135  * and inform it accordingly
136  * If we decide to follow, myVSafes will be extended
137  * returns the planned speed if following or -1 if overtaking */
139  int blocked, int dir,
140  const std::pair<MSVehicle*, double>& neighLead,
141  double remainingSeconds);
142 
145  int blocked, int dir,
146  const std::pair<MSVehicle*, double>& neighFollow,
147  double remainingSeconds,
148  double plannedSpeed);
149 
150 
151  /* @brief compute the distance to cover until a safe gap to the vehicle v in front is reached
152  * assuming constant velocities
153  * @param[in] follower the vehicle which overtakes
154  * @param[in] leader the vehicle to be overtaken
155  * @param[in] gap initial distance between front of follower and back of leader
156  * @param[in] leaderSpeed an assumed speed for the leader (default uses the current speed)
157  * @param[in] followerSpeed an assumed speed for the follower (default uses the current speed)
158  * @return the distance that the relative positions would have to change.
159  */
160  static double overtakeDistance(const MSVehicle* follower, const MSVehicle* leader, const double gap, double followerSpeed = INVALID_SPEED, double leaderSpeed = INVALID_SPEED);
161 
163  int slowDownForBlocked(MSVehicle** blocked, int state);
164 
166  double anticipateFollowSpeed(const std::pair<MSVehicle*, double>& leaderDist, double dist, double vMax, bool acceleratingLeader);
167 
169  void saveBlockerLength(MSVehicle* blocker, int lcaCounter);
170 
172  void adaptSpeedToPedestrians(const MSLane* lane, double& v);
173 
175  inline void saveBlockerLength(double length) {
177  };
178 
179  inline bool amBlockingLeader() {
180  return (myOwnState & LCA_AMBLOCKINGLEADER) != 0;
181  }
182  inline bool amBlockingFollower() {
183  return (myOwnState & LCA_AMBLOCKINGFOLLOWER) != 0;
184  }
185  inline bool amBlockingFollowerNB() {
187  }
188  inline bool amBlockingFollowerPlusNB() {
190  }
191  inline bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist) {
192  return dist / (abs(laneOffset)) < lookForwardDist;
193  }
194  inline bool currentDistAllows(double dist, int laneOffset, double lookForwardDist) {
195  return dist / abs(laneOffset) > lookForwardDist;
196  }
197 
204  void addLCSpeedAdvice(const double vSafe);
205 
206 protected:
207 
209  typedef std::pair<double, int> Info;
210 
213  /* @brief a value for tracking the probability of following the/"Rechtsfahrgebot"
214  * A larger negative value indicates higher probability for moving to the
215  * right (as in mySpeedGainProbability) */
217 
219  double myLeftSpace;
220 
221  /*@brief the speed to use when computing the look-ahead distance for
222  * determining urgency of strategic lane changes */
224 
227  std::vector<double> myLCAccelerationAdvices;
228 
229  bool myDontBrake; // XXX: myDontBrake is initialized as false and seems not to be changed anywhere... What's its purpose???
230 
232 
234  double myCooperativeParam; // in [0,1]
238 
239  // @brief the factor by which the lookahead distance to the left differs from the lookahead to the right
241  // @brief the factor by which the speedGain-threshold for the leftdiffers from the threshold for the right
243 
244  // @brief willingness to undercut longitudinal safe gaps
245  double myAssertive;
246  // @brief lookahead for speedGain in seconds
248  // @brief bounus factor staying on the inside of multi-lane roundabout
250  // @brief factor for cooperative speed adjustment
252  // allow overtaking right even though it is prohibited
254 
255  // for feature testing
256  const double myExperimentalParam1;
257 
259 
261 
262  // @brief willingness to encroach on other vehicles laterally (pushing them around)
266 };
#define INVALID_SPEED
Definition: MSLCM_LC2013.h:34
@ LCA_AMBLOCKINGLEADER
@ LCA_AMBLOCKINGFOLLOWER_DONTBRAKE
@ LCA_AMBLOCKINGFOLLOWER
LaneChangeModel
@ LCM_LC2013
T MAX2(T a, T b)
Definition: StdDefs.h:79
A class responsible for exchanging messages between cars involved in lane-change interaction.
Interface for lane-change models.
int myOwnState
The current state of the vehicle.
The car-following model abstraction.
Definition: MSCFModel.h:55
A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013.
Definition: MSLCM_LC2013.h:45
void saveBlockerLength(double length)
reserve space at the end of the lane to avoid dead locks
Definition: MSLCM_LC2013.h:175
bool currentDistAllows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_LC2013.h:194
bool amBlockingLeader()
Definition: MSLCM_LC2013.h:179
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
bool amBlockingFollowerNB()
Definition: MSLCM_LC2013.h:185
double myLookAheadSpeed
Definition: MSLCM_LC2013.h:223
double computeSpeedLat(double latDist, double &maneuverDist) const
decides the next lateral speed (for continuous lane changing)
double _patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)
double myStrategicParam
Definition: MSLCM_LC2013.h:233
double myRoundaboutBonus
Definition: MSLCM_LC2013.h:249
double mySpeedGainLookahead
Definition: MSLCM_LC2013.h:247
const double myExperimentalParam1
Definition: MSLCM_LC2013.h:256
void initDerivedParameters()
init cached parameters derived directly from model parameters
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...
double myCooperativeParam
Definition: MSLCM_LC2013.h:234
std::vector< double > myLCAccelerationAdvices
vector of LC-related acceleration recommendations Filled in wantsChange() and applied in patchSpeed()
Definition: MSLCM_LC2013.h:227
MSLCM_LC2013(MSVehicle &v)
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
double myChangeProbThresholdRight
Definition: MSLCM_LC2013.h:263
double anticipateFollowSpeed(const std::pair< MSVehicle *, double > &leaderDist, double dist, double vMax, bool acceleratingLeader)
anticipate future follow speed for the given leader
double myCooperativeSpeed
Definition: MSLCM_LC2013.h:251
bool amBlockingFollower()
Definition: MSLCM_LC2013.h:182
double informLeader(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, double > &neighLead, double remainingSeconds)
double mySpeedGainParam
Definition: MSLCM_LC2013.h:235
double myLookaheadLeft
Definition: MSLCM_LC2013.h:240
double myLeadingBlockerLength
Definition: MSLCM_LC2013.h:218
LaneChangeModel getModelID() const
Returns the model's id.
Definition: MSLCM_LC2013.h:53
std::pair< double, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
Definition: MSLCM_LC2013.h:209
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
double getSafetyFactor() const
return factor for modifying the safety constraints of the car-following model
double myLeftSpace
Definition: MSLCM_LC2013.h:219
double myOppositeParam
Definition: MSLCM_LC2013.h:237
bool amBlockingFollowerPlusNB()
Definition: MSLCM_LC2013.h:188
double myKeepRightProbability
Definition: MSLCM_LC2013.h:216
double myKeepRightParam
Definition: MSLCM_LC2013.h:236
bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_LC2013.h:191
void adaptSpeedToPedestrians(const MSLane *lane, double &v)
react to pedestrians on the given lane
virtual ~MSLCM_LC2013()
void saveBlockerLength(MSVehicle *blocker, int lcaCounter)
save space for vehicles which need to counter-lane-change
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
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 mySpeedGainRight
Definition: MSLCM_LC2013.h:242
double myAssertive
Definition: MSLCM_LC2013.h:245
bool debugVehicle() const
whether the current vehicles shall be debugged
double myOvertakeRightParam
Definition: MSLCM_LC2013.h:253
double mySpeedGainProbability
a value for tracking the probability that a change to the offset with the same sign is beneficial
Definition: MSLCM_LC2013.h:212
double getOppositeSafetyFactor() const
return factor for modifying the safety constraints for opposite-diretction overtaking of the car-foll...
void * inform(void *info, MSVehicle *sender)
double myChangeProbThresholdLeft
Definition: MSLCM_LC2013.h:264
double getAssumedDecelForLaneChangeDuration() const
Returns a deceleration value which is used for the estimation of the duration of a lane change.
void addLCSpeedAdvice(const double vSafe)
Takes a vSafe (speed advice for speed in the next simulation step), converts it into an acceleration ...
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 ...
static double overtakeDistance(const MSVehicle *follower, const MSVehicle *leader, const double gap, double followerSpeed=INVALID_SPEED, double leaderSpeed=INVALID_SPEED)
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77