SUMO - Simulation of Urban MObility
MSLCM_LC2013.h
Go to the documentation of this file.
1 /****************************************************************************/
11 // A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 #ifndef MSLCM_LC2013_h
25 #define MSLCM_LC2013_h
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
38 #include <vector>
39 
40 // INVALID_SPEED should be used when the construction of upper bound for the speed
41 // leads to no restrictions, e.g. during LC-messaging to followers or leaders.
42 // Currently either std::numeric_limits<...>.max() or -1 is used for this purpose in many places.
43 // TODO: implement this everywhere and remove workarounds for ballistic update in cases of possible '-1'-returns. Refs. #2577
44 #define INVALID_SPEED 299792458 + 1 // nothing can go faster than the speed of light!
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
56 public:
57 
58  enum MyLCAEnum {
61  LCA_MRIGHT = 1 << 18,
62  LCA_MLEFT = 1 << 19,
63  // !!! never set LCA_UNBLOCK = 1 << 20,
65  // !!! never used LCA_AMBLOCKINGSECONDFOLLOWER = 1 << 22,
66  LCA_CHANGE_TO_HELP = 1 << 23,
67  // !!! never read LCA_KEEP1 = 1 << 24,
68  // !!! never used LCA_KEEP2 = 1 << 25,
69  LCA_AMBACKBLOCKER = 1 << 26,
71  };
72 
73 
75 
76  virtual ~MSLCM_LC2013();
77 
78  bool debugVehicle() const;
79 
84  int wantsChange(
85  int laneOffset,
86  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
87  const std::pair<MSVehicle*, double>& leader,
88  const std::pair<MSVehicle*, double>& neighLead,
89  const std::pair<MSVehicle*, double>& neighFollow,
90  const MSLane& neighLane,
91  const std::vector<MSVehicle::LaneQ>& preb,
92  MSVehicle** lastBlocked,
93  MSVehicle** firstBlocked);
94 
95  void* inform(void* info, MSVehicle* sender);
96 
105  double patchSpeed(const double min, const double wanted, const double max,
106  const MSCFModel& cfModel);
108  double _patchSpeed(const double min, const double wanted, const double max,
109  const MSCFModel& cfModel);
110 
111  void changed();
112 
113  void prepareStep();
114 
116  std::string getParameter(const std::string& key) const;
117 
119  void setParameter(const std::string& key, const std::string& value);
120 
121 protected:
122 
124  int _wantsChange(
125  int laneOffset,
126  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
127  const std::pair<MSVehicle*, double>& leader,
128  const std::pair<MSVehicle*, double>& neighLead,
129  const std::pair<MSVehicle*, double>& neighFollow,
130  const MSLane& neighLane,
131  const std::vector<MSVehicle::LaneQ>& preb,
132  MSVehicle** lastBlocked,
133  MSVehicle** firstBlocked);
134 
135  /* @brief decide whether we will overtake or follow a blocking leader
136  * and inform it accordingly
137  * If we decide to follow, myVSafes will be extended
138  * returns the planned speed if following or -1 if overtaking */
140  int blocked, int dir,
141  const std::pair<MSVehicle*, double>& neighLead,
142  double remainingSeconds);
143 
146  int blocked, int dir,
147  const std::pair<MSVehicle*, double>& neighFollow,
148  double remainingSeconds,
149  double plannedSpeed);
150 
151 
152  /* @brief compute the distance to cover until a safe gap to the vehicle v in front is reached
153  * assuming constant velocities
154  * @param[in] follower the vehicle which overtakes
155  * @param[in] leader the vehicle to be overtaken
156  * @param[in] gap initial distance between front of follower and back of leader
157  * @param[in] leaderSpeed an assumed speed for the leader (default uses the current speed)
158  * @param[in] followerSpeed an assumed speed for the follower (default uses the current speed)
159  * @return the distance that the relative positions would have to change.
160  */
161  static double overtakeDistance(const MSVehicle* follower, const MSVehicle* leader, const double gap, double followerSpeed = INVALID_SPEED, double leaderSpeed = INVALID_SPEED);
162 
164  int slowDownForBlocked(MSVehicle** blocked, int state);
165 
166 
167  // XXX: consider relocation of the roundabout functions (perhaps to MSVehicle or the abstract LC Model...) (Leo)
177  static void
178  getRoundaboutAheadInfo(const MSLCM_LC2013* lcm, const MSVehicle::LaneQ& curr, const MSVehicle::LaneQ& neigh,
179  double& roundaboutDistanceAhead, double& roundaboutDistanceAheadNeigh, int& roundaboutEdgesAhead, int& roundaboutEdgesAheadNeigh);
180 
187  double
188  roundaboutDistBonus(double roundaboutDistAhead, int roundaboutEdgesAhead) const;
189 
195  static double
196  distanceAlongNextRoundabout(double position, const MSLane* initialLane, const std::vector<MSLane*>& continuationLanes);
197 
199  void saveBlockerLength(MSVehicle* blocker, int lcaCounter);
200 
202  inline void saveBlockerLength(double length) {
204  };
205 
206  inline bool amBlockingLeader() {
207  return (myOwnState & LCA_AMBLOCKINGLEADER) != 0;
208  }
209  inline bool amBlockingFollower() {
210  return (myOwnState & LCA_AMBLOCKINGFOLLOWER) != 0;
211  }
212  inline bool amBlockingFollowerNB() {
214  }
215  inline bool amBlockingFollowerPlusNB() {
217  }
218  inline bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist) {
219  return dist / (abs(laneOffset)) < lookForwardDist;
220  }
221  inline bool currentDistAllows(double dist, int laneOffset, double lookForwardDist) {
222  return dist / abs(laneOffset) > lookForwardDist;
223  }
224 
226  typedef std::pair<double, int> Info;
227 
228 
229 
230 protected:
233  /* @brief a value for tracking the probability of following the/"Rechtsfahrgebot"
234  * A larger negative value indicates higher probability for moving to the
235  * right (as in mySpeedGainProbability) */
237 
239  double myLeftSpace;
240 
241  /*@brief the speed to use when computing the look-ahead distance for
242  * determining urgency of strategic lane changes */
244 
245  std::vector<double> myVSafes;
246  bool myDontBrake; // XXX: myDontBrake is initialized as false and seems not to be changed anywhere... What's its purpose???
247 
249 
251  double myCooperativeParam; // in [0,1]
254 
255  const double myExperimentalParam1; // for feature testing
257 
259 
260  // @brief willingness to encroach on other vehicles laterally (pushing them around)
264 };
265 
266 
267 #endif
268 
269 /****************************************************************************/
270 
double myLeadingBlockerLength
Definition: MSLCM_LC2013.h:238
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.
void saveBlockerLength(MSVehicle *blocker, int lcaCounter)
save space for vehicles which need to counter-lane-change
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
MSLCM_LC2013(MSVehicle &v)
void prepareStep()
#define min(a, b)
Definition: polyfonts.c:66
bool amBlockingFollower()
Definition: MSLCM_LC2013.h:209
bool amBlockingFollowerNB()
Definition: MSLCM_LC2013.h:212
double myKeepRightProbability
Definition: MSLCM_LC2013.h:236
The car-following model abstraction.
Definition: MSCFModel.h:60
double myLookAheadSpeed
Definition: MSLCM_LC2013.h:243
double myStrategicParam
Definition: MSLCM_LC2013.h:250
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
double myKeepRightParam
Definition: MSLCM_LC2013.h:253
T MAX2(T a, T b)
Definition: StdDefs.h:70
double _patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)
std::pair< double, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
Definition: MSLCM_LC2013.h:226
#define abs(a)
Definition: polyfonts.c:67
bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_LC2013.h:218
const double myChangeProbThresholdRight
Definition: MSLCM_LC2013.h:261
static double distanceAlongNextRoundabout(double position, const MSLane *initialLane, const std::vector< MSLane *> &continuationLanes)
compute the distance on the next upcoming roundabout along a given sequence of lanes.
bool debugVehicle() const
whether the current vehicles shall be debugged
A class responsible for exchanging messages between cars involved in lane-change interaction.
static double overtakeDistance(const MSVehicle *follower, const MSVehicle *leader, const double gap, double followerSpeed=INVALID_SPEED, double leaderSpeed=INVALID_SPEED)
A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013...
Definition: MSLCM_LC2013.h:55
double mySpeedGainParam
Definition: MSLCM_LC2013.h:252
#define max(a, b)
Definition: polyfonts.c:65
double mySpeedGainProbability
a value for tracking the probability that a change to the offset with the same sign is beneficial ...
Definition: MSLCM_LC2013.h:232
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
const double myChangeProbThresholdLeft
Definition: MSLCM_LC2013.h:262
bool currentDistAllows(double dist, int laneOffset, double lookForwardDist)
Definition: MSLCM_LC2013.h:221
const double myExperimentalParam1
Definition: MSLCM_LC2013.h:255
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
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...
A structure representing the best lanes for continuing the current route starting at &#39;lane&#39;...
Definition: MSVehicle.h:702
int myOwnState
The current state of the vehicle.
std::vector< double > myVSafes
Definition: MSLCM_LC2013.h:245
double myLeftSpace
Definition: MSLCM_LC2013.h:239
static void getRoundaboutAheadInfo(const MSLCM_LC2013 *lcm, const MSVehicle::LaneQ &curr, const MSVehicle::LaneQ &neigh, double &roundaboutDistanceAhead, double &roundaboutDistanceAheadNeigh, int &roundaboutEdgesAhead, int &roundaboutEdgesAheadNeigh)
computes the distance and number of edges in the next upcoming roundabout along the lane continuation...
void saveBlockerLength(double length)
reserve space at the end of the lane to avoid dead locks
Definition: MSLCM_LC2013.h:202
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 myCooperativeParam
Definition: MSLCM_LC2013.h:251
virtual ~MSLCM_LC2013()
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key ...
bool amBlockingFollowerPlusNB()
Definition: MSLCM_LC2013.h:215
double informLeader(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, double > &neighLead, double remainingSeconds)
void * inform(void *info, MSVehicle *sender)
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
#define INVALID_SPEED
Definition: MSLCM_LC2013.h:44
Interface for lane-change models.
bool amBlockingLeader()
Definition: MSLCM_LC2013.h:206
double roundaboutDistBonus(double roundaboutDistAhead, int roundaboutEdgesAhead) const
Computes the artificial bonus distance for roundabout lanes this additional distance reduces the sens...