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 /****************************************************************************/
10 // Interface for lane-change models
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef MSAbstractLaneChangeModel_h
24 #define MSAbstractLaneChangeModel_h
25 
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 "MSLane.h"
37 #include "MSVehicle.h"
38 
39 
40 // ===========================================================================
41 // used enumeration
42 // ===========================================================================
49 
51  LCA_NONE = 0,
57  LCA_LEFT = 4,
59  LCA_RIGHT = 8,
60 
63 
64 
67 
72 
77 
83 
84  // The vehicle is blocked being overlapping
85  // This is currently not used, but I'll keep it while working on this, as
86  // overlapping may be interested, but surely divided by leader/follower
87  // LCA_OVERLAPPING = 64
89 
90 };
91 
92 
93 
94 
95 
96 // ===========================================================================
97 // class definitions
98 // ===========================================================================
104 public:
108  class MSLCMessager {
109  public:
115  MSLCMessager(MSVehicle* leader, MSVehicle* neighLead, MSVehicle* neighFollow)
116  : myLeader(leader), myNeighLeader(neighLead),
117  myNeighFollower(neighFollow) { }
118 
119 
122 
123 
129  void* informLeader(void* info, MSVehicle* sender) {
130  assert(myLeader != 0);
131  return myLeader->getLaneChangeModel().inform(info, sender);
132  }
133 
134 
140  void* informNeighLeader(void* info, MSVehicle* sender) {
141  assert(myNeighLeader != 0);
142  return myNeighLeader->getLaneChangeModel().inform(info, sender);
143  }
144 
145 
151  void* informNeighFollower(void* info, MSVehicle* sender) {
152  assert(myNeighFollower != 0);
153  return myNeighFollower->getLaneChangeModel().inform(info, sender);
154  }
155 
156 
157  private:
164 
165  };
166 
167 
168 
173  : myVehicle(v), myOwnState(0),
174 #ifndef NO_TRACI
175  myChangeRequest(MSVehicle::REQUEST_NONE),
176 #endif
177  myCarFollowModel(v.getCarFollowModel()) {
178  }
179 
180 
183 
184 
185 
186  int getOwnState() const {
187  return myOwnState;
188  }
189 
190  void setOwnState(int state) {
191  myOwnState = state;
192  }
193 
194  virtual void prepareStep() { }
195 
199  virtual int wantsChangeToRight(
200  MSLCMessager& msgPass, int blocked,
201  const std::pair<MSVehicle*, SUMOReal> &leader,
202  const std::pair<MSVehicle*, SUMOReal> &neighLead,
203  const std::pair<MSVehicle*, SUMOReal> &neighFollow,
204  const MSLane& neighLane,
205  const std::vector<MSVehicle::LaneQ> &preb,
206  MSVehicle** lastBlocked) = 0;
207 
211  virtual int wantsChangeToLeft(
212  MSLCMessager& msgPass, int blocked,
213  const std::pair<MSVehicle*, SUMOReal> &leader,
214  const std::pair<MSVehicle*, SUMOReal> &neighLead,
215  const std::pair<MSVehicle*, SUMOReal> &neighFollow,
216  const MSLane& neighLane,
217  const std::vector<MSVehicle::LaneQ> &preb,
218  MSVehicle** lastBlocked) = 0;
219 
220  virtual void* inform(void* info, MSVehicle* sender) = 0;
221 
233  virtual SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
234  const MSCFModel& cfModel) = 0;
235 
236  virtual void changed() = 0;
237 
238 #ifndef NO_TRACI
239 
246  myChangeRequest = request;
247  };
248 
256  if (request == myChangeRequest) {
258  }
259  }
260 #endif
261 
262 protected:
263  virtual bool congested(const MSVehicle* const neighLeader) {
264  if (neighLeader == 0) {
265  return false;
266  }
267  // Congested situation are relevant only on highways (maxSpeed > 70km/h)
268  // and congested on German Highways means that the vehicles have speeds
269  // below 60km/h. Overtaking on the right is allowed then.
270  if ((myVehicle.getLane()->getMaxSpeed() <= 70.0 / 3.6) || (neighLeader->getLane()->getMaxSpeed() <= 70.0 / 3.6)) {
271 
272  return false;
273  }
274  if (myVehicle.congested() && neighLeader->congested()) {
275  return true;
276  }
277  return false;
278  }
279 
280  virtual bool predInteraction(const MSVehicle* const leader) {
281  if (leader == 0) {
282  return false;
283  }
284  // let's check it on highways only
285  if (leader->getSpeed() < (80.0 / 3.6)) {
286  return false;
287  }
289  return gap < myCarFollowModel.interactionGap(&myVehicle, leader->getSpeed());
290  }
291 
292 
293 
294 protected:
297 
300 
301 
302 #ifndef NO_TRACI
304 #endif
305 
308 
309 };
310 
311 
312 #endif
313 
314 /****************************************************************************/
315