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-2016 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 
72  int wantsChangeSublane(int laneOffset,
73  const MSLeaderDistanceInfo& leaders,
74  const MSLeaderDistanceInfo& followers,
75  const MSLeaderDistanceInfo& blockers,
76  const MSLeaderDistanceInfo& neighLeaders,
77  const MSLeaderDistanceInfo& neighFollowers,
78  const MSLeaderDistanceInfo& neighBlockers,
79  const MSLane& neighLane,
80  const std::vector<MSVehicle::LaneQ>& preb,
81  MSVehicle** lastBlocked,
82  MSVehicle** firstBlocked,
83  SUMOReal& latDist, int& blocked);
84 
85  void* inform(void* info, MSVehicle* sender);
86 
95  SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
96  const MSCFModel& cfModel);
98  SUMOReal _patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
99  const MSCFModel& cfModel);
100 
101  void changed();
102 
103  void prepareStep();
104 
106  bool debugVehicle() const;
107 
108  void setOwnState(int state) {
109  myOwnState = state;
110  myPreviousState = state;
111  }
112 
113 protected:
114 
117  int laneOffset,
118  const MSLeaderDistanceInfo& leaders,
119  const MSLeaderDistanceInfo& followers,
120  const MSLeaderDistanceInfo& blockers,
121  const MSLeaderDistanceInfo& neighLeaders,
122  const MSLeaderDistanceInfo& neighFollowers,
123  const MSLeaderDistanceInfo& neighBlockers,
124  const MSLane& neighLane,
125  const std::vector<MSVehicle::LaneQ>& preb,
126  MSVehicle** lastBlocked,
127  MSVehicle** firstBlocked,
128  SUMOReal& latDist, int& blocked);
129 
130 
131  /* @brief decide whether we will overtake or follow blocking leaders
132  * and inform them accordingly (see informLeader)
133  * If we decide to follow, myVSafes will be extended
134  * returns the planned speed if following or -1 if overtaking */
135  SUMOReal informLeaders(int blocked, int dir,
136  const std::vector<CLeaderDist>& blockers,
137  SUMOReal remainingSeconds);
138 
140  void informFollowers(int blocked, int dir,
141  const std::vector<CLeaderDist>& blockers,
142  SUMOReal remainingSeconds,
143  SUMOReal plannedSpeed);
144 
145  /* @brief decide whether we will overtake or follow a blocking leader
146  * and inform it accordingly
147  * If we decide to follow, myVSafes will be extended
148  * returns the planned speed if following or -1 if overtaking */
149  SUMOReal informLeader(int blocked, int dir,
150  const CLeaderDist& neighLead,
151  SUMOReal remainingSeconds);
152 
154  void informFollower(int blocked, int dir,
155  const CLeaderDist& neighFollow,
156  SUMOReal remainingSeconds,
157  SUMOReal plannedSpeed);
158 
159 
161  int slowDownForBlocked(MSVehicle** blocked, int state);
162 
164  void saveBlockerLength(const MSVehicle* blocker, int lcaCounter);
165 
167  inline void saveBlockerLength(SUMOReal length) {
169  };
170 
171  inline bool amBlockingLeader() {
172  return (myOwnState & LCA_AMBLOCKINGLEADER) != 0;
173  }
174  inline bool amBlockingFollower() {
175  return (myOwnState & LCA_AMBLOCKINGFOLLOWER) != 0;
176  }
177  inline bool amBlockingFollowerNB() {
179  }
180  inline bool amBlockingFollowerPlusNB() {
182  }
183  inline bool currentDistDisallows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist) {
184  return dist / (abs(laneOffset)) < lookForwardDist;
185  }
186  inline bool currentDistAllows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist) {
187  return dist / abs(laneOffset) > lookForwardDist;
188  }
189 
191  typedef std::pair<SUMOReal, int> Info;
192 
193 
195  void updateExpectedSublaneSpeeds(const MSLeaderInfo& ahead, int sublaneOffset, int laneIndex);
196 
199 
200 protected:
201 
203  void msg(const CLeaderDist& cld, SUMOReal speed, int state);
204 
206  int computeSublaneShift(const MSEdge* prevEdge, const MSEdge* curEdge);
207 
209  static CLeaderDist getLongest(const MSLeaderDistanceInfo& ldi);
210 
212  static CLeaderDist getSlowest(const MSLeaderDistanceInfo& ldi);
213 
215  int checkBlocking(const MSLane& neighLane, SUMOReal& latDist, int laneOffset,
216  const MSLeaderDistanceInfo& leaders,
217  const MSLeaderDistanceInfo& followers,
218  const MSLeaderDistanceInfo& blockers,
219  const MSLeaderDistanceInfo& neighLeaders,
220  const MSLeaderDistanceInfo& neighFollowers,
221  const MSLeaderDistanceInfo& neighBlockers,
222  std::vector<CLeaderDist>* collectLeadBlockers = 0,
223  std::vector<CLeaderDist>* collectFollowBlockers = 0,
224  bool saveOriginalLatDist = true);
225 
227  static int checkBlockingVehicles(const MSVehicle* ego, const MSLeaderDistanceInfo& vehicles,
228  SUMOReal latDist, SUMOReal foeOffset, bool leaders, LaneChangeAction blockType,
229  std::vector<CLeaderDist>* collectBlockers = 0);
230 
232  static bool overlap(SUMOReal right, SUMOReal left, SUMOReal right2, SUMOReal left2);
233 
235  static LaneChangeAction getLCA(int state, SUMOReal latDist);
236 
238  int checkStrategicChange(int ret,
239  int laneOffset,
240  const std::vector<MSVehicle::LaneQ>& preb,
241  const MSLeaderDistanceInfo& leaders,
242  const MSLeaderDistanceInfo& neighLeaders,
243  int currIdx,
244  int bestLaneOffset,
245  bool changeToBest,
246  int lcaCounter,
247  SUMOReal currentDist,
248  SUMOReal neighDist,
249  SUMOReal laDist,
250  int roundaboutEdgesAhead
251  );
252 
254  int keepLatGap(int state,
255  const MSLeaderDistanceInfo& leaders,
256  const MSLeaderDistanceInfo& followers,
257  const MSLeaderDistanceInfo& blockers,
258  const MSLeaderDistanceInfo& neighLeaders,
259  const MSLeaderDistanceInfo& neighFollowers,
260  const MSLeaderDistanceInfo& neighBlockers,
261  const MSLane& neighLane,
262  int laneOffset,
263  SUMOReal& latDist,
264  int& blocked);
265 
266 
268  void updateGaps(const MSLeaderDistanceInfo& others, SUMOReal foeOffset, SUMOReal newCenter, SUMOReal gapFactor,
269  SUMOReal& surplusGapRight, SUMOReal& surplusGapLeft) const;
270 
271 protected:
276 
277  /* @brief a value for tracking the probability of following the/"Rechtsfahrgebot"
278  * A larger negative value indicates higher probability for moving to the
279  * right (as in mySpeedGainProbability) */
281 
284 
285  /*@brief the speed to use when computing the look-ahead distance for
286  * determining urgency of strategic lane changes */
288 
290  std::vector<SUMOReal> myVSafes;
291 
293  std::vector<SUMOReal> myExpectedSublaneSpeeds;
294 
297 
300 
303 
306 
309 
311 
317  // @brief willingness to encroach on other vehicles laterally (pushing them around)
320 
322 
323  // @brief willingness to encroach on other vehicles laterally (pushing them around)
328 
329 };
330 
331 
332 #endif
333 
334 /****************************************************************************/
335 
void * inform(void *info, MSVehicle *sender)
int checkBlocking(const MSLane &neighLane, SUMOReal &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 saveOriginalLatDist=true)
restrict latDist to permissible speed and determine blocking state depending on that distance ...
void informFollower(int blocked, int dir, const CLeaderDist &neighFollow, SUMOReal remainingSeconds, SUMOReal plannedSpeed)
decide whether we will try cut in before the follower or allow to be overtaken
void informFollowers(int blocked, int dir, const std::vector< CLeaderDist > &blockers, SUMOReal remainingSeconds, SUMOReal plannedSpeed)
call informFollower for multiple followers
A lane change model developed by J. Erdmann.
Definition: MSLCM_SL2015.h:44
SUMOReal myKeepRightProbability
Definition: MSLCM_SL2015.h:280
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, SUMOReal &latDist, int &blocked)
check whether lateral gap requirements are met override the current maneuver if necessary ...
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:127
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:81
SUMOReal informLeader(int blocked, int dir, const CLeaderDist &neighLead, SUMOReal remainingSeconds)
SUMOReal myOrigLatDist
the complete lateral distance the vehicle wants to travel to finish its maneuver
Definition: MSLCM_SL2015.h:308
std::vector< SUMOReal > myVSafes
speed adaptation requests by ego and surrounding vehicles
Definition: MSLCM_SL2015.h:290
#define min(a, b)
Definition: polyfonts.c:66
void msg(const CLeaderDist &cld, SUMOReal speed, int state)
send a speed recommendation to the given vehicle
bool myCanChangeFully
whether the current lane changing meneuver can be finished in a single step
Definition: MSLCM_SL2015.h:302
bool debugVehicle() const
whether the current vehicles shall be debugged
The car-following model abstraction.
Definition: MSCFModel.h:59
bool currentDistAllows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist)
Definition: MSLCM_SL2015.h:186
static CLeaderDist getSlowest(const MSLeaderDistanceInfo &ldi)
get the slowest vehicle in the given info
SUMOReal myLeftSpace
Definition: MSLCM_SL2015.h:283
std::pair< const MSVehicle *, SUMOReal > CLeaderDist
Definition: MSLeaderInfo.h:42
void updateExpectedSublaneSpeeds(const MSLeaderInfo &ahead, int sublaneOffset, int laneIndex)
update expected speeds for each sublane of the current edge
T MAX2(T a, T b)
Definition: StdDefs.h:75
StateAndDist decideDirection(StateAndDist sd1, StateAndDist sd2) const
decide in which direction to move in case both directions are desirable
void updateGaps(const MSLeaderDistanceInfo &others, SUMOReal foeOffset, SUMOReal newCenter, SUMOReal gapFactor, SUMOReal &surplusGapRight, SUMOReal &surplusGapLeft) const
check remaining lateral gaps for the given foe vehicles
bool amBlockingFollower()
Definition: MSLCM_SL2015.h:174
MSLCM_SL2015(MSVehicle &v)
#define abs(a)
Definition: polyfonts.c:67
static int checkBlockingVehicles(const MSVehicle *ego, const MSLeaderDistanceInfo &vehicles, SUMOReal latDist, SUMOReal foeOffset, bool leaders, LaneChangeAction blockType, std::vector< CLeaderDist > *collectBlockers=0)
check whether any of the vehicles overlaps with ego
void saveBlockerLength(const MSVehicle *blocker, int lcaCounter)
save space for vehicles which need to counter-lane-change
A road/street connecting two junctions.
Definition: MSEdge.h:80
SUMOReal myLeadingBlockerLength
Definition: MSLCM_SL2015.h:282
void prepareStep()
#define max(a, b)
Definition: polyfonts.c:65
static bool overlap(SUMOReal right, SUMOReal left, SUMOReal right2, SUMOReal left2)
return whether the given intervals overlap
SUMOReal informLeaders(int blocked, int dir, const std::vector< CLeaderDist > &blockers, SUMOReal remainingSeconds)
std::vector< SUMOReal > myExpectedSublaneSpeeds
expected travel speeds on all sublanes on the current edge(!)
Definition: MSLCM_SL2015.h:293
const MSEdge * myLastEdge
expected travel speeds on all sublanes on the current edge(!)
Definition: MSLCM_SL2015.h:296
int wantsChangeSublane(int laneOffset, 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, SUMOReal &latDist, int &blocked)
Called to examine whether the vehicle wants to change using the given laneOffset. This method gets th...
const SUMOReal myChangeProbThresholdLeft
Definition: MSLCM_SL2015.h:325
bool amBlockingFollowerNB()
Definition: MSLCM_SL2015.h:177
SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel &cfModel)
Called to adapt the speed in order to allow a lane change.
std::pair< SUMOReal, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
Definition: MSLCM_SL2015.h:191
SUMOReal myLookAheadSpeed
Definition: MSLCM_SL2015.h:287
int _wantsChangeSublane(int laneOffset, 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, SUMOReal &latDist, int &blocked)
helper function for doing the actual work
SUMOReal _patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal 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
virtual ~MSLCM_SL2015()
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, SUMOReal currentDist, SUMOReal neighDist, SUMOReal laDist, int roundaboutEdgesAhead)
compute strategic lane change actions
LaneChangeAction
The state of a vehicle&#39;s lane-change behavior.
const SUMOReal myCooperativeParam
Definition: MSLCM_SL2015.h:313
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
SUMOReal mySpeedGainProbabilityRight
a value for tracking the probability that a change to the right is beneficial
Definition: MSLCM_SL2015.h:273
const SUMOReal myPushy
Definition: MSLCM_SL2015.h:318
const SUMOReal mySublaneParam
Definition: MSLCM_SL2015.h:316
const SUMOReal myStrategicParam
Definition: MSLCM_SL2015.h:312
bool currentDistDisallows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist)
Definition: MSLCM_SL2015.h:183
#define SUMOReal
Definition: config.h:213
const SUMOReal mySpeedGainParam
Definition: MSLCM_SL2015.h:314
void setOwnState(int state)
Definition: MSLCM_SL2015.h:108
void saveBlockerLength(SUMOReal length)
reserve space at the end of the lane to avoid dead locks
Definition: MSLCM_SL2015.h:167
bool amBlockingLeader()
Definition: MSLCM_SL2015.h:171
bool myDontBrake
flag to prevent speed adaptation by slowing down
Definition: MSLCM_SL2015.h:299
const SUMOReal myKeepRightParam
Definition: MSLCM_SL2015.h:315
const SUMOReal myChangeProbThresholdRight
Definition: MSLCM_SL2015.h:324
const SUMOReal mySpeedLossProbThreshold
Definition: MSLCM_SL2015.h:326
static LaneChangeAction getLCA(int state, SUMOReal latDist)
compute lane change action from desired lateral distance
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:305
int computeSublaneShift(const MSEdge *prevEdge, const MSEdge *curEdge)
compute shift so that prevSublane + shift = newSublane
SUMOReal mySpeedGainProbabilityLeft
a value for tracking the probability that a change to the left is beneficial
Definition: MSLCM_SL2015.h:275
Interface for lane-change models.
bool amBlockingFollowerPlusNB()
Definition: MSLCM_SL2015.h:180