SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2016 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*, SUMOReal>& leader,
88  const std::pair<MSVehicle*, SUMOReal>& neighLead,
89  const std::pair<MSVehicle*, SUMOReal>& 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  SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
106  const MSCFModel& cfModel);
108  SUMOReal _patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
109  const MSCFModel& cfModel);
110 
111  void changed();
112 
113  void prepareStep();
114 
115 
116 protected:
117 
119  int _wantsChange(
120  int laneOffset,
121  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
122  const std::pair<MSVehicle*, SUMOReal>& leader,
123  const std::pair<MSVehicle*, SUMOReal>& neighLead,
124  const std::pair<MSVehicle*, SUMOReal>& neighFollow,
125  const MSLane& neighLane,
126  const std::vector<MSVehicle::LaneQ>& preb,
127  MSVehicle** lastBlocked,
128  MSVehicle** firstBlocked);
129 
130  /* @brief decide whether we will overtake or follow a blocking leader
131  * and inform it accordingly
132  * If we decide to follow, myVSafes will be extended
133  * returns the planned speed if following or -1 if overtaking */
135  int blocked, int dir,
136  const std::pair<MSVehicle*, SUMOReal>& neighLead,
137  SUMOReal remainingSeconds);
138 
141  int blocked, int dir,
142  const std::pair<MSVehicle*, SUMOReal>& neighFollow,
143  SUMOReal remainingSeconds,
144  SUMOReal plannedSpeed);
145 
146 
147  /* @brief compute the distance to cover until a safe gap to the vehicle v in front is reached
148  * assuming constant velocities
149  * @param[in] follower the vehicle which overtakes
150  * @param[in] leader the vehicle to be overtaken
151  * @param[in] gap initial distance between front of follower and back of leader
152  * @param[in] leaderSpeed an assumed speed for the leader (default uses the current speed)
153  * @param[in] followerSpeed an assumed speed for the follower (default uses the current speed)
154  * @return the distance that the relative positions would have to change.
155  */
156  static SUMOReal overtakeDistance(const MSVehicle* follower, const MSVehicle* leader, const SUMOReal gap, SUMOReal followerSpeed = INVALID_SPEED, SUMOReal leaderSpeed = INVALID_SPEED);
157 
159  int slowDownForBlocked(MSVehicle** blocked, int state);
160 
161 
162  // XXX: consider relocation of the roundabout functions (perhaps to MSVehicle or the abstract LC Model...) (Leo)
172  static void
173  getRoundaboutAheadInfo(const MSLCM_LC2013* lcm, const MSVehicle::LaneQ& curr, const MSVehicle::LaneQ& neigh,
174  SUMOReal& roundaboutDistanceAhead, SUMOReal& roundaboutDistanceAheadNeigh, int& roundaboutEdgesAhead, int& roundaboutEdgesAheadNeigh);
175 
182  SUMOReal
183  roundaboutDistBonus(SUMOReal roundaboutDistAhead, int roundaboutEdgesAhead) const;
184 
190  static SUMOReal
191  distanceAlongNextRoundabout(SUMOReal position, const MSLane* initialLane, const std::vector<MSLane*>& continuationLanes);
192 
194  void saveBlockerLength(MSVehicle* blocker, int lcaCounter);
195 
197  inline void saveBlockerLength(SUMOReal length) {
199  };
200 
201  inline bool amBlockingLeader() {
202  return (myOwnState & LCA_AMBLOCKINGLEADER) != 0;
203  }
204  inline bool amBlockingFollower() {
205  return (myOwnState & LCA_AMBLOCKINGFOLLOWER) != 0;
206  }
207  inline bool amBlockingFollowerNB() {
209  }
210  inline bool amBlockingFollowerPlusNB() {
212  }
213  inline bool currentDistDisallows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist) {
214  return dist / (abs(laneOffset)) < lookForwardDist;
215  }
216  inline bool currentDistAllows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist) {
217  return dist / abs(laneOffset) > lookForwardDist;
218  }
219 
221  typedef std::pair<SUMOReal, int> Info;
222 
223 
224 
225 protected:
228  /* @brief a value for tracking the probability of following the/"Rechtsfahrgebot"
229  * A larger negative value indicates higher probability for moving to the
230  * right (as in mySpeedGainProbability) */
232 
235 
236  /*@brief the speed to use when computing the look-ahead distance for
237  * determining urgency of strategic lane changes */
239 
240  std::vector<SUMOReal> myVSafes;
241  bool myDontBrake; // XXX: myDontBrake is initialized as false and seems not to be changed anywhere... What's its purpose???
242 
244 
246  const SUMOReal myCooperativeParam; // in [0,1]
250 
252 
253  // @brief willingness to encroach on other vehicles laterally (pushing them around)
257 };
258 
259 
260 #endif
261 
262 /****************************************************************************/
263 
bool debugVehicle() const
whether the current vehicles shall be debugged
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:82
MSLCM_LC2013(MSVehicle &v)
int wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, SUMOReal > &leader, const std::pair< MSVehicle *, SUMOReal > &neighLead, const std::pair< MSVehicle *, SUMOReal > &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...
#define min(a, b)
Definition: polyfonts.c:66
bool amBlockingFollower()
Definition: MSLCM_LC2013.h:204
bool amBlockingFollowerNB()
Definition: MSLCM_LC2013.h:207
static SUMOReal distanceAlongNextRoundabout(SUMOReal position, const MSLane *initialLane, const std::vector< MSLane * > &continuationLanes)
compute the distance on the next upcoming roundabout along a given sequence of lanes.
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.
const SUMOReal myChangeProbThresholdRight
Definition: MSLCM_LC2013.h:254
The car-following model abstraction.
Definition: MSCFModel.h:60
SUMOReal myKeepRightProbability
Definition: MSLCM_LC2013.h:231
T MAX2(T a, T b)
Definition: StdDefs.h:75
const SUMOReal myKeepRightParam
Definition: MSLCM_LC2013.h:248
const SUMOReal myChangeProbThresholdLeft
Definition: MSLCM_LC2013.h:255
static void getRoundaboutAheadInfo(const MSLCM_LC2013 *lcm, const MSVehicle::LaneQ &curr, const MSVehicle::LaneQ &neigh, SUMOReal &roundaboutDistanceAhead, SUMOReal &roundaboutDistanceAheadNeigh, int &roundaboutEdgesAhead, int &roundaboutEdgesAheadNeigh)
computes the distance and number of edges in the next upcoming roundabout along the lane continuation...
std::vector< SUMOReal > myVSafes
Definition: MSLCM_LC2013.h:240
const SUMOReal myCooperativeParam
Definition: MSLCM_LC2013.h:246
#define abs(a)
Definition: polyfonts.c:67
void informFollower(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, SUMOReal > &neighFollow, SUMOReal remainingSeconds, SUMOReal plannedSpeed)
decide whether we will try cut in before the follower or allow to be overtaken
void saveBlockerLength(SUMOReal length)
reserve space at the end of the lane to avoid dead locks
Definition: MSLCM_LC2013.h:197
const SUMOReal myStrategicParam
Definition: MSLCM_LC2013.h:245
A class responsible for exchanging messages between cars involved in lane-change interaction.
bool currentDistDisallows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist)
Definition: MSLCM_LC2013.h:213
A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013...
Definition: MSLCM_LC2013.h:55
bool currentDistAllows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist)
Definition: MSLCM_LC2013.h:216
#define max(a, b)
Definition: polyfonts.c:65
SUMOReal myLeadingBlockerLength
Definition: MSLCM_LC2013.h:233
SUMOReal myLookAheadSpeed
Definition: MSLCM_LC2013.h:238
static SUMOReal overtakeDistance(const MSVehicle *follower, const MSVehicle *leader, const SUMOReal gap, SUMOReal followerSpeed=INVALID_SPEED, SUMOReal leaderSpeed=INVALID_SPEED)
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
A structure representing the best lanes for continuing the route.
Definition: MSVehicle.h:669
int myOwnState
The current state of the vehicle.
SUMOReal informLeader(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, SUMOReal > &neighLead, SUMOReal remainingSeconds)
std::pair< SUMOReal, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
Definition: MSLCM_LC2013.h:221
int _wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, SUMOReal > &leader, const std::pair< MSVehicle *, SUMOReal > &neighLead, const std::pair< MSVehicle *, SUMOReal > &neighFollow, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked)
helper function for doing the actual work
virtual ~MSLCM_LC2013()
SUMOReal mySpeedGainProbability
a value for tracking the probability that a change to the offset with the same sign is beneficial ...
Definition: MSLCM_LC2013.h:227
SUMOReal myLeftSpace
Definition: MSLCM_LC2013.h:234
#define SUMOReal
Definition: config.h:214
bool amBlockingFollowerPlusNB()
Definition: MSLCM_LC2013.h:210
SUMOReal _patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel &cfModel)
SUMOReal roundaboutDistBonus(SUMOReal roundaboutDistAhead, int roundaboutEdgesAhead) const
Computes the artificial bonus distance for roundabout lanes this additional distance reduces the sens...
void * inform(void *info, MSVehicle *sender)
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
const SUMOReal mySpeedGainParam
Definition: MSLCM_LC2013.h:247
#define INVALID_SPEED
Definition: MSLCM_LC2013.h:44
Interface for lane-change models.
bool amBlockingLeader()
Definition: MSLCM_LC2013.h:201