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