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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013
19 /****************************************************************************/
20 #ifndef MSLCM_LC2013_h
21 #define MSLCM_LC2013_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
30 #include <vector>
31 
32 // INVALID_SPEED should be used when the construction of upper bound for the speed
33 // leads to no restrictions, e.g. during LC-messaging to followers or leaders.
34 // Currently either std::numeric_limits<...>.max() or -1 is used for this purpose in many places.
35 // TODO: implement this everywhere and remove workarounds for ballistic update in cases of possible '-1'-returns. Refs. #2577
36 #define INVALID_SPEED 299792458 + 1 // nothing can go faster than the speed of light!
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
48 public:
49 
51 
52  virtual ~MSLCM_LC2013();
53 
56  return LCM_LC2013;
57  }
58 
60  void initDerivedParameters();
61 
62  bool debugVehicle() const;
63 
72  int wantsChange(
73  int laneOffset,
74  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
75  const std::pair<MSVehicle*, double>& leader,
76  const std::pair<MSVehicle*, double>& neighLead,
77  const std::pair<MSVehicle*, double>& neighFollow,
78  const MSLane& neighLane,
79  const std::vector<MSVehicle::LaneQ>& preb,
80  MSVehicle** lastBlocked,
81  MSVehicle** firstBlocked);
82 
83  void* inform(void* info, MSVehicle* sender);
84 
95  double patchSpeed(const double min, const double wanted, const double max,
96  const MSCFModel& cfModel);
98  double _patchSpeed(const double min, const double wanted, const double max,
99  const MSCFModel& cfModel);
100 
101  void changed();
102 
103  double getSafetyFactor() const;
104 
105  double getOppositeSafetyFactor() const;
106 
107  void prepareStep();
108 
110  std::string getParameter(const std::string& key) const;
111 
113  void setParameter(const std::string& key, const std::string& value);
114 
116  double computeSpeedLat(double latDist, double& maneuverDist);
117 
121 
122 protected:
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>& neighLead,
130  const std::pair<MSVehicle*, double>& neighFollow,
131  const MSLane& neighLane,
132  const std::vector<MSVehicle::LaneQ>& preb,
133  MSVehicle** lastBlocked,
134  MSVehicle** firstBlocked);
135 
136  /* @brief decide whether we will overtake or follow a blocking leader
137  * and inform it accordingly
138  * If we decide to follow, myVSafes will be extended
139  * returns the planned speed if following or -1 if overtaking */
141  int blocked, int dir,
142  const std::pair<MSVehicle*, double>& neighLead,
143  double remainingSeconds);
144 
147  int blocked, int dir,
148  const std::pair<MSVehicle*, double>& neighFollow,
149  double remainingSeconds,
150  double plannedSpeed);
151 
152 
153  /* @brief compute the distance to cover until a safe gap to the vehicle v in front is reached
154  * assuming constant velocities
155  * @param[in] follower the vehicle which overtakes
156  * @param[in] leader the vehicle to be overtaken
157  * @param[in] gap initial distance between front of follower and back of leader
158  * @param[in] leaderSpeed an assumed speed for the leader (default uses the current speed)
159  * @param[in] followerSpeed an assumed speed for the follower (default uses the current speed)
160  * @return the distance that the relative positions would have to change.
161  */
162  static double overtakeDistance(const MSVehicle* follower, const MSVehicle* leader, const double gap, double followerSpeed = INVALID_SPEED, double leaderSpeed = INVALID_SPEED);
163 
165  int slowDownForBlocked(MSVehicle** blocked, int state);
166 
167 
174  double getRoundaboutDistBonus(const MSVehicle::LaneQ& curr, const MSVehicle::LaneQ& neigh, const MSVehicle::LaneQ& best);
175 
177  void saveBlockerLength(MSVehicle* blocker, int lcaCounter);
178 
180  void adaptSpeedToPedestrians(const MSLane* lane, double& v);
181 
183  inline void saveBlockerLength(double length) {
185  };
186 
187  inline bool amBlockingLeader() {
188  return (myOwnState & LCA_AMBLOCKINGLEADER) != 0;
189  }
190  inline bool amBlockingFollower() {
191  return (myOwnState & LCA_AMBLOCKINGFOLLOWER) != 0;
192  }
193  inline bool amBlockingFollowerNB() {
195  }
196  inline bool amBlockingFollowerPlusNB() {
198  }
199  inline bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist) {
200  return dist / (abs(laneOffset)) < lookForwardDist;
201  }
202  inline bool currentDistAllows(double dist, int laneOffset, double lookForwardDist) {
203  return dist / abs(laneOffset) > lookForwardDist;
204  }
205 
212  void addLCSpeedAdvice(const double vSafe);
213 
214 protected:
215 
217  typedef std::pair<double, int> Info;
218 
221  /* @brief a value for tracking the probability of following the/"Rechtsfahrgebot"
222  * A larger negative value indicates higher probability for moving to the
223  * right (as in mySpeedGainProbability) */
225 
227  double myLeftSpace;
228 
229  /*@brief the speed to use when computing the look-ahead distance for
230  * determining urgency of strategic lane changes */
232 
235  std::vector<double> myLCAccelerationAdvices;
236 
237  bool myDontBrake; // XXX: myDontBrake is initialized as false and seems not to be changed anywhere... What's its purpose???
238 
240 
242  double myCooperativeParam; // in [0,1]
246 
247  // @brief the factor by which the lookahead distance to the left differs from the lookahead to the right
249  // @brief the factor by which the speedGain-threshold for the leftdiffers from the threshold for the right
251 
252  // @brief willingness to undercut longitudinal safe gaps
253  double myAssertive;
254  // allow overtaking right even though it is prohibited
256 
257  // for feature testing
258  const double myExperimentalParam1;
259 
261 
263 
264  // @brief willingness to encroach on other vehicles laterally (pushing them around)
268 };
269 
270 
271 #endif
272 
273 /****************************************************************************/
274 
MSLCM_LC2013::myStrategicParam
double myStrategicParam
Definition: MSLCM_LC2013.h:241
MSLCM_LC2013::getOppositeSafetyFactor
double getOppositeSafetyFactor() const
return factor for modifying the safety constraints for opposite-diretction overtaking of the car-foll...
Definition: MSLCM_LC2013.cpp:2092
MSLCM_LC2013::getAssumedDecelForLaneChangeDuration
double getAssumedDecelForLaneChangeDuration() const
Returns a deceleration value which is used for the estimation of the duration of a lane change.
Definition: MSLCM_LC2013.cpp:2082
MSLCM_LC2013::addLCSpeedAdvice
void addLCSpeedAdvice(const double vSafe)
Takes a vSafe (speed advice for speed in the next simulation step), converts it into an acceleration ...
Definition: MSLCM_LC2013.cpp:2064
MSLCM_LC2013::Info
std::pair< double, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
Definition: MSLCM_LC2013.h:217
MSLCM_LC2013::myLookAheadSpeed
double myLookAheadSpeed
Definition: MSLCM_LC2013.h:231
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSLCM_LC2013::myKeepRightProbability
double myKeepRightProbability
Definition: MSLCM_LC2013.h:224
MSLCM_LC2013::getSafetyFactor
double getSafetyFactor() const
return factor for modifying the safety constraints of the car-following model
Definition: MSLCM_LC2013.cpp:2087
MSLCM_LC2013::prepareStep
void prepareStep()
Definition: MSLCM_LC2013.cpp:1017
MSLCM_LC2013::amBlockingFollowerNB
bool amBlockingFollowerNB()
Definition: MSLCM_LC2013.h:193
MSLCM_LC2013::changed
void changed()
Definition: MSLCM_LC2013.cpp:1043
MSAbstractLaneChangeModel::MSLCMessager
A class responsible for exchanging messages between cars involved in lane-change interaction.
Definition: MSAbstractLaneChangeModel.h:51
LaneChangeModel
LaneChangeModel
Definition: SUMOXMLDefinitions.h:1303
LCA_AMBLOCKINGLEADER
@ LCA_AMBLOCKINGLEADER
Definition: SUMOXMLDefinitions.h:1286
MSLCM_LC2013::getModelID
LaneChangeModel getModelID() const
Returns the model's id.
Definition: MSLCM_LC2013.h:55
MSVehicle::LaneQ
A structure representing the best lanes for continuing the current route starting at 'lane'.
Definition: MSVehicle.h:810
MSLCM_LC2013::_wantsChange
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
Definition: MSLCM_LC2013.cpp:1060
MSLCM_LC2013::getRoundaboutDistBonus
double getRoundaboutDistBonus(const MSVehicle::LaneQ &curr, const MSVehicle::LaneQ &neigh, const MSVehicle::LaneQ &best)
Computes the artificial bonus distance for roundabout lanes this additional distance reduces the sens...
Definition: MSLCM_LC2013.cpp:1787
MSLCM_LC2013::amBlockingFollower
bool amBlockingFollower()
Definition: MSLCM_LC2013.h:190
MSLCM_LC2013::patchSpeed
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 ...
Definition: MSLCM_LC2013.cpp:188
MSLCM_LC2013::saveBlockerLength
void saveBlockerLength(MSVehicle *blocker, int lcaCounter)
save space for vehicles which need to counter-lane-change
Definition: MSLCM_LC2013.cpp:1995
MSLCM_LC2013::myChangeProbThresholdLeft
double myChangeProbThresholdLeft
Definition: MSLCM_LC2013.h:266
MSLCM_LC2013::mySpeedGainParam
double mySpeedGainParam
Definition: MSLCM_LC2013.h:243
MSLCM_LC2013::myAssertive
double myAssertive
Definition: MSLCM_LC2013.h:253
MSLCM_LC2013::wantsChange
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...
Definition: MSLCM_LC2013.cpp:149
MSLCM_LC2013::myKeepRightParam
double myKeepRightParam
Definition: MSLCM_LC2013.h:244
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
MSLCM_LC2013::currentDistAllows
bool currentDistAllows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_LC2013.h:202
MSLCM_LC2013::debugVehicle
bool debugVehicle() const
whether the current vehicles shall be debugged
Definition: MSLCM_LC2013.cpp:143
MSLCM_LC2013::computeSpeedLat
double computeSpeedLat(double latDist, double &maneuverDist)
decides the next lateral speed (for continuous lane changing)
Definition: MSLCM_LC2013.cpp:2071
MSLCM_LC2013::overtakeDistance
static double overtakeDistance(const MSVehicle *follower, const MSVehicle *leader, const double gap, double followerSpeed=INVALID_SPEED, double leaderSpeed=INVALID_SPEED)
Definition: MSLCM_LC2013.cpp:431
MSLCM_LC2013::mySpeedGainProbability
double mySpeedGainProbability
a value for tracking the probability that a change to the offset with the same sign is beneficial
Definition: MSLCM_LC2013.h:220
MSLCM_LC2013::informFollower
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
Definition: MSLCM_LC2013.cpp:616
MSLCM_LC2013::slowDownForBlocked
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
Definition: MSLCM_LC2013.cpp:1939
MSLCM_LC2013::initDerivedParameters
void initDerivedParameters()
init cached parameters derived directly from model parameters
Definition: MSLCM_LC2013.cpp:136
MSLCM_LC2013::currentDistDisallows
bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_LC2013.h:199
MSLCM_LC2013::_patchSpeed
double _patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)
Definition: MSLCM_LC2013.cpp:221
MSLCM_LC2013::myChangeProbThresholdRight
double myChangeProbThresholdRight
Definition: MSLCM_LC2013.h:265
LCA_AMBLOCKINGFOLLOWER_DONTBRAKE
@ LCA_AMBLOCKINGFOLLOWER_DONTBRAKE
Definition: SUMOXMLDefinitions.h:1291
MSLCM_LC2013::adaptSpeedToPedestrians
void adaptSpeedToPedestrians(const MSLane *lane, double &v)
react to pedestrians on the given lane
Definition: MSLCM_LC2013.cpp:2041
MSLCM_LC2013::myLCAccelerationAdvices
std::vector< double > myLCAccelerationAdvices
vector of LC-related acceleration recommendations Filled in wantsChange() and applied in patchSpeed()
Definition: MSLCM_LC2013.h:235
MSLCM_LC2013::myCooperativeParam
double myCooperativeParam
Definition: MSLCM_LC2013.h:242
MSLCM_LC2013::~MSLCM_LC2013
virtual ~MSLCM_LC2013()
Definition: MSLCM_LC2013.cpp:130
MSLCM_LC2013::myDontBrake
bool myDontBrake
Definition: MSLCM_LC2013.h:237
MSLCM_LC2013::mySpeedGainRight
double mySpeedGainRight
Definition: MSLCM_LC2013.h:250
MSLCM_LC2013::myOppositeParam
double myOppositeParam
Definition: MSLCM_LC2013.h:245
MSLCM_LC2013::myExperimentalParam1
const double myExperimentalParam1
Definition: MSLCM_LC2013.h:258
INVALID_SPEED
#define INVALID_SPEED
Definition: MSLCM_LC2013.h:36
MSAbstractLaneChangeModel::myOwnState
int myOwnState
The current state of the vehicle.
Definition: MSAbstractLaneChangeModel.h:592
MSLCM_LC2013::myLeftSpace
double myLeftSpace
Definition: MSLCM_LC2013.h:227
MSLCM_LC2013::myLookaheadLeft
double myLookaheadLeft
Definition: MSLCM_LC2013.h:248
MSCFModel
The car-following model abstraction.
Definition: MSCFModel.h:56
MSLCM_LC2013::getParameter
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
Definition: MSLCM_LC2013.cpp:2097
config.h
MSLCM_LC2013::myOvertakeRightParam
double myOvertakeRightParam
Definition: MSLCM_LC2013.h:255
MSAbstractLaneChangeModel
Interface for lane-change models.
Definition: MSAbstractLaneChangeModel.h:45
MSLCM_LC2013
A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013.
Definition: MSLCM_LC2013.h:47
MSLCM_LC2013::inform
void * inform(void *info, MSVehicle *sender)
Definition: MSLCM_LC2013.cpp:410
MSLCM_LC2013::saveBlockerLength
void saveBlockerLength(double length)
reserve space at the end of the lane to avoid dead locks
Definition: MSLCM_LC2013.h:183
MSLCM_LC2013::amBlockingFollowerPlusNB
bool amBlockingFollowerPlusNB()
Definition: MSLCM_LC2013.h:196
MSLCM_LC2013::setParameter
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this laneChangeModel. Throw exception for unsupported key
Definition: MSLCM_LC2013.cpp:2124
MSLCM_LC2013::amBlockingLeader
bool amBlockingLeader()
Definition: MSLCM_LC2013.h:187
LCA_AMBLOCKINGFOLLOWER
@ LCA_AMBLOCKINGFOLLOWER
Definition: SUMOXMLDefinitions.h:1287
LCM_LC2013
@ LCM_LC2013
Definition: SUMOXMLDefinitions.h:1305
MSAbstractLaneChangeModel.h
MSLCM_LC2013::informLeader
double informLeader(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, double > &neighLead, double remainingSeconds)
Definition: MSLCM_LC2013.cpp:444
MSLCM_LC2013::myLeadingBlockerLength
double myLeadingBlockerLength
Definition: MSLCM_LC2013.h:226
MSLCM_LC2013::MSLCM_LC2013
MSLCM_LC2013(MSVehicle &v)
Definition: MSLCM_LC2013.cpp:99
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79