SUMO - Simulation of Urban MObility
MSLCM_SL2015.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2013-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 /****************************************************************************/
18 // A lane change model for heterogeneous traffic (based on sub-lanes)
19 /****************************************************************************/
20 #ifndef MSLCM_SL2015_h
21 #define MSLCM_SL2015_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
34 #include <vector>
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
45 public:
46 
47  enum MyLCAEnum {
48  LCA_MNone = 0,
51  LCA_MRIGHT = 1 << 18,
52  LCA_MLEFT = 1 << 19,
53  // !!! never set LCA_UNBLOCK = 1 << 20,
55  // !!! never used LCA_AMBLOCKINGSECONDFOLLOWER = 1 << 22,
56  LCA_CHANGE_TO_HELP = 1 << 23,
57  // !!! never read LCA_KEEP1 = 1 << 24,
58  // !!! never used LCA_KEEP2 = 1 << 25,
59  LCA_AMBACKBLOCKER = 1 << 26,
61  };
62 
63 
65 
66  virtual ~MSLCM_SL2015();
67 
69  void initDerivedParameters();
70 
79  int wantsChangeSublane(int laneOffset,
80  LaneChangeAction alternatives,
81  const MSLeaderDistanceInfo& leaders,
82  const MSLeaderDistanceInfo& followers,
83  const MSLeaderDistanceInfo& blockers,
84  const MSLeaderDistanceInfo& neighLeaders,
85  const MSLeaderDistanceInfo& neighFollowers,
86  const MSLeaderDistanceInfo& neighBlockers,
87  const MSLane& neighLane,
88  const std::vector<MSVehicle::LaneQ>& preb,
89  MSVehicle** lastBlocked,
90  MSVehicle** firstBlocked,
91  double& latDist, double& maneuverDist, int& blocked);
92 
100  int wantsChange(
101  int laneOffset,
102  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
103  const std::pair<MSVehicle*, double>& leader,
104  const std::pair<MSVehicle*, double>& neighLead,
105  const std::pair<MSVehicle*, double>& neighFollow,
106  const MSLane& neighLane,
107  const std::vector<MSVehicle::LaneQ>& preb,
108  MSVehicle** lastBlocked,
109  MSVehicle** firstBlocked);
110 
111  void* inform(void* info, MSVehicle* sender);
112 
123  double patchSpeed(const double min, const double wanted, const double max,
124  const MSCFModel& cfModel);
126  double _patchSpeed(const double min, const double wanted, const double max,
127  const MSCFModel& cfModel);
128 
129  void changed();
130 
131  void prepareStep();
132 
134  bool debugVehicle() const;
135 
136  void setOwnState(const int state);
137 
140  virtual void updateSafeLatDist(const double travelledLatDist);
141 
143  std::string getParameter(const std::string& key) const;
144 
146  void setParameter(const std::string& key, const std::string& value);
147 
150  double computeSpeedLat(double latDist, double& maneuverDist);
151 
152 protected:
153 
156  int laneOffset,
157  LaneChangeAction alternatives,
158  const MSLeaderDistanceInfo& leaders,
159  const MSLeaderDistanceInfo& followers,
160  const MSLeaderDistanceInfo& blockers,
161  const MSLeaderDistanceInfo& neighLeaders,
162  const MSLeaderDistanceInfo& neighFollowers,
163  const MSLeaderDistanceInfo& neighBlockers,
164  const MSLane& neighLane,
165  const std::vector<MSVehicle::LaneQ>& preb,
166  MSVehicle** lastBlocked,
167  MSVehicle** firstBlocked,
168  double& latDist, double& maneuverDist, int& blocked);
169 
170 
171  /* @brief decide whether we will overtake or follow blocking leaders
172  * and inform them accordingly (see informLeader)
173  * If we decide to follow, myVSafes will be extended
174  * returns the planned speed if following or -1 if overtaking */
175  double informLeaders(int blocked, int dir,
176  const std::vector<CLeaderDist>& blockers,
177  double remainingSeconds);
178 
180  void informFollowers(int blocked, int dir,
181  const std::vector<CLeaderDist>& blockers,
182  double remainingSeconds,
183  double plannedSpeed);
184 
185  /* @brief decide whether we will overtake or follow a blocking leader
186  * and inform it accordingly
187  * If we decide to follow, myVSafes will be extended
188  * returns the planned speed if following or -1 if overtaking */
189  double informLeader(int blocked, int dir,
190  const CLeaderDist& neighLead,
191  double remainingSeconds);
192 
194  void informFollower(int blocked, int dir,
195  const CLeaderDist& neighFollow,
196  double remainingSeconds,
197  double plannedSpeed);
198 
199 
201  int slowDownForBlocked(MSVehicle** blocked, int state);
202 
204  void saveBlockerLength(const MSVehicle* blocker, int lcaCounter);
205 
207  inline void saveBlockerLength(double length) {
209  };
210 
211  inline bool amBlockingLeader() {
212  return (myOwnState & LCA_AMBLOCKINGLEADER) != 0;
213  }
214  inline bool amBlockingFollower() {
215  return (myOwnState & LCA_AMBLOCKINGFOLLOWER) != 0;
216  }
217  inline bool amBlockingFollowerNB() {
219  }
220  inline bool amBlockingFollowerPlusNB() {
222  }
223  inline bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist) {
224  return dist / (abs(laneOffset)) < lookForwardDist;
225  }
226  inline bool currentDistAllows(double dist, int laneOffset, double lookForwardDist) {
227  return dist / abs(laneOffset) > lookForwardDist;
228  }
229 
230 
232  typedef std::pair<double, int> Info;
233 
240  void addLCSpeedAdvice(const double vSafe);
241 
243  void updateExpectedSublaneSpeeds(const MSLeaderDistanceInfo& ahead, int sublaneOffset, int laneIndex);
244 
247 
248 
249 protected:
250 
252  void msg(const CLeaderDist& cld, double speed, int state);
253 
255  int computeSublaneShift(const MSEdge* prevEdge, const MSEdge* curEdge);
256 
258  static CLeaderDist getLongest(const MSLeaderDistanceInfo& ldi);
259 
261  static CLeaderDist getSlowest(const MSLeaderDistanceInfo& ldi);
262 
264  int checkBlocking(const MSLane& neighLane, double& latDist, double& maneuverDist, int laneOffset,
265  const MSLeaderDistanceInfo& leaders,
266  const MSLeaderDistanceInfo& followers,
267  const MSLeaderDistanceInfo& blockers,
268  const MSLeaderDistanceInfo& neighLeaders,
269  const MSLeaderDistanceInfo& neighFollowers,
270  const MSLeaderDistanceInfo& neighBlockers,
271  std::vector<CLeaderDist>* collectLeadBlockers = 0,
272  std::vector<CLeaderDist>* collectFollowBlockers = 0,
273  bool keepLatGapManeuver = false,
274  double gapFactor = 0,
275  int* retBlockedFully = 0);
276 
278  int checkBlockingVehicles(const MSVehicle* ego, const MSLeaderDistanceInfo& vehicles,
279  double latDist, double foeOffset, bool leaders, LaneChangeAction blockType,
280  double& safeLatGapRight, double& safeLatGapLeft,
281  std::vector<CLeaderDist>* collectBlockers = 0) const;
282 
284  static bool overlap(double right, double left, double right2, double left2);
285 
287  static LaneChangeAction getLCA(int state, double latDist);
288 
291  int checkStrategicChange(int ret,
292  int laneOffset,
293  const std::vector<MSVehicle::LaneQ>& preb,
294  const MSLeaderDistanceInfo& leaders,
295  const MSLeaderDistanceInfo& neighLeaders,
296  int currIdx,
297  int bestLaneOffset,
298  bool changeToBest,
299  double currentDist,
300  double neighDist,
301  double laDist,
302  int roundaboutEdgesAhead,
303  double latLaneDist,
304  double& latDist
305  );
306 
307 
309  int keepLatGap(int state,
310  const MSLeaderDistanceInfo& leaders,
311  const MSLeaderDistanceInfo& followers,
312  const MSLeaderDistanceInfo& blockers,
313  const MSLeaderDistanceInfo& neighLeaders,
314  const MSLeaderDistanceInfo& neighFollowers,
315  const MSLeaderDistanceInfo& neighBlockers,
316  const MSLane& neighLane,
317  int laneOffset,
318  double& latDist,
319  double& maneuverDist,
320  int& blocked);
321 
322 
324  void updateGaps(const MSLeaderDistanceInfo& others, double foeOffset, double oldCenter, double gapFactor,
325  double& surplusGapRight, double& surplusGapLeft, bool saveMinGap = false, double netOverlap = 0,
326  double latDist = 0,
327  std::vector<CLeaderDist>* collectBlockers = 0);
328 
330  double computeGapFactor(int state) const;
331 
333  double getWidth() const;
334 
336  void updateCFRelated(const MSLeaderDistanceInfo& vehicles, double foeOffset, bool leaders);
337 
339  double getSublaneWidth() {
341  }
342 
344  void commitManoeuvre(int blocked, int blockedFully,
345  const MSLeaderDistanceInfo& leaders,
346  const MSLeaderDistanceInfo& neighLeaders,
347  const MSLane& neighLane,
348  double maneuverDist);
349 
351  double commitFollowSpeed(double speed, double latDist, double secondsToLeaveLane, const MSLeaderDistanceInfo& leaders, double foeOffset) const;
352 
354  double computeSpeedGain(double latDistSublane, double defaultNextSpeed) const;
355 
356 protected:
361 
362  /* @brief a value for tracking the probability of following the/"Rechtsfahrgebot"
363  * A larger negative value indicates higher probability for moving to the
364  * right (as in mySpeedGainProbability) */
366 
368  double myLeftSpace;
369 
370  /*@brief the speed to use when computing the look-ahead distance for
371  * determining urgency of strategic lane changes */
373 
376  std::vector<double> myLCAccelerationAdvices;
377 
379  std::vector<double> myExpectedSublaneSpeeds;
380 
383 
386 
389 
393 
395  std::set<const MSVehicle*> myCFRelated;
397 
399 
405  // @brief willingness to encroach on other vehicles laterally (pushing them around)
406  double myPushy;
407  // @brief willingness to undercut longitudinal safe gaps
408  double myAssertive;
409  // @brief dynamic component of willingness for longitudinal gap reduction
410  double myImpatience;
412  // @brief time to reach maximum impatience in seconds
414  // @brief lateral acceleration
415  double myAccelLat;
416  // @brief the factor by which the lookahead distance to the left differs from the lookahead to the right
418  // @brief the factor by which the speedGain-threshold for the leftdiffers from the threshold for the right
421 
423 
424  // @brief threshold value for changing to the right
426  // @brief threshold value for changing to the left
428  // @brief threshold value for accepting speed loss to achieve desired sublane alignment
431 
432 };
433 
434 
435 #endif
436 
437 /****************************************************************************/
438 
void * inform(void *info, MSVehicle *sender)
static double gLateralResolution
Definition: MSGlobals.h:91
A lane change model developed by J. Erdmann.
Definition: MSLCM_SL2015.h:44
void initDerivedParameters()
init cached parameters derived directly from model parameters
double myLeftSpace
Definition: MSLCM_SL2015.h:368
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:135
double myChangeProbThresholdLeft
Definition: MSLCM_SL2015.h:427
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
void msg(const CLeaderDist &cld, double speed, int state)
send a speed recommendation to the given vehicle
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 mySpeedGainProbabilityLeft
a value for tracking the probability that a change to the left is beneficial
Definition: MSLCM_SL2015.h:360
std::set< const MSVehicle * > myCFRelated
set of vehicles that are in a car-following relationship with ego (leader of followers) ...
Definition: MSLCM_SL2015.h:395
double mySpeedGainParam
Definition: MSLCM_SL2015.h:402
double informLeaders(int blocked, int dir, const std::vector< CLeaderDist > &blockers, double remainingSeconds)
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:564
bool myCanChangeFully
whether the current lane changing maneuver can be finished in a single step
Definition: MSLCM_SL2015.h:388
double myLookaheadLeft
Definition: MSLCM_SL2015.h:417
double myKeepRightParam
Definition: MSLCM_SL2015.h:403
double computeGapFactor(int state) const
compute the gap factor for the given state
void saveBlockerLength(double length)
reserve space at the end of the lane to avoid dead locks
Definition: MSLCM_SL2015.h:207
int checkBlockingVehicles(const MSVehicle *ego, const MSLeaderDistanceInfo &vehicles, double latDist, double foeOffset, bool leaders, LaneChangeAction blockType, double &safeLatGapRight, double &safeLatGapLeft, std::vector< CLeaderDist > *collectBlockers=0) const
check whether any of the vehicles overlaps with ego
The car-following model abstraction.
Definition: MSCFModel.h:59
double computeSpeedLat(double latDist, double &maneuverDist)
decides the next lateral speed depending on the remaining lane change distance to be covered and upda...
int checkBlocking(const MSLane &neighLane, double &latDist, double &maneuverDist, int laneOffset, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &followers, const MSLeaderDistanceInfo &blockers, const MSLeaderDistanceInfo &neighLeaders, const MSLeaderDistanceInfo &neighFollowers, const MSLeaderDistanceInfo &neighBlockers, std::vector< CLeaderDist > *collectLeadBlockers=0, std::vector< CLeaderDist > *collectFollowBlockers=0, bool keepLatGapManeuver=false, double gapFactor=0, int *retBlockedFully=0)
restrict latDist to permissible speed and determine blocking state depending on that distance ...
double myStrategicParam
Definition: MSLCM_SL2015.h:400
double mySpeedLossProbThreshold
Definition: MSLCM_SL2015.h:429
void setOwnState(const int state)
static CLeaderDist getSlowest(const MSLeaderDistanceInfo &ldi)
get the slowest vehicle in the given info
std::vector< double > myExpectedSublaneSpeeds
expected travel speeds on all sublanes on the current edge(!)
Definition: MSLCM_SL2015.h:379
double myTimeToImpatience
Definition: MSLCM_SL2015.h:413
T MAX2(T a, T b)
Definition: StdDefs.h:73
bool debugVehicle() const
whether the current vehicles shall be debugged
bool amBlockingFollower()
Definition: MSLCM_SL2015.h:214
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:513
MSLCM_SL2015(MSVehicle &v)
double myChangeProbThresholdRight
Definition: MSLCM_SL2015.h:425
int keepLatGap(int state, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &followers, const MSLeaderDistanceInfo &blockers, const MSLeaderDistanceInfo &neighLeaders, const MSLeaderDistanceInfo &neighFollowers, const MSLeaderDistanceInfo &neighBlockers, const MSLane &neighLane, int laneOffset, double &latDist, double &maneuverDist, int &blocked)
check whether lateral gap requirements are met override the current maneuver if necessary ...
double getSublaneWidth()
return the current sublane width (and return a sensible value when running without sublanes) ...
Definition: MSLCM_SL2015.h:339
double mySafeLatDistRight
the lateral distance the vehicle can safely move in the currently considered direction ...
Definition: MSLCM_SL2015.h:391
void saveBlockerLength(const MSVehicle *blocker, int lcaCounter)
save space for vehicles which need to counter-lane-change
double getWidth() const
return the widht of this vehicle (padded for numerical stability)
static bool overlap(double right, double left, double right2, double left2)
return whether the given intervals overlap
A class responsible for exchanging messages between cars involved in lane-change interaction.
StateAndDist decideDirection(StateAndDist sd1, StateAndDist sd2) const
decide in which direction to move in case both directions are desirable
A road/street connecting two junctions.
Definition: MSEdge.h:80
void commitManoeuvre(int blocked, int blockedFully, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &neighLeaders, const MSLane &neighLane, double maneuverDist)
commit to lane change maneuvre potentially overriding safe speed
double myLeadingBlockerLength
Definition: MSLCM_SL2015.h:367
void prepareStep()
double commitFollowSpeed(double speed, double latDist, double secondsToLeaveLane, const MSLeaderDistanceInfo &leaders, double foeOffset) const
compute speed when committing to an urgent change that is safe in regard to leading vehicles ...
void updateCFRelated(const MSLeaderDistanceInfo &vehicles, double foeOffset, bool leaders)
find leaders/followers that are already in a car-following relationship with ego
void addLCSpeedAdvice(const double vSafe)
Takes a vSafe (speed advice for speed in the next simulation step), converts it into an acceleration ...
const MSEdge * myLastEdge
expected travel speeds on all sublanes on the current edge(!)
Definition: MSLCM_SL2015.h:382
double myPushy
Definition: MSLCM_SL2015.h:406
double informLeader(int blocked, int dir, const CLeaderDist &neighLead, double remainingSeconds)
static LaneChangeAction getLCA(int state, double latDist)
compute lane change action from desired lateral distance
void informFollowers(int blocked, int dir, const std::vector< CLeaderDist > &blockers, double remainingSeconds, double plannedSpeed)
call informFollower for multiple followers
bool amBlockingFollowerNB()
Definition: MSLCM_SL2015.h:217
int wantsChangeSublane(int laneOffset, LaneChangeAction alternatives, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &followers, const MSLeaderDistanceInfo &blockers, const MSLeaderDistanceInfo &neighLeaders, const MSLeaderDistanceInfo &neighFollowers, const MSLeaderDistanceInfo &neighBlockers, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked, double &latDist, double &maneuverDist, int &blocked)
Called to examine whether the vehicle wants to change with the given laneOffset (using the sublane mo...
int _wantsChangeSublane(int laneOffset, LaneChangeAction alternatives, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &followers, const MSLeaderDistanceInfo &blockers, const MSLeaderDistanceInfo &neighLeaders, const MSLeaderDistanceInfo &neighFollowers, const MSLeaderDistanceInfo &neighBlockers, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked, double &latDist, double &maneuverDist, int &blocked)
helper function for doing the actual work
double myMinImpatience
Definition: MSLCM_SL2015.h:411
virtual void updateSafeLatDist(const double travelledLatDist)
Updates the value of safe lateral distances (mySafeLatDistLeft and mySafeLatDistRight) during maneuve...
double _patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)
int myOwnState
The current state of the vehicle.
static CLeaderDist getLongest(const MSLeaderDistanceInfo &ldi)
get the longest vehicle in the given info
double myCooperativeParam
Definition: MSLCM_SL2015.h:401
std::pair< double, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
Definition: MSLCM_SL2015.h:232
double computeSpeedGain(double latDistSublane, double defaultNextSpeed) const
compute speedGain when moving by the given amount
int checkStrategicChange(int ret, int laneOffset, const std::vector< MSVehicle::LaneQ > &preb, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &neighLeaders, int currIdx, int bestLaneOffset, bool changeToBest, double currentDist, double neighDist, double laDist, int roundaboutEdgesAhead, double latLaneDist, double &latDist)
compute strategic lane change actions TODO: Better documentation, refs #2
double mySpeedGainRight
Definition: MSLCM_SL2015.h:419
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
virtual ~MSLCM_SL2015()
std::pair< const MSVehicle *, double > CLeaderDist
Definition: MSLeaderInfo.h:41
LaneChangeAction
The state of a vehicle&#39;s lane-change behavior.
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 ...
double myKeepRightProbability
Definition: MSLCM_SL2015.h:365
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
void informFollower(int blocked, int dir, const CLeaderDist &neighFollow, double remainingSeconds, double plannedSpeed)
decide whether we will try cut in before the follower or allow to be overtaken
bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_SL2015.h:223
double myAccelLat
Definition: MSLCM_SL2015.h:415
std::vector< double > myLCAccelerationAdvices
vector of LC-related acceleration recommendations Filled in wantsChange() and applied in patchSpeed()...
Definition: MSLCM_SL2015.h:376
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key ...
double mySpeedGainProbabilityRight
a value for tracking the probability that a change to the right is beneficial
Definition: MSLCM_SL2015.h:358
double myLookAheadSpeed
Definition: MSLCM_SL2015.h:372
bool myCFRelatedReady
Definition: MSLCM_SL2015.h:396
bool currentDistAllows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_SL2015.h:226
bool amBlockingLeader()
Definition: MSLCM_SL2015.h:211
bool myDontBrake
flag to prevent speed adaptation by slowing down
Definition: MSLCM_SL2015.h:385
double myImpatience
Definition: MSLCM_SL2015.h:410
double mySafeLatDistLeft
Definition: MSLCM_SL2015.h:392
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 is a wrapper a...
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
int computeSublaneShift(const MSEdge *prevEdge, const MSEdge *curEdge)
compute shift so that prevSublane + shift = newSublane
Interface for lane-change models.
void updateExpectedSublaneSpeeds(const MSLeaderDistanceInfo &ahead, int sublaneOffset, int laneIndex)
update expected speeds for each sublane of the current edge
double mySublaneParam
Definition: MSLCM_SL2015.h:404
void updateGaps(const MSLeaderDistanceInfo &others, double foeOffset, double oldCenter, double gapFactor, double &surplusGapRight, double &surplusGapLeft, bool saveMinGap=false, double netOverlap=0, double latDist=0, std::vector< CLeaderDist > *collectBlockers=0)
check remaining lateral gaps for the given foe vehicles and optionally update minimum lateral gaps ...
bool amBlockingFollowerPlusNB()
Definition: MSLCM_SL2015.h:220
double myAssertive
Definition: MSLCM_SL2015.h:408