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-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 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
121  // @brief direction that was checked
122  int dir;
123 
124  StateAndDist(int _state, SUMOReal _latDist, int _dir) :
125  state(_state),
126  latDist(_latDist),
127  dir(_dir) {}
128  };
129 
131  void static initGlobalOptions(const OptionsCont& oc);
132 
138 
144 
146  virtual ~MSAbstractLaneChangeModel();
147 
148  inline int getOwnState() const {
149  return myOwnState;
150  }
151 
152  virtual void setOwnState(int state) {
153  myOwnState = state;
154  }
155 
156  virtual void prepareStep() { }
157 
162  virtual int wantsChange(
163  int laneOffset,
164  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
165  const std::pair<MSVehicle*, SUMOReal>& leader,
166  const std::pair<MSVehicle*, SUMOReal>& neighLead,
167  const std::pair<MSVehicle*, SUMOReal>& neighFollow,
168  const MSLane& neighLane,
169  const std::vector<MSVehicle::LaneQ>& preb,
170  MSVehicle** lastBlocked,
171  MSVehicle** firstBlocked) {
172  UNUSED_PARAMETER(laneOffset);
173  UNUSED_PARAMETER(&msgPass);
174  UNUSED_PARAMETER(blocked);
175  UNUSED_PARAMETER(&leader);
176  UNUSED_PARAMETER(&neighLead);
177  UNUSED_PARAMETER(&neighFollow);
178  UNUSED_PARAMETER(&neighLane);
179  UNUSED_PARAMETER(&preb);
180  UNUSED_PARAMETER(lastBlocked);
181  UNUSED_PARAMETER(firstBlocked);
182  throw ProcessError("Method not implemented by model " + toString(myModel));
183  };
184 
185  virtual int wantsChangeSublane(
186  int laneOffset,
187  const MSLeaderDistanceInfo& leaders,
188  const MSLeaderDistanceInfo& followers,
189  const MSLeaderDistanceInfo& blockers,
190  const MSLeaderDistanceInfo& neighLeaders,
191  const MSLeaderDistanceInfo& neighFollowers,
192  const MSLeaderDistanceInfo& neighBlockers,
193  const MSLane& neighLane,
194  const std::vector<MSVehicle::LaneQ>& preb,
195  MSVehicle** lastBlocked,
196  MSVehicle** firstBlocked,
197  SUMOReal& latDist, int& blocked) {
198  UNUSED_PARAMETER(laneOffset);
199  UNUSED_PARAMETER(&leaders);
200  UNUSED_PARAMETER(&followers);
201  UNUSED_PARAMETER(&blockers);
202  UNUSED_PARAMETER(&neighLeaders);
203  UNUSED_PARAMETER(&neighFollowers);
204  UNUSED_PARAMETER(&neighBlockers);
205  UNUSED_PARAMETER(&neighLane);
206  UNUSED_PARAMETER(&preb);
207  UNUSED_PARAMETER(lastBlocked);
208  UNUSED_PARAMETER(firstBlocked);
209  UNUSED_PARAMETER(latDist);
210  UNUSED_PARAMETER(blocked);
211  throw ProcessError("Method not implemented by model " + toString(myModel));
212  }
213 
215  virtual void updateExpectedSublaneSpeeds(const MSLeaderInfo& ahead, int sublaneOffset, int laneIndex) {
216  UNUSED_PARAMETER(&ahead);
217  UNUSED_PARAMETER(sublaneOffset);
218  UNUSED_PARAMETER(laneIndex);
219  throw ProcessError("Method not implemented by model " + toString(myModel));
220  }
221 
224  UNUSED_PARAMETER(sd1);
225  UNUSED_PARAMETER(sd2);
226  throw ProcessError("Method not implemented by model " + toString(myModel));
227  }
228 
229  virtual void* inform(void* info, MSVehicle* sender) = 0;
230 
242  virtual SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
243  const MSCFModel& cfModel) = 0;
244 
245  /* @brief called once when the primary lane of the vehicle changes (updates
246  * the custom variables of each child implementation */
247  virtual void changed() = 0;
248 
249 
251  virtual bool debugVehicle() const {
252  return false;
253  }
254 
256  void changedToOpposite();
257 
258  void unchanged() {
259  if (myLastLaneChangeOffset > 0) {
261  } else if (myLastLaneChangeOffset < 0) {
263  }
264  }
265 
270  return myShadowLane;
271  }
272 
274  MSLane* getShadowLane(const MSLane* lane) const;
275 
277  void setShadowLane(MSLane* lane) {
278  myShadowLane = lane;
279  }
280 
281  const std::vector<MSLane*>& getShadowFurtherLanes() const {
282  return myShadowFurtherLanes;
283  }
284 
285  const std::vector<SUMOReal>& getShadowFurtherLanesPosLat() const {
287  }
288 
290  return myLastLaneChangeOffset;
291  }
292 
293 
295  inline bool pastMidpoint() const {
296  return myLaneChangeCompletion >= 0.5;
297  }
298 
300  SUMOTime remainingTime() const;
301 
303  inline bool isChangingLanes() const {
304  return myLaneChangeCompletion < (1 - NUMERICAL_EPS);
305  }
306 
308  inline int getLaneChangeDirection() const {
309  return myLaneChangeDirection;
310  }
311 
313  int getShadowDirection() const;
314 
316  SUMOReal getAngleOffset() const;
317 
319  inline SUMOReal getLateralSpeed() const {
320  return myLateralspeed;
321  }
322 
324  inline bool alreadyChanged() const {
325  return myAlreadyChanged;
326  }
327 
329  void resetChanged() {
330  myAlreadyChanged = false;
331  }
332 
334  bool startLaneChangeManeuver(MSLane* source, MSLane* target, int direction);
335 
336  /* @brief continue the lane change maneuver and return whether the midpoint
337  * was passed in this step
338  */
339  bool updateCompletion();
340 
341  /* @brief update lane change shadow after the vehicle moved to a new lane */
342  void updateShadowLane();
343 
344  /* @brief finish the lane change maneuver
345  */
347 
348  /* @brief clean up all references to the shadow vehicle
349  */
350  void cleanupShadowLane();
351 
353  virtual void saveBlockerLength(SUMOReal length) {
354  UNUSED_PARAMETER(length);
355  };
356 
358  myPartiallyOccupatedByShadow.push_back(lane);
359  }
360 
362  myNoPartiallyOccupatedByShadow.push_back(lane);
363  }
364 
366  void primaryLaneChanged(MSLane* source, MSLane* target, int direction);
367 
369  void setShadowApproachingInformation(MSLink* link) const;
371 
372  bool isOpposite() const {
373  return myAmOpposite;
374  }
375 
376 protected:
377  virtual bool congested(const MSVehicle* const neighLeader);
378 
379  virtual bool predInteraction(const std::pair<MSVehicle*, SUMOReal>& leader);
380 
382  bool cancelRequest(int state);
383 
384 
385 protected:
388 
391 
394 
397 
400 
403 
406 
407  /* @brief Lanes that are parially (laterally) occupied by the back of the
408  * vehicle (analogue to MSVehicle::myFurtherLanes) */
409  std::vector<MSLane*> myShadowFurtherLanes;
410  std::vector<SUMOReal> myShadowFurtherLanesPosLat;
411 
414 
417 
419  std::vector<MSLane*> myPartiallyOccupatedByShadow;
420 
421  /* @brief list of lanes where there is no shadow vehicle partial occupator
422  * (when changing to a lane that has no predecessor) */
423  std::vector<MSLane*> myNoPartiallyOccupatedByShadow;
424 
425  /* @brief to be called by derived classes in their changed() method.
426  * If dir=0 is given, the current value remains unchanged */
427  void initLastLaneChangeOffset(int dir);
428 
431 
433  static bool myLCOutput;
434 
435 private:
436  /* @brief information how long ago the vehicle has performed a lane-change,
437  * sign indicates direction of the last change
438  */
440 
442  mutable std::vector<MSLink*> myApproachedByShadow;
443 
446 
447 
448 private:
451 };
452 
453 
454 #endif
455 
456 /****************************************************************************/
457 
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
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:82
long long int SUMOTime
Definition: SUMOTime.h:43
#define min(a, b)
Definition: polyfonts.c:66
const std::vector< SUMOReal > & getShadowFurtherLanesPosLat() const
SUMOReal getLateralSpeed() const
return the lateral speed of the current lane change maneuver
std::vector< SUMOReal > myShadowFurtherLanesPosLat
virtual void * inform(void *info, MSVehicle *sender)=0
virtual bool predInteraction(const std::pair< MSVehicle *, SUMOReal > &leader)
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
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
virtual 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...
MSLCMessager(MSVehicle *leader, MSVehicle *neighLead, MSVehicle *neighFollow)
Constructor.
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
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...
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
SUMOTime remainingTime() const
return whether the vehicle passed the midpoint of a continuous lane change maneuver ...
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:2702
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, SUMOReal &latDist, int &blocked)
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) XXX: What if a vehicle changes lanes and passes a junction sim...
#define max(a, b)
Definition: polyfonts.c:65
bool cancelRequest(int state)
whether the influencer cancels the given request
std::vector< MSLane * > myNoPartiallyOccupatedByShadow
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
std::vector< MSLane * > myShadowFurtherLanes
int getLaneChangeDirection() const
return the direction of the current lane change maneuver
virtual void setOwnState(int state)
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.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
virtual bool debugVehicle() const
whether the current vehicles shall be debugged
virtual void saveBlockerLength(SUMOReal length)
reserve space at the end of the lane to avoid dead locks
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.
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 SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel &cfModel)=0
Called to adapt the speed in order to allow a lane change.
SUMOReal myLateralspeed
The lateral offset during a continuous LaneChangeManeuver.
const std::vector< MSLane * > & getShadowFurtherLanes() const
void changedToOpposite()
called when a vehicle changes between lanes in opposite directions
#define SUMOReal
Definition: config.h:213
StateAndDist(int _state, SUMOReal _latDist, int _dir)
#define NUMERICAL_EPS
Definition: config.h:160
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. ...
SUMOReal myLaneChangeCompletion
progress of the lane change maneuver 0:started, 1:complete
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.
SUMOReal getAngleOffset() const
return the angle offset during a continuous change maneuver
Interface for lane-change models.
MSVehicle * myLeader
The leader on the informed vehicle&#39;s lane.
virtual bool congested(const MSVehicle *const neighLeader)
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)
virtual ~MSAbstractLaneChangeModel()
Destructor.