SUMO - Simulation of Urban MObility
MSLCM_SL2015.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // A lane change model for heterogeneous traffic (based on sub-lanes)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2013-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
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 
75  int wantsChangeSublane(int laneOffset,
76  LaneChangeAction alternatives,
77  const MSLeaderDistanceInfo& leaders,
78  const MSLeaderDistanceInfo& followers,
79  const MSLeaderDistanceInfo& blockers,
80  const MSLeaderDistanceInfo& neighLeaders,
81  const MSLeaderDistanceInfo& neighFollowers,
82  const MSLeaderDistanceInfo& neighBlockers,
83  const MSLane& neighLane,
84  const std::vector<MSVehicle::LaneQ>& preb,
85  MSVehicle** lastBlocked,
86  MSVehicle** firstBlocked,
87  double& latDist, int& blocked);
88 
93  int wantsChange(
94  int laneOffset,
95  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
96  const std::pair<MSVehicle*, double>& leader,
97  const std::pair<MSVehicle*, double>& neighLead,
98  const std::pair<MSVehicle*, double>& neighFollow,
99  const MSLane& neighLane,
100  const std::vector<MSVehicle::LaneQ>& preb,
101  MSVehicle** lastBlocked,
102  MSVehicle** firstBlocked);
103 
104  void* inform(void* info, MSVehicle* sender);
105 
114  double patchSpeed(const double min, const double wanted, const double max,
115  const MSCFModel& cfModel);
117  double _patchSpeed(const double min, const double wanted, const double max,
118  const MSCFModel& cfModel);
119 
120  void changed();
121 
122  void prepareStep();
123 
125  bool debugVehicle() const;
126 
127  void setOwnState(const int state);
128 
130  std::string getParameter(const std::string& key) const;
131 
133  void setParameter(const std::string& key, const std::string& value);
134 
135 protected:
136 
139  int laneOffset,
140  LaneChangeAction alternatives,
141  const MSLeaderDistanceInfo& leaders,
142  const MSLeaderDistanceInfo& followers,
143  const MSLeaderDistanceInfo& blockers,
144  const MSLeaderDistanceInfo& neighLeaders,
145  const MSLeaderDistanceInfo& neighFollowers,
146  const MSLeaderDistanceInfo& neighBlockers,
147  const MSLane& neighLane,
148  const std::vector<MSVehicle::LaneQ>& preb,
149  MSVehicle** lastBlocked,
150  MSVehicle** firstBlocked,
151  double& latDist, int& blocked);
152 
153 
154  /* @brief decide whether we will overtake or follow blocking leaders
155  * and inform them accordingly (see informLeader)
156  * If we decide to follow, myVSafes will be extended
157  * returns the planned speed if following or -1 if overtaking */
158  double informLeaders(int blocked, int dir,
159  const std::vector<CLeaderDist>& blockers,
160  double remainingSeconds);
161 
163  void informFollowers(int blocked, int dir,
164  const std::vector<CLeaderDist>& blockers,
165  double remainingSeconds,
166  double plannedSpeed);
167 
168  /* @brief decide whether we will overtake or follow a blocking leader
169  * and inform it accordingly
170  * If we decide to follow, myVSafes will be extended
171  * returns the planned speed if following or -1 if overtaking */
172  double informLeader(int blocked, int dir,
173  const CLeaderDist& neighLead,
174  double remainingSeconds);
175 
177  void informFollower(int blocked, int dir,
178  const CLeaderDist& neighFollow,
179  double remainingSeconds,
180  double plannedSpeed);
181 
182 
184  int slowDownForBlocked(MSVehicle** blocked, int state);
185 
187  void saveBlockerLength(const MSVehicle* blocker, int lcaCounter);
188 
190  inline void saveBlockerLength(double length) {
192  };
193 
194  inline bool amBlockingLeader() {
195  return (myOwnState & LCA_AMBLOCKINGLEADER) != 0;
196  }
197  inline bool amBlockingFollower() {
198  return (myOwnState & LCA_AMBLOCKINGFOLLOWER) != 0;
199  }
200  inline bool amBlockingFollowerNB() {
202  }
203  inline bool amBlockingFollowerPlusNB() {
205  }
206  inline bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist) {
207  return dist / (abs(laneOffset)) < lookForwardDist;
208  }
209  inline bool currentDistAllows(double dist, int laneOffset, double lookForwardDist) {
210  return dist / abs(laneOffset) > lookForwardDist;
211  }
212 
214  typedef std::pair<double, int> Info;
215 
216 
218  void updateExpectedSublaneSpeeds(const MSLeaderInfo& ahead, int sublaneOffset, int laneIndex);
219 
222 
223 protected:
224 
226  void msg(const CLeaderDist& cld, double speed, int state);
227 
229  int computeSublaneShift(const MSEdge* prevEdge, const MSEdge* curEdge);
230 
232  static CLeaderDist getLongest(const MSLeaderDistanceInfo& ldi);
233 
235  static CLeaderDist getSlowest(const MSLeaderDistanceInfo& ldi);
236 
238  int checkBlocking(const MSLane& neighLane, double& latDist, int laneOffset,
239  const MSLeaderDistanceInfo& leaders,
240  const MSLeaderDistanceInfo& followers,
241  const MSLeaderDistanceInfo& blockers,
242  const MSLeaderDistanceInfo& neighLeaders,
243  const MSLeaderDistanceInfo& neighFollowers,
244  const MSLeaderDistanceInfo& neighBlockers,
245  std::vector<CLeaderDist>* collectLeadBlockers = 0,
246  std::vector<CLeaderDist>* collectFollowBlockers = 0,
247  bool keepLatGapManeuver = false,
248  double gapFactor = 0,
249  int* retBlockedFully = 0);
250 
252  int checkBlockingVehicles(const MSVehicle* ego, const MSLeaderDistanceInfo& vehicles,
253  double latDist, double foeOffset, bool leaders, LaneChangeAction blockType,
254  std::vector<CLeaderDist>* collectBlockers = 0) const;
255 
257  static bool overlap(double right, double left, double right2, double left2);
258 
260  static LaneChangeAction getLCA(int state, double latDist);
261 
263  int checkStrategicChange(int ret,
264  int laneOffset,
265  const std::vector<MSVehicle::LaneQ>& preb,
266  const MSLeaderDistanceInfo& leaders,
267  const MSLeaderDistanceInfo& neighLeaders,
268  int currIdx,
269  int bestLaneOffset,
270  bool changeToBest,
271  int lcaCounter,
272  double currentDist,
273  double neighDist,
274  double laDist,
275  int roundaboutEdgesAhead,
276  double latLaneDist,
277  double& latDist
278  );
279 
280 
282  int keepLatGap(int state,
283  const MSLeaderDistanceInfo& leaders,
284  const MSLeaderDistanceInfo& followers,
285  const MSLeaderDistanceInfo& blockers,
286  const MSLeaderDistanceInfo& neighLeaders,
287  const MSLeaderDistanceInfo& neighFollowers,
288  const MSLeaderDistanceInfo& neighBlockers,
289  const MSLane& neighLane,
290  int laneOffset,
291  double& latDist,
292  int& blocked);
293 
294 
296  void updateGaps(const MSLeaderDistanceInfo& others, double foeOffset, double oldCenter, double gapFactor,
297  double& surplusGapRight, double& surplusGapLeft, bool saveMinGap = false, double netOverlap = 0,
298  double latDist = 0,
299  std::vector<CLeaderDist>* collectBlockers = 0);
300 
302  double computeGapFactor(int state) const;
303 
305  double computeSpeedLat(double latDist);
306 
308  double getWidth() const;
309 
311  void updateCFRelated(const MSLeaderDistanceInfo& vehicles, double foeOffset);
312 
314  double getSublaneWidth() {
316  }
317 
319  void commitManoeuvre(int blocked, int blockedFully,
320  const MSLeaderDistanceInfo& leaders,
321  const MSLeaderDistanceInfo& neighLeaders,
322  const MSLane& neighLane);
323 
325  double commitFollowSpeed(double speed, double latDist, double secondsToLeaveLane, const MSLeaderDistanceInfo& leaders, double foeOffset) const;
326 
328  double computeSpeedGain(double latDistSublane, double defaultNextSpeed) const;
329 
330 protected:
335 
336  /* @brief a value for tracking the probability of following the/"Rechtsfahrgebot"
337  * A larger negative value indicates higher probability for moving to the
338  * right (as in mySpeedGainProbability) */
340 
342  double myLeftSpace;
343 
344  /*@brief the speed to use when computing the look-ahead distance for
345  * determining urgency of strategic lane changes */
347 
349  std::vector<double> myVSafes;
350 
352  std::vector<double> myExpectedSublaneSpeeds;
353 
356 
359 
362 
365 
368 
370  std::set<const MSVehicle*> myCFRelated;
372 
374 
380  // @brief willingness to encroach on other vehicles laterally (pushing them around)
381  double myPushy;
382  // @brief willingness to undercut longitudinal safe gaps
383  double myAssertive;
384  // @brief dynamic component of willingness for longitudinal gap reduction
385  double myImpatience;
386  // @brief time to reach maximum impatience in seconds
388  // @brief lateral acceleration
389  double myAccelLat;
391 
393 
394  // @brief threshold value for changing to the right
396  // @brief threshold value for changing to the left
398  // @brief threshold value for accepting speed loss to achieve desired sublane alignment
401 
402 };
403 
404 
405 #endif
406 
407 /****************************************************************************/
408 
void * inform(void *info, MSVehicle *sender)
void updateCFRelated(const MSLeaderDistanceInfo &vehicles, double foeOffset)
find leaders/followers that are already in a car-following relationship with ego
static double gLateralResolution
Definition: MSGlobals.h:92
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:342
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:136
double myChangeProbThresholdLeft
Definition: MSLCM_SL2015.h:397
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:500
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:334
std::set< const MSVehicle * > myCFRelated
set of vehicles that are in a car-following relationship with ego (leader of followers) ...
Definition: MSLCM_SL2015.h:370
#define min(a, b)
Definition: polyfonts.c:66
double mySpeedGainParam
Definition: MSLCM_SL2015.h:377
int checkBlocking(const MSLane &neighLane, double &latDist, 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 informLeaders(int blocked, int dir, const std::vector< CLeaderDist > &blockers, double remainingSeconds)
bool myCanChangeFully
whether the current lane changing meneuver can be finished in a single step
Definition: MSLCM_SL2015.h:361
double myKeepRightParam
Definition: MSLCM_SL2015.h:378
bool debugVehicle() const
whether the current vehicles shall be debugged
void saveBlockerLength(double length)
reserve space at the end of the lane to avoid dead locks
Definition: MSLCM_SL2015.h:190
int checkStrategicChange(int ret, int laneOffset, const std::vector< MSVehicle::LaneQ > &preb, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &neighLeaders, int currIdx, int bestLaneOffset, bool changeToBest, int lcaCounter, double currentDist, double neighDist, double laDist, int roundaboutEdgesAhead, double latLaneDist, double &latDist)
compute strategic lane change actions
The car-following model abstraction.
Definition: MSCFModel.h:60
double myStrategicParam
Definition: MSLCM_SL2015.h:375
double mySpeedLossProbThreshold
Definition: MSLCM_SL2015.h:399
void setOwnState(const int state)
static CLeaderDist getSlowest(const MSLeaderDistanceInfo &ldi)
get the slowest vehicle in the given info
void updateExpectedSublaneSpeeds(const MSLeaderInfo &ahead, int sublaneOffset, int laneIndex)
update expected speeds for each sublane of the current edge
double computeGapFactor(int state) const
compute the gap factor for the given state
std::vector< double > myExpectedSublaneSpeeds
expected travel speeds on all sublanes on the current edge(!)
Definition: MSLCM_SL2015.h:352
double myTimeToImpatience
Definition: MSLCM_SL2015.h:387
T MAX2(T a, T b)
Definition: StdDefs.h:74
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, int &blocked)
check whether lateral gap requirements are met override the current maneuver if necessary ...
void commitManoeuvre(int blocked, int blockedFully, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &neighLeaders, const MSLane &neighLane)
commit to lane change maneuvre potentially overriding safe speed
StateAndDist decideDirection(StateAndDist sd1, StateAndDist sd2) const
decide in which direction to move in case both directions are desirable
bool amBlockingFollower()
Definition: MSLCM_SL2015.h:197
MSLCM_SL2015(MSVehicle &v)
#define abs(a)
Definition: polyfonts.c:67
double myChangeProbThresholdRight
Definition: MSLCM_SL2015.h:395
double getWidth() const
return the widht of this vehicle (padded for numerical stability)
std::vector< double > myVSafes
speed adaptation requests by ego and surrounding vehicles
Definition: MSLCM_SL2015.h:349
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, int &blocked)
Called to examine whether the vehicle wants to change with the given laneOffset (using the sublane mo...
double getSublaneWidth()
return the current sublane width (and return a sensible value when running without sublanes) ...
Definition: MSLCM_SL2015.h:314
void saveBlockerLength(const MSVehicle *blocker, int lcaCounter)
save space for vehicles which need to counter-lane-change
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.
A road/street connecting two junctions.
Definition: MSEdge.h:81
double myLeadingBlockerLength
Definition: MSLCM_SL2015.h:341
void prepareStep()
#define max(a, b)
Definition: polyfonts.c:65
int checkBlockingVehicles(const MSVehicle *ego, const MSLeaderDistanceInfo &vehicles, double latDist, double foeOffset, bool leaders, LaneChangeAction blockType, std::vector< CLeaderDist > *collectBlockers=0) const
check whether any of the vehicles overlaps with ego
const MSEdge * myLastEdge
expected travel speeds on all sublanes on the current edge(!)
Definition: MSLCM_SL2015.h:355
double myPushy
Definition: MSLCM_SL2015.h:381
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:200
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 computeSpeedGain(double latDistSublane, double defaultNextSpeed) const
compute speedGain when moving by the given amount
double myCooperativeParam
Definition: MSLCM_SL2015.h:376
std::pair< double, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
Definition: MSLCM_SL2015.h:214
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
virtual ~MSLCM_SL2015()
std::pair< const MSVehicle *, double > CLeaderDist
Definition: MSLeaderInfo.h:42
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.
double myKeepRightProbability
Definition: MSLCM_SL2015.h:339
double myOrigLatDist
the complete lateral distance the vehicle wants to travel to finish its maneuver
Definition: MSLCM_SL2015.h:367
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
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key ...
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 ...
bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_SL2015.h:206
double myAccelLat
Definition: MSLCM_SL2015.h:389
double mySpeedGainProbabilityRight
a value for tracking the probability that a change to the right is beneficial
Definition: MSLCM_SL2015.h:332
double myLookAheadSpeed
Definition: MSLCM_SL2015.h:346
bool myCFRelatedReady
Definition: MSLCM_SL2015.h:371
bool currentDistAllows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_SL2015.h:209
bool amBlockingLeader()
Definition: MSLCM_SL2015.h:194
bool myDontBrake
flag to prevent speed adaptation by slowing down
Definition: MSLCM_SL2015.h:358
double computeSpeedLat(double latDist)
decides the next lateral speed depending on the remaining lane change distance to be covered ...
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:499
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, int &blocked)
helper function for doing the actual work
double myImpatience
Definition: MSLCM_SL2015.h:385
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:79
int myPreviousState
lane changing state from the previous simulation step
Definition: MSLCM_SL2015.h:364
int computeSublaneShift(const MSEdge *prevEdge, const MSEdge *curEdge)
compute shift so that prevSublane + shift = newSublane
Interface for lane-change models.
double mySublaneParam
Definition: MSLCM_SL2015.h:379
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:203
double myAssertive
Definition: MSLCM_SL2015.h:383