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-2015 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 // ===========================================================================
49 
51  LCA_NONE = 0,
53  LCA_STAY = 1 << 0,
55  LCA_LEFT = 1 << 1,
57  LCA_RIGHT = 1 << 2,
58 
60  LCA_STRATEGIC = 1 << 3,
62  LCA_COOPERATIVE = 1 << 4,
64  LCA_SPEEDGAIN = 1 << 5,
66  LCA_KEEPRIGHT = 1 << 6,
68  LCA_TRACI = 1 << 7,
69 
71  LCA_URGENT = 1 << 8,
72 
76 
79 
84 
89 
90  // The vehicle is blocked being overlapping
91  LCA_OVERLAPPING = 1 << 13,
92 
93  // The vehicle does not have enough space to complete a continuous lane
94  // change before the next turning movement
96 
102 
104 
105 };
106 
107 
108 
109 
110 
111 // ===========================================================================
112 // class definitions
113 // ===========================================================================
119 public:
120 
124  class MSLCMessager {
125  public:
131  MSLCMessager(MSVehicle* leader, MSVehicle* neighLead, MSVehicle* neighFollow)
132  : myLeader(leader), myNeighLeader(neighLead),
133  myNeighFollower(neighFollow) { }
134 
135 
138 
139 
145  void* informLeader(void* info, MSVehicle* sender) {
146  assert(myLeader != 0);
147  return myLeader->getLaneChangeModel().inform(info, sender);
148  }
149 
150 
156  void* informNeighLeader(void* info, MSVehicle* sender) {
157  assert(myNeighLeader != 0);
158  return myNeighLeader->getLaneChangeModel().inform(info, sender);
159  }
160 
161 
167  void* informNeighFollower(void* info, MSVehicle* sender) {
168  assert(myNeighFollower != 0);
169  return myNeighFollower->getLaneChangeModel().inform(info, sender);
170  }
171 
172 
173  private:
180 
181  };
182 
184  void static initGlobalOptions(const OptionsCont& oc);
185 
191 
196 
198  virtual ~MSAbstractLaneChangeModel();
199 
200  inline int getOwnState() const {
201  return myOwnState;
202  }
203 
204  inline void setOwnState(int state) {
205  myOwnState = state;
206  }
207 
208  virtual void prepareStep() { }
209 
214  virtual int wantsChange(
215  int laneOffset,
216  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
217  const std::pair<MSVehicle*, SUMOReal>& leader,
218  const std::pair<MSVehicle*, SUMOReal>& neighLead,
219  const std::pair<MSVehicle*, SUMOReal>& neighFollow,
220  const MSLane& neighLane,
221  const std::vector<MSVehicle::LaneQ>& preb,
222  MSVehicle** lastBlocked,
223  MSVehicle** firstBlocked) = 0;
224 
225  virtual void* inform(void* info, MSVehicle* sender) = 0;
226 
238  virtual SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
239  const MSCFModel& cfModel) = 0;
240 
241  virtual void changed(int dir) = 0;
242 
243  void unchanged() {
244  if (myLastLaneChangeOffset > 0) {
246  } else if (myLastLaneChangeOffset < 0) {
248  }
249  }
250 
255  return myShadowLane;
256  }
257 
259  MSLane* getShadowLane(const MSLane* lane) const;
260 
261 
263  return myLastLaneChangeOffset;
264  }
265 
266 
268  inline bool isLaneChangeMidpointPassed() const {
270  }
271 
274  return myLaneChangeCompletion;
275  }
276 
278  inline bool isChangingLanes() const {
279  return myLaneChangeCompletion < (1 - NUMERICAL_EPS);
280  }
281 
283  inline bool hasShadowVehicle() const {
284  return myHaveShadow;
285  }
286 
288  inline int getLaneChangeDirection() const {
289  return myLaneChangeDirection;
290  }
291 
293  inline bool alreadyMoved() const {
294  return myAlreadyMoved;
295  }
296 
298  void resetMoved() {
299  myAlreadyMoved = false;
300  }
301 
303  bool startLaneChangeManeuver(MSLane* source, MSLane* target, int direction);
304 
305 
306  /* @brief continue the lane change maneuver
307  * @param[in] moved Whether the vehicle has moved to a new lane
308  */
309  void continueLaneChangeManeuver(bool moved);
310 
311  /* @brief finish the lane change maneuver
312  */
314 
316  void removeLaneChangeShadow(const MSMoveReminder::Notification reason, bool notify = true);
317 
319  virtual void saveBlockerLength(SUMOReal length) {
320  UNUSED_PARAMETER(length);
321  };
322 
324  myPartiallyOccupatedByShadow.push_back(lane);
325  }
326 
328  myNoPartiallyOccupatedByShadow.push_back(lane);
329  }
330 
331 protected:
332  virtual bool congested(const MSVehicle* const neighLeader);
333 
334  virtual bool predInteraction(const MSVehicle* const leader);
335 
337  bool cancelRequest(int state);
338 
339 
340 protected:
343 
346 
349 
352 
355 
358 
361 
364 
367 
369  std::vector<MSLane*> myPartiallyOccupatedByShadow;
370 
371  /* @brief list of lanes where there is no shadow vehicle partial occupator
372  * (when changing to a lane that has no predecessor) */
373  std::vector<MSLane*> myNoPartiallyOccupatedByShadow;
374 
375  /* @brief to be called by derived classes in their changed() method.
376  * If dir=0 is given, the current value remains unchanged */
377  void initLastLaneChangeOffset(int dir);
378 
381 
382 private:
383  /* @brief information how long ago the vehicle has performed a lane-change,
384  * sign indicates direction of the last change
385  */
387 
388 
389 
390 private:
393 };
394 
395 
396 #endif
397 
398 /****************************************************************************/
399 
No action desired.
MSAbstractLaneChangeModel(MSVehicle &v)
Constructor.
std::vector< MSLane * > myPartiallyOccupatedByShadow
list of lanes where the shadow vehicle is partial occupator
bool myHaveShadow
Wether a vehicle shadow exists.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:43
#define min(a, b)
Definition: polyfonts.c:66
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
virtual void * inform(void *info, MSVehicle *sender)=0
The action is done to help someone else.
MSVehicle * myNeighLeader
The leader on the lane the vehicle want to change to.
bool hasShadowVehicle() const
return true if the vehicle currently has a shadow vehicle
The car-following model abstraction.
Definition: MSCFModel.h:59
void * informNeighFollower(void *info, MSVehicle *sender)
Informs the follower on the desired lane.
Notification
Definition of a vehicle state.
MSLCMessager(MSVehicle *leader, MSVehicle *neighLead, MSVehicle *neighFollow)
Constructor.
virtual bool predInteraction(const MSVehicle *const leader)
MSLane * myShadowLane
The lane the vehicle shadow is on during a continuous lane change.
The action is due to a TraCI request.
The action is urgent (to be defined by lc-model)
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:1904
MSVehicle * myNeighFollower
The follower on the lane the vehicle want to change to.
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)
Wants go to the left.
#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)
bool alreadyMoved() const
reset the flag whether a vehicle already moved to false
bool myLaneChangeMidpointPassed
whether myLane has already been set to the target of the lane-change maneuver
The vehicle is blocked by left follower.
int myLaneChangeDirection
direction of the lane change maneuver -1 means right, 1 means left
static void initGlobalOptions(const OptionsCont &oc)
init global model parameters
MSLane * getShadowLane() const
Returns the lane the vehicles shadow is on during continuouss lane change.
int myOwnState
The current state of the vehicle.
bool myAlreadyMoved
whether the vehicle has already moved this step
SUMOReal getLaneChangeCompletion() const
return whether the vehicle passed the midpoint of a continuous lane change maneuver ...
Wants go to the right.
LaneChangeAction
A try to store the state of a vehicle&#39;s lane-change wish in an int.
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
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.
The action is needed to follow the route (navigational lc)
void setNoShadowPartialOccupator(MSLane *lane)
bool isLaneChangeMidpointPassed() const
return whether the vehicle passed the midpoint of a continuous lane change maneuver ...
void * informLeader(void *info, MSVehicle *sender)
Informs the leader on the same lane.
The action is due to the default of keeping right "Rechtsfahrgebot".
A storage for options typed value containers)
Definition: OptionsCont.h:108
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.
Needs to stay on the current lane.
void resetMoved()
reset the flag whether a vehicle already moved to false
virtual void changed(int dir)=0
#define SUMOReal
Definition: config.h:214
The vehicle is blocked by right follower.
#define NUMERICAL_EPS
Definition: config.h:161
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)=0
Called to examine whether the vehicle wants to change using the given laneOffset. This method gets th...
#define DELTA_T
Definition: SUMOTime.h:50
The vehicle is blocked by left leader.
SUMOReal myLaneChangeCompletion
progress of the lane change maneuver 0:started, 1:complete
void removeLaneChangeShadow(const MSMoveReminder::Notification reason, bool notify=true)
remove the shadow copy of a lane change maneuver
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:77
const MSCFModel & myCarFollowModel
The vehicle&#39;s car following model.
The vehicle is blocked by right leader.
Interface for lane-change models.
MSVehicle * myLeader
The leader on the informed vehicle&#39;s lane.
int getLaneChangeDirection() const
return the direction of the current lane change maneuver
virtual bool congested(const MSVehicle *const neighLeader)
The action is due to the wish to be faster (tactical lc)
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)
virtual ~MSAbstractLaneChangeModel()
Destructor.