SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
14 // Copyright (C) 2001-2014 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 "MSVehicle.h"
37 class MSLane;
38 
39 // ===========================================================================
40 // used enumeration
41 // ===========================================================================
48 
50  LCA_NONE = 0,
52  LCA_STAY = 1 << 0,
54  LCA_LEFT = 1 << 1,
56  LCA_RIGHT = 1 << 2,
57 
59  LCA_STRATEGIC = 1 << 3,
61  LCA_COOPERATIVE = 1 << 4,
63  LCA_SPEEDGAIN = 1 << 5,
65  LCA_KEEPRIGHT = 1 << 6,
67  LCA_TRACI = 1 << 7,
68 
70  LCA_URGENT = 1 << 8,
71 
75 
78 
83 
88 
89  // The vehicle is blocked being overlapping
90  LCA_OVERLAPPING = 1 << 13,
91 
97 
99 
100 };
101 
102 
103 
104 
105 
106 // ===========================================================================
107 // class definitions
108 // ===========================================================================
114 public:
115 
119  class MSLCMessager {
120  public:
126  MSLCMessager(MSVehicle* leader, MSVehicle* neighLead, MSVehicle* neighFollow)
127  : myLeader(leader), myNeighLeader(neighLead),
128  myNeighFollower(neighFollow) { }
129 
130 
133 
134 
140  void* informLeader(void* info, MSVehicle* sender) {
141  assert(myLeader != 0);
142  return myLeader->getLaneChangeModel().inform(info, sender);
143  }
144 
145 
151  void* informNeighLeader(void* info, MSVehicle* sender) {
152  assert(myNeighLeader != 0);
153  return myNeighLeader->getLaneChangeModel().inform(info, sender);
154  }
155 
156 
162  void* informNeighFollower(void* info, MSVehicle* sender) {
163  assert(myNeighFollower != 0);
164  return myNeighFollower->getLaneChangeModel().inform(info, sender);
165  }
166 
167 
168  private:
175 
176  };
177 
183 
188 
190  virtual ~MSAbstractLaneChangeModel();
191 
192  inline int getOwnState() const {
193  return myOwnState;
194  }
195 
196  inline void setOwnState(int state) {
197  myOwnState = state;
198  }
199 
200  virtual void prepareStep() { }
201 
206  virtual int wantsChange(
207  int laneOffset,
208  MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
209  const std::pair<MSVehicle*, SUMOReal>& leader,
210  const std::pair<MSVehicle*, SUMOReal>& neighLead,
211  const std::pair<MSVehicle*, SUMOReal>& neighFollow,
212  const MSLane& neighLane,
213  const std::vector<MSVehicle::LaneQ>& preb,
214  MSVehicle** lastBlocked,
215  MSVehicle** firstBlocked) = 0;
216 
217  virtual void* inform(void* info, MSVehicle* sender) = 0;
218 
230  virtual SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
231  const MSCFModel& cfModel) = 0;
232 
233  virtual void changed() = 0;
234 
235  void unchanged() {
237  }
238 
243  return myShadowLane;
244  }
245 
246 
248  return myLastLaneChangeOffset;
249  }
250 
251 
253  inline bool isLaneChangeMidpointPassed() const {
255  }
256 
259  return myLaneChangeCompletion;
260  }
261 
263  inline bool isChangingLanes() const {
264  return myLaneChangeCompletion < (1 - NUMERICAL_EPS);
265  }
266 
268  inline int getLaneChangeDirection() const {
269  return myLaneChangeDirection;
270  }
271 
273  inline bool alreadyMoved() const {
274  return myAlreadyMoved;
275  }
276 
278  void resetMoved() {
279  myAlreadyMoved = false;
280  }
281 
282 
284  bool startLaneChangeManeuver(MSLane* source, MSLane* target, int direction);
285 
286 
287  /* @brief continue the lane change maneuver
288  * @param[in] moved Whether the vehicle has moved to a new lane
289  */
290  void continueLaneChangeManeuver(bool moved);
291 
292  /* @brief finish the lane change maneuver
293  */
294  inline void endLaneChangeManeuver() {
297  myShadowLane = 0;
298  }
299 
301  void removeLaneChangeShadow();
302 
304  virtual void saveBlockerLength(SUMOReal length) {
305  UNUSED_PARAMETER(length);
306  };
307 
308 protected:
309  virtual bool congested(const MSVehicle* const neighLeader);
310 
311  virtual bool predInteraction(const MSVehicle* const leader);
312 
313 
314 protected:
317 
320 
323 
326 
329 
332 
335 
338 
341 
344 
345 private:
348 };
349 
350 
351 #endif
352 
353 /****************************************************************************/
354 
No action desired.
MSAbstractLaneChangeModel(MSVehicle &v)
Constructor.
bool myHaveShadow
Wether a vehicle shadow exists.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
#define min(a, b)
Definition: polyfonts.c:62
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.
The car-following model abstraction.
Definition: MSCFModel.h:58
void * informNeighFollower(void *info, MSVehicle *sender)
Informs the follower on the desired lane.
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:38
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:1740
MSVehicle * myNeighFollower
The follower on the lane the vehicle want to change to.
A class responsible for exchanging messages between cars involved in lane-change interaction.
LaneChangeModel
Wants go to the left.
#define max(a, b)
Definition: polyfonts.c:61
void removeLaneChangeShadow()
remove the shadow copy of a lane change maneuver
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
virtual void changed()=0
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'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)
SUMOTime myLastLaneChangeOffset
information how long ago the vehicle has performed a lane-change
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".
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
#define SUMOReal
Definition: config.h:215
The vehicle is blocked by right follower.
#define NUMERICAL_EPS
Definition: config.h:159
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
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's car following model.
The vehicle is blocked by right leader.
Interface for lane-change models.
MSVehicle * myLeader
The leader on the informed vehicle'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)
virtual ~MSAbstractLaneChangeModel()
Destructor.