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-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 /****************************************************************************/
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 
53  LaneChangeModel getModelID() const override {
55  }
56 
58  void initDerivedParameters();
59 
60  bool debugVehicle() const override;
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>& follower,
75  const std::pair<MSVehicle*, double>& neighLead,
76  const std::pair<MSVehicle*, double>& neighFollow,
77  const MSLane& neighLane,
78  const std::vector<MSVehicle::LaneQ>& preb,
79  MSVehicle** lastBlocked,
80  MSVehicle** firstBlocked) override;
81 
82  void* inform(void* info, MSVehicle* sender) override;
83 
94  double patchSpeed(const double min, const double wanted, const double max,
95  const MSCFModel& cfModel) override;
96 
97  void changed() override;
98 
99  double getSafetyFactor() const override;
100 
101  double getOppositeSafetyFactor() const override;
102 
103  void prepareStep() override;
104 
106  std::string getParameter(const std::string& key) const override;
107 
109  void setParameter(const std::string& key, const std::string& value) override;
110 
112  double computeSpeedLat(double latDist, double& maneuverDist, bool urgent) const override;
113 
116  double getAssumedDecelForLaneChangeDuration() const override;
117 
118 protected:
119 
121  double _patchSpeed(const double min, const double wanted, const double max,
122  const MSCFModel& cfModel);
123 
125  int _wantsChange(
126  int laneOffset,
127  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
128  const std::pair<MSVehicle*, double>& leader,
129  const std::pair<MSVehicle*, double>& follower,
130  const std::pair<MSVehicle*, double>& neighLead,
131  const std::pair<MSVehicle*, double>& neighFollow,
132  const MSLane& neighLane,
133  const std::vector<MSVehicle::LaneQ>& preb,
134  MSVehicle** lastBlocked,
135  MSVehicle** firstBlocked);
136 
137  /* @brief decide whether we will overtake or follow a blocking leader
138  * and inform it accordingly
139  * If we decide to follow, myVSafes will be extended
140  * returns the planned speed if following or -1 if overtaking */
142  int blocked, int dir,
143  const std::pair<MSVehicle*, double>& neighLead,
144  double remainingSeconds);
145 
148  int blocked, int dir,
149  const std::pair<MSVehicle*, double>& neighFollow,
150  double remainingSeconds,
151  double plannedSpeed);
152 
153 
154  /* @brief compute the distance to cover until a safe gap to the vehicle v in front is reached
155  * assuming constant velocities
156  * @param[in] follower the vehicle which overtakes
157  * @param[in] leader the vehicle to be overtaken
158  * @param[in] gap initial distance between front of follower and back of leader
159  * @param[in] leaderSpeed an assumed speed for the leader (default uses the current speed)
160  * @param[in] followerSpeed an assumed speed for the follower (default uses the current speed)
161  * @return the distance that the relative positions would have to change.
162  */
163  static double overtakeDistance(const MSVehicle* follower, const MSVehicle* leader, const double gap, double followerSpeed = INVALID_SPEED, double leaderSpeed = INVALID_SPEED);
164 
166  int slowDownForBlocked(MSVehicle** blocked, int state);
167 
169  double anticipateFollowSpeed(const std::pair<MSVehicle*, double>& leaderDist, double dist, double vMax, bool acceleratingLeader);
170 
172  void saveBlockerLength(MSVehicle* blocker, int lcaCounter);
173 
175  void adaptSpeedToPedestrians(const MSLane* lane, double& v);
176 
178  inline void saveBlockerLength(double length) override {
180  };
181 
182  inline bool amBlockingLeader() {
183  return (myOwnState & LCA_AMBLOCKINGLEADER) != 0;
184  }
185  inline bool amBlockingFollower() {
186  return (myOwnState & LCA_AMBLOCKINGFOLLOWER) != 0;
187  }
188  inline bool amBlockingFollowerNB() {
190  }
191  inline bool amBlockingFollowerPlusNB() {
193  }
194  inline bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist) {
195  return dist / (abs(laneOffset)) < lookForwardDist;
196  }
197  inline bool currentDistAllows(double dist, int laneOffset, double lookForwardDist) {
198  return dist / abs(laneOffset) > lookForwardDist;
199  }
200 
207  void addLCSpeedAdvice(const double vSafe);
208 
209 protected:
210 
212  typedef std::pair<double, int> Info;
213 
216  /* @brief a value for tracking the probability of following the/"Rechtsfahrgebot"
217  * A larger negative value indicates higher probability for moving to the
218  * right (as in mySpeedGainProbability) */
220 
222  double myLeftSpace;
223 
224  /*@brief the speed to use when computing the look-ahead distance for
225  * determining urgency of strategic lane changes */
227 
230  std::vector<double> myLCAccelerationAdvices;
231 
232  bool myDontBrake; // XXX: myDontBrake is initialized as false and seems not to be changed anywhere... What's its purpose???
233 
235 
237  double myCooperativeParam; // in [0,1]
241 
242  // @brief the factor by which the lookahead distance to the left differs from the lookahead to the right
244  // @brief the factor by which the speedGain-threshold for the leftdiffers from the threshold for the right
246 
247  // @brief willingness to undercut longitudinal safe gaps
248  double myAssertive;
249  // @brief lookahead for speedGain in seconds
251  // @brief bounus factor staying on the inside of multi-lane roundabout
253  // @brief factor for cooperative speed adjustment
255  // allow overtaking right even though it is prohibited
257 
258  // time for unrestricted driving on the right to accept keepRight change
260 
261  // for feature testing
262  const double myExperimentalParam1;
263 
265 
267 
268  // @brief willingness to encroach on other vehicles laterally (pushing them around)
272 };
#define INVALID_SPEED
Definition: MSLCM_LC2013.h:34
@ LCA_AMBLOCKINGLEADER
@ LCA_AMBLOCKINGFOLLOWER_DONTBRAKE
@ LCA_AMBLOCKINGFOLLOWER
LaneChangeModel
T MAX2(T a, T b)
Definition: StdDefs.h:80
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
bool currentDistAllows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_LC2013.h:197
int wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, double > &leader, const std::pair< MSVehicle *, double > &follower, 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) override
Called to examine whether the vehicle wants to change using the given laneOffset. This method gets th...
bool amBlockingLeader()
Definition: MSLCM_LC2013.h:182
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 computeSpeedLat(double latDist, double &maneuverDist, bool urgent) const override
decides the next lateral speed (for continuous lane changing)
bool amBlockingFollowerNB()
Definition: MSLCM_LC2013.h:188
double myLookAheadSpeed
Definition: MSLCM_LC2013.h:226
double _patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)
bool debugVehicle() const override
whether the current vehicles shall be debugged
double myStrategicParam
Definition: MSLCM_LC2013.h:236
double myRoundaboutBonus
Definition: MSLCM_LC2013.h:252
double getAssumedDecelForLaneChangeDuration() const override
Returns a deceleration value which is used for the estimation of the duration of a lane change.
double mySpeedGainLookahead
Definition: MSLCM_LC2013.h:250
const double myExperimentalParam1
Definition: MSLCM_LC2013.h:262
double patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel) override
Called to adapt the speed in order to allow a lane change. It uses information on LC-related desired ...
void initDerivedParameters()
init cached parameters derived directly from model parameters
LaneChangeModel getModelID() const override
Returns the model's id.
Definition: MSLCM_LC2013.h:53
double myCooperativeParam
Definition: MSLCM_LC2013.h:237
std::vector< double > myLCAccelerationAdvices
vector of LC-related acceleration recommendations Filled in wantsChange() and applied in patchSpeed()
Definition: MSLCM_LC2013.h:230
MSLCM_LC2013(MSVehicle &v)
double myChangeProbThresholdRight
Definition: MSLCM_LC2013.h:269
double anticipateFollowSpeed(const std::pair< MSVehicle *, double > &leaderDist, double dist, double vMax, bool acceleratingLeader)
anticipate future follow speed for the given leader
std::string getParameter(const std::string &key) const override
try to retrieve the given parameter from this device. Throw exception for unsupported key
void setParameter(const std::string &key, const std::string &value) override
try to set the given parameter for this laneChangeModel. Throw exception for unsupported key
double myCooperativeSpeed
Definition: MSLCM_LC2013.h:254
bool amBlockingFollower()
Definition: MSLCM_LC2013.h:185
double informLeader(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, double > &neighLead, double remainingSeconds)
double mySpeedGainParam
Definition: MSLCM_LC2013.h:238
double myLookaheadLeft
Definition: MSLCM_LC2013.h:243
void saveBlockerLength(double length) override
reserve space at the end of the lane to avoid dead locks
Definition: MSLCM_LC2013.h:178
double myLeadingBlockerLength
Definition: MSLCM_LC2013.h:221
std::pair< double, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
Definition: MSLCM_LC2013.h:212
void prepareStep() override
double getSafetyFactor() const override
return factor for modifying the safety constraints of the car-following model
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
double myLeftSpace
Definition: MSLCM_LC2013.h:222
double myOppositeParam
Definition: MSLCM_LC2013.h:240
bool amBlockingFollowerPlusNB()
Definition: MSLCM_LC2013.h:191
double myKeepRightProbability
Definition: MSLCM_LC2013.h:219
double myKeepRightParam
Definition: MSLCM_LC2013.h:239
bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_LC2013.h:194
void adaptSpeedToPedestrians(const MSLane *lane, double &v)
react to pedestrians on the given lane
virtual ~MSLCM_LC2013()
double getOppositeSafetyFactor() const override
return factor for modifying the safety constraints for opposite-diretction overtaking of the car-foll...
void saveBlockerLength(MSVehicle *blocker, int lcaCounter)
save space for vehicles which need to counter-lane-change
double mySpeedGainRight
Definition: MSLCM_LC2013.h:245
double myKeepRightAcceptanceTime
Definition: MSLCM_LC2013.h:259
double myAssertive
Definition: MSLCM_LC2013.h:248
double myOvertakeRightParam
Definition: MSLCM_LC2013.h:256
void changed() override
double mySpeedGainProbability
a value for tracking the probability that a change to the offset with the same sign is beneficial
Definition: MSLCM_LC2013.h:215
double myChangeProbThresholdLeft
Definition: MSLCM_LC2013.h:270
void * inform(void *info, MSVehicle *sender) override
void addLCSpeedAdvice(const double vSafe)
Takes a vSafe (speed advice for speed in the next simulation step), converts it into an acceleration ...
int _wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, double > &leader, const std::pair< MSVehicle *, double > &follower, 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
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:75