SUMO - Simulation of Urban MObility
MSAbstractLaneChangeModel.h
Go to the documentation of this file.
1 /****************************************************************************/
11 // Interface for lane-change models
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 MSAbstractLaneChangeModel_h
25 #define MSAbstractLaneChangeModel_h
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <microsim/MSVehicle.h>
37 
38 class MSLane;
39 
40 // ===========================================================================
41 // used enumeration
42 // ===========================================================================
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
52 public:
53 
57  class MSLCMessager {
58  public:
64  MSLCMessager(MSVehicle* leader, MSVehicle* neighLead, MSVehicle* neighFollow)
65  : myLeader(leader), myNeighLeader(neighLead),
66  myNeighFollower(neighFollow) { }
67 
68 
71 
72 
78  void* informLeader(void* info, MSVehicle* sender) {
79  assert(myLeader != 0);
80  return myLeader->getLaneChangeModel().inform(info, sender);
81  }
82 
83 
89  void* informNeighLeader(void* info, MSVehicle* sender) {
90  assert(myNeighLeader != 0);
91  return myNeighLeader->getLaneChangeModel().inform(info, sender);
92  }
93 
94 
100  void* informNeighFollower(void* info, MSVehicle* sender) {
101  assert(myNeighFollower != 0);
102  return myNeighFollower->getLaneChangeModel().inform(info, sender);
103  }
104 
105 
106  private:
113 
114  };
115 
116  struct StateAndDist {
117  // @brief LaneChangeAction flags
118  int state;
119  // @brief lateralDistance
120  double latDist;
121  // @brief direction that was checked
122  int dir;
123 
124  StateAndDist(int _state, double _latDist, int _dir) :
125  state(_state),
126  latDist(_latDist),
127  dir(_dir) {}
128 
129  bool sameDirection(const StateAndDist& other) const {
130  return latDist * other.latDist > 0;
131  }
132  };
133 
135  void static initGlobalOptions(const OptionsCont& oc);
136 
142 
148 
150  virtual ~MSAbstractLaneChangeModel();
151 
152  inline int getOwnState() const {
153  return myOwnState;
154  }
155 
156  virtual void setOwnState(const int state);
157 
158  const std::pair<int, int>& getSavedState(const int dir) const {
159  return mySavedStates.find(dir)->second;
160  }
161 
162  void saveState(const int dir, const int stateWithoutTraCI, const int state) {
163  mySavedStates[dir] = std::make_pair(stateWithoutTraCI, state);
164  }
165 
166  virtual void prepareStep() {
170  }
171 
176  virtual int wantsChange(
177  int laneOffset,
178  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
179  const std::pair<MSVehicle*, double>& leader,
180  const std::pair<MSVehicle*, double>& neighLead,
181  const std::pair<MSVehicle*, double>& neighFollow,
182  const MSLane& neighLane,
183  const std::vector<MSVehicle::LaneQ>& preb,
184  MSVehicle** lastBlocked,
185  MSVehicle** firstBlocked) {
186  UNUSED_PARAMETER(laneOffset);
187  UNUSED_PARAMETER(&msgPass);
188  UNUSED_PARAMETER(blocked);
189  UNUSED_PARAMETER(&leader);
190  UNUSED_PARAMETER(&neighLead);
191  UNUSED_PARAMETER(&neighFollow);
192  UNUSED_PARAMETER(&neighLane);
193  UNUSED_PARAMETER(&preb);
194  UNUSED_PARAMETER(lastBlocked);
195  UNUSED_PARAMETER(firstBlocked);
196  throw ProcessError("Method not implemented by model " + toString(myModel));
197  };
198 
199  virtual int wantsChangeSublane(
200  int laneOffset,
201  const MSLeaderDistanceInfo& leaders,
202  const MSLeaderDistanceInfo& followers,
203  const MSLeaderDistanceInfo& blockers,
204  const MSLeaderDistanceInfo& neighLeaders,
205  const MSLeaderDistanceInfo& neighFollowers,
206  const MSLeaderDistanceInfo& neighBlockers,
207  const MSLane& neighLane,
208  const std::vector<MSVehicle::LaneQ>& preb,
209  MSVehicle** lastBlocked,
210  MSVehicle** firstBlocked,
211  double& latDist, int& blocked) {
212  UNUSED_PARAMETER(laneOffset);
213  UNUSED_PARAMETER(&leaders);
214  UNUSED_PARAMETER(&followers);
215  UNUSED_PARAMETER(&blockers);
216  UNUSED_PARAMETER(&neighLeaders);
217  UNUSED_PARAMETER(&neighFollowers);
218  UNUSED_PARAMETER(&neighBlockers);
219  UNUSED_PARAMETER(&neighLane);
220  UNUSED_PARAMETER(&preb);
221  UNUSED_PARAMETER(lastBlocked);
222  UNUSED_PARAMETER(firstBlocked);
223  UNUSED_PARAMETER(latDist);
224  UNUSED_PARAMETER(blocked);
225  throw ProcessError("Method not implemented by model " + toString(myModel));
226  }
227 
229  virtual void updateExpectedSublaneSpeeds(const MSLeaderInfo& ahead, int sublaneOffset, int laneIndex) {
230  UNUSED_PARAMETER(&ahead);
231  UNUSED_PARAMETER(sublaneOffset);
232  UNUSED_PARAMETER(laneIndex);
233  throw ProcessError("Method not implemented by model " + toString(myModel));
234  }
235 
238  UNUSED_PARAMETER(sd1);
239  UNUSED_PARAMETER(sd2);
240  throw ProcessError("Method not implemented by model " + toString(myModel));
241  }
242 
243  virtual void* inform(void* info, MSVehicle* sender) = 0;
244 
256  virtual double patchSpeed(const double min, const double wanted, const double max,
257  const MSCFModel& cfModel) = 0;
258 
259  /* @brief called once when the primary lane of the vehicle changes (updates
260  * the custom variables of each child implementation */
261  virtual void changed() = 0;
262 
263 
265  virtual bool debugVehicle() const {
266  return false;
267  }
268 
270  void changedToOpposite();
271 
272  void unchanged() {
273  if (myLastLaneChangeOffset > 0) {
275  } else if (myLastLaneChangeOffset < 0) {
277  }
278  }
279 
284  return myShadowLane;
285  }
286 
288  MSLane* getShadowLane(const MSLane* lane) const;
289 
291  void setShadowLane(MSLane* lane) {
292  myShadowLane = lane;
293  }
294 
295  const std::vector<MSLane*>& getShadowFurtherLanes() const {
296  return myShadowFurtherLanes;
297  }
298 
299  const std::vector<double>& getShadowFurtherLanesPosLat() const {
301  }
302 
304  return myLastLaneChangeOffset;
305  }
306 
307 
309  inline bool pastMidpoint() const {
310  return myLaneChangeCompletion >= 0.5;
311  }
312 
314  SUMOTime remainingTime() const;
315 
317  inline bool isChangingLanes() const {
318  return myLaneChangeCompletion < (1 - NUMERICAL_EPS);
319  }
320 
322  inline int getLaneChangeDirection() const {
323  return myLaneChangeDirection;
324  }
325 
327  int getShadowDirection() const;
328 
330  double getAngleOffset() const;
331 
333  inline double getLateralSpeed() const {
334  return myLateralspeed;
335  }
336 
338  inline bool alreadyChanged() const {
339  return myAlreadyChanged;
340  }
341 
343  void resetChanged() {
344  myAlreadyChanged = false;
345  }
346 
348  bool startLaneChangeManeuver(MSLane* source, MSLane* target, int direction);
349 
350  /* @brief continue the lane change maneuver and return whether the midpoint
351  * was passed in this step
352  */
353  bool updateCompletion();
354 
355  /* @brief update lane change shadow after the vehicle moved to a new lane */
356  void updateShadowLane();
357 
358  /* @brief finish the lane change maneuver
359  */
361 
362  /* @brief clean up all references to the shadow vehicle
363  */
364  void cleanupShadowLane();
365 
367  virtual void saveBlockerLength(double length) {
368  UNUSED_PARAMETER(length);
369  };
370 
372  myPartiallyOccupatedByShadow.push_back(lane);
373  }
374 
376  myNoPartiallyOccupatedByShadow.push_back(lane);
377  }
378 
380  void primaryLaneChanged(MSLane* source, MSLane* target, int direction);
381 
383  void setShadowApproachingInformation(MSLink* link) const;
385 
386  bool isOpposite() const {
387  return myAmOpposite;
388  }
389 
391  virtual std::string getParameter(const std::string& key) const {
392  throw InvalidArgument("Parameter '" + key + "' is not supported for laneChangeModel of type '" + toString(myModel) + "'");
393  }
394 
396  virtual void setParameter(const std::string& key, const std::string& value) {
397  UNUSED_PARAMETER(value);
398  throw InvalidArgument("Setting parameter '" + key + "' is not supported for laneChangeModel of type '" + toString(myModel) + "'");
399  }
400 
401 protected:
402  virtual bool congested(const MSVehicle* const neighLeader);
403 
404  virtual bool predInteraction(const std::pair<MSVehicle*, double>& leader);
405 
407  bool cancelRequest(int state);
408 
409 
410 protected:
413 
416  std::map<int, std::pair<int, int> > mySavedStates;
417 
420 
423 
426 
429 
432 
433  /* @brief Lanes that are parially (laterally) occupied by the back of the
434  * vehicle (analogue to MSVehicle::myFurtherLanes) */
435  std::vector<MSLane*> myShadowFurtherLanes;
436  std::vector<double> myShadowFurtherLanesPosLat;
437 
440 
443 
445  std::vector<MSLane*> myPartiallyOccupatedByShadow;
446 
447  /* @brief list of lanes where there is no shadow vehicle partial occupator
448  * (when changing to a lane that has no predecessor) */
449  std::vector<MSLane*> myNoPartiallyOccupatedByShadow;
450 
454 
455 
456  /* @brief to be called by derived classes in their changed() method.
457  * If dir=0 is given, the current value remains unchanged */
458  void initLastLaneChangeOffset(int dir);
459 
462 
464  static bool myLCOutput;
465 
466  static const double NO_LATERAL_NEIGHBOR;
467 
468 private:
469  /* @brief information how long ago the vehicle has performed a lane-change,
470  * sign indicates direction of the last change
471  */
473 
475  mutable std::vector<MSLink*> myApproachedByShadow;
476 
479 
480 
481 private:
484 };
485 
486 
487 #endif
488 
489 /****************************************************************************/
490 
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
std::vector< MSLane * > myPartiallyOccupatedByShadow
list of lanes where the shadow vehicle is partial occupator
const std::vector< double > & getShadowFurtherLanesPosLat() const
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:136
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
virtual 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, double &latDist, int &blocked)
#define min(a, b)
Definition: polyfonts.c:66
virtual void * inform(void *info, MSVehicle *sender)=0
MSVehicle * myNeighLeader
The leader on the lane the vehicle want to change to.
int getShadowDirection() const
return the direction in which the current shadow lane lies
double myLaneChangeCompletion
progress of the lane change maneuver 0:started, 1:complete
The car-following model abstraction.
Definition: MSCFModel.h:60
void * informNeighFollower(void *info, MSVehicle *sender)
Informs the follower on the desired lane.
Notification
Definition of a vehicle state.
static bool myLCOutput
whether to record lane-changing
MSLCMessager(MSVehicle *leader, MSVehicle *neighLead, MSVehicle *neighFollow)
Constructor.
double myLateralspeed
The lateral offset during a continuous LaneChangeManeuver.
SUMOTime DELTA_T
Definition: SUMOTime.cpp:40
double getAngleOffset() const
return the angle offset during a continuous change maneuver
virtual std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this laneChangeModel. Throw exception for unsupported key ...
virtual StateAndDist decideDirection(StateAndDist sd1, StateAndDist sd2) const
decide in which direction to move in case both directions are desirable
bool alreadyChanged() const
reset the flag whether a vehicle already moved to false
MSLane * myShadowLane
A lane that is partially occupied by the front of the vehicle but that is not the primary lane...
virtual bool predInteraction(const std::pair< MSVehicle *, double > &leader)
bool sameDirection(const StateAndDist &other) const
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:38
SUMOTime remainingTime() const
return whether the vehicle passed the midpoint of a continuous lane change maneuver ...
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:2921
void saveState(const int dir, const int stateWithoutTraCI, const int state)
std::vector< double > myShadowFurtherLanesPosLat
virtual double patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)=0
Called to adapt the speed in order to allow a lane change.
MSVehicle * myNeighFollower
The follower on the lane the vehicle want to change to.
const LaneChangeModel myModel
the type of this model
static bool myAllowOvertakingRight
whether overtaking on the right is permitted
A class responsible for exchanging messages between cars involved in lane-change interaction.
LaneChangeModel
The vehicle changes lanes (micro only)
The action has not been determined.
#define max(a, b)
Definition: polyfonts.c:65
bool cancelRequest(int state)
whether the influencer cancels the given request
std::vector< MSLane * > myNoPartiallyOccupatedByShadow
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
void setShadowPartialOccupator(MSLane *lane)
void setShadowLane(MSLane *lane)
set the shadow lane
virtual void updateExpectedSublaneSpeeds(const MSLeaderInfo &ahead, int sublaneOffset, int laneIndex)
update expected speeds for each sublane of the current edge
virtual void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this laneChangeModel. Throw exception for unsupported key ...
virtual 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...
std::vector< MSLane * > myShadowFurtherLanes
int getLaneChangeDirection() const
return the direction of the current lane change maneuver
int myLaneChangeDirection
direction of the lane change maneuver -1 means right, 1 means left
bool pastMidpoint() const
return whether the vehicle passed the midpoint of a continuous lane change maneuver ...
virtual void changed()=0
static void initGlobalOptions(const OptionsCont &oc)
init global model parameters
void setShadowApproachingInformation(MSLink *link) const
set approach information for the shadow vehicle
int myOwnState
The current state of the vehicle.
virtual bool debugVehicle() const
whether the current vehicles shall be debugged
StateAndDist(int _state, double _latDist, int _dir)
bool startLaneChangeManeuver(MSLane *source, MSLane *target, int direction)
start the lane change maneuver and return whether it continues
void primaryLaneChanged(MSLane *source, MSLane *target, int direction)
called once when the vehicles primary lane changes
MSAbstractLaneChangeModel & operator=(const MSAbstractLaneChangeModel &s)
Invalidated assignment operator.
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
void * informNeighLeader(void *info, MSVehicle *sender)
Informs the leader on the desired lane.
virtual void setOwnState(const int state)
void setNoShadowPartialOccupator(MSLane *lane)
void * informLeader(void *info, MSVehicle *sender)
Informs the leader on the same lane.
void resetChanged()
reset the flag whether a vehicle already moved to false
A storage for options typed value containers)
Definition: OptionsCont.h:99
virtual void saveBlockerLength(double length)
reserve space at the end of the lane to avoid dead locks
const std::vector< MSLane * > & getShadowFurtherLanes() const
void changedToOpposite()
called when a vehicle changes between lanes in opposite directions
long long int SUMOTime
Definition: TraCIDefs.h:52
#define NUMERICAL_EPS
Definition: config.h:151
std::vector< MSLink * > myApproachedByShadow
links which are approached by the shadow vehicle
MSLane * getShadowLane() const
Returns the lane the vehicles shadow is on during continuous/sublane lane change. ...
double getLateralSpeed() const
return the lateral speed of the current lane change maneuver
double myLastLateralGapLeft
the minimum lateral gaps to other vehicles that were found when last changing to the left and right ...
static MSAbstractLaneChangeModel * build(LaneChangeModel lcm, MSVehicle &vehicle)
Factory method for instantiating new lane changing models.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
bool myAlreadyChanged
whether the vehicle has already moved this step
const MSCFModel & myCarFollowModel
The vehicle&#39;s car following model.
bool myAmOpposite
whether the vehicle is driving in the opposite direction
MSAbstractLaneChangeModel(MSVehicle &v, const LaneChangeModel model)
Constructor.
Interface for lane-change models.
MSVehicle * myLeader
The leader on the informed vehicle&#39;s lane.
std::map< int, std::pair< int, int > > mySavedStates
virtual bool congested(const MSVehicle *const neighLeader)
const std::pair< int, int > & getSavedState(const int dir) const
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)
virtual ~MSAbstractLaneChangeModel()
Destructor.