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-2013 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,
56  LCA_LEFT = 4,
58  LCA_RIGHT = 8,
59 
62 
63 
66 
71 
76 
82 
83  // The vehicle is blocked being overlapping
84  // This is currently not used, but I'll keep it while working on this, as
85  // overlapping may be interested, but surely divided by leader/follower
86  // LCA_OVERLAPPING = 64
88 
89 };
90 
91 
92 
93 
94 
95 // ===========================================================================
96 // class definitions
97 // ===========================================================================
103 public:
107  class MSLCMessager {
108  public:
114  MSLCMessager(MSVehicle* leader, MSVehicle* neighLead, MSVehicle* neighFollow)
115  : myLeader(leader), myNeighLeader(neighLead),
116  myNeighFollower(neighFollow) { }
117 
118 
121 
122 
128  void* informLeader(void* info, MSVehicle* sender) {
129  assert(myLeader != 0);
130  return myLeader->getLaneChangeModel().inform(info, sender);
131  }
132 
133 
139  void* informNeighLeader(void* info, MSVehicle* sender) {
140  assert(myNeighLeader != 0);
141  return myNeighLeader->getLaneChangeModel().inform(info, sender);
142  }
143 
144 
150  void* informNeighFollower(void* info, MSVehicle* sender) {
151  assert(myNeighFollower != 0);
152  return myNeighFollower->getLaneChangeModel().inform(info, sender);
153  }
154 
155 
156  private:
163 
164  };
165 
166 
171 
173  virtual ~MSAbstractLaneChangeModel();
174 
175  inline int getOwnState() const {
176  return myOwnState;
177  }
178 
179  inline void setOwnState(int state) {
180  myOwnState = state;
181  }
182 
183  virtual void prepareStep() { }
184 
188  virtual int wantsChangeToRight(
189  MSLCMessager& msgPass, int blocked,
190  const std::pair<MSVehicle*, SUMOReal>& leader,
191  const std::pair<MSVehicle*, SUMOReal>& neighLead,
192  const std::pair<MSVehicle*, SUMOReal>& neighFollow,
193  const MSLane& neighLane,
194  const std::vector<MSVehicle::LaneQ>& preb,
195  MSVehicle** lastBlocked) = 0;
196 
200  virtual int wantsChangeToLeft(
201  MSLCMessager& msgPass, int blocked,
202  const std::pair<MSVehicle*, SUMOReal>& leader,
203  const std::pair<MSVehicle*, SUMOReal>& neighLead,
204  const std::pair<MSVehicle*, SUMOReal>& neighFollow,
205  const MSLane& neighLane,
206  const std::vector<MSVehicle::LaneQ>& preb,
207  MSVehicle** lastBlocked) = 0;
208 
209  virtual void* inform(void* info, MSVehicle* sender) = 0;
210 
222  virtual SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
223  const MSCFModel& cfModel) = 0;
224 
225  virtual void changed() = 0;
226 
227  void unchanged() {
229  }
230 
235  return myShadowLane;
236  }
237 
238 
240  return myLastLaneChangeOffset;
241  }
242 
243 
245  inline bool isLaneChangeMidpointPassed() const {
247  }
248 
251  return myLaneChangeCompletion;
252  }
253 
255  inline bool isChangingLanes() const {
256  return myLaneChangeCompletion < (1 - NUMERICAL_EPS);
257  }
258 
260  inline int getLaneChangeDirection() const {
261  return myLaneChangeDirection;
262  }
263 
265  inline bool alreadyMoved() const {
266  return myAlreadyMoved;
267  }
268 
270  void resetMoved() {
271  myAlreadyMoved = false;
272  }
273 
274 
276  bool startLaneChangeManeuver(MSLane* source, MSLane* target, int direction);
277 
278 
279  /* @brief continue the lane change maneuver
280  * @param[in] moved Whether the vehicle has moved to a new lane
281  */
282  void continueLaneChangeManeuver(bool moved);
283 
284  /* @brief finish the lane change maneuver
285  */
286  inline void endLaneChangeManeuver() {
289  myShadowLane = 0;
290  }
291 
293  void removeLaneChangeShadow();
294 
295 #ifndef NO_TRACI
296 
303  myChangeRequest = request;
304  };
305 
313  if (request == myChangeRequest) {
315  }
316  }
317 #endif
318 
319 protected:
320  virtual bool congested(const MSVehicle* const neighLeader);
321 
322  virtual bool predInteraction(const MSVehicle* const leader);
323 
324 
325 protected:
328 
331 
334 
337 
340 
343 
346 
349 
352 
353 #ifndef NO_TRACI
355 #endif
356 
359 
360 private:
363 };
364 
365 
366 #endif
367 
368 /****************************************************************************/
369 
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
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.
vehicle doesn&#39;t want to change
Definition: MSVehicle.h:127
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 the wish to follow the route (navigational lc)
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:1527
MSVehicle * myNeighFollower
The follower on the lane the vehicle want to change to.
virtual int wantsChangeToLeft(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)=0
Called to examine whether the vehicle wants to change to left This method gets the information about ...
A class responsible for exchanging messages between cars involved in lane-change interaction.
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
ChangeRequest
Requests set via TraCI.
Definition: MSVehicle.h:125
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
virtual int wantsChangeToRight(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)=0
Called to examine whether the vehicle wants to change to right This method gets the information about...
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.
bool startLaneChangeManeuver(MSLane *source, MSLane *target, int direction)
start the lane change maneuver and return whether it continues
virtual void requestLaneChange(MSVehicle::ChangeRequest request)
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.
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.
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.
void resetMoved()
reset the flag whether a vehicle already moved to false
#define SUMOReal
Definition: config.h:221
The vehicle is blocked by right follower.
#define NUMERICAL_EPS
Definition: config.h:165
#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
Representation of a lane in the micro simulation.
Definition: MSLane.h:73
const MSCFModel & myCarFollowModel
The vehicle&#39;s car following model.
virtual void fulfillChangeRequest(MSVehicle::ChangeRequest request)
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)
MSVehicle::ChangeRequest myChangeRequest
virtual ~MSAbstractLaneChangeModel()
Destructor.