SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSLaneChanger.cpp
Go to the documentation of this file.
1 /****************************************************************************/
12 // Performs lane changing of vehicles
13 /****************************************************************************/
14 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
15 // Copyright (C) 2002-2015 DLR (http://www.dlr.de/) and contributors
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include "MSLaneChanger.h"
36 #include "MSNet.h"
37 #include "MSVehicle.h"
38 #include "MSVehicleType.h"
39 #include "MSVehicleTransfer.h"
40 #include "MSGlobals.h"
41 #include <cassert>
42 #include <iterator>
43 #include <cstdlib>
44 #include <cmath>
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 //#define DEBUG_VEHICLE_GUI_SELECTION 1
53 #ifdef DEBUG_VEHICLE_GUI_SELECTION
55 #include <guisim/GUIVehicle.h>
56 #include <guisim/GUILane.h>
57 #endif
58 
59 
60 // ===========================================================================
61 // member method definitions
62 // ===========================================================================
63 MSLaneChanger::MSLaneChanger(const std::vector<MSLane*>* lanes, bool allowSwap)
64  : myAllowsSwap(allowSwap) {
65  assert(lanes->size() > 1);
66 
67  // Fill the changer with the lane-data.
68  myChanger.reserve(lanes->size());
69  for (std::vector<MSLane*>::const_iterator lane = lanes->begin(); lane != lanes->end(); ++lane) {
70  ChangeElem ce;
71  ce.follow = 0;
72  ce.lead = 0;
73  ce.lane = *lane;
74  ce.veh = (*lane)->myVehicles.rbegin();
75  ce.hoppedVeh = 0;
76  ce.lastBlocked = 0;
77  ce.firstBlocked = 0;
78  myChanger.push_back(ce);
79  }
80 }
81 
82 
84 
85 
86 void
88  // This is what happens in one timestep. After initialization of the
89  // changer, each vehicle will try to change. After that the changer
90  // nedds an update to prevent multiple changes of one vehicle.
91  // Finally, the change-result has to be given back to the lanes.
92  initChanger();
93  while (vehInChanger()) {
94  bool haveChanged = change();
95  updateChanger(haveChanged);
96  }
97  updateLanes(t);
98 }
99 
100 
101 void
103  // Prepare myChanger with a safe state.
104  for (ChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
105  ce->lead = 0;
106  ce->hoppedVeh = 0;
107  ce->lastBlocked = 0;
108  ce->firstBlocked = 0;
109  ce->dens = 0;
110 
111  MSLane::VehCont& vehicles = ce->lane->myVehicles;
112  if (vehicles.empty()) {
113  ce->veh = vehicles.rend();
114  ce->follow = 0;
115  continue;
116  }
117  ce->veh = vehicles.rbegin();
118  if (vehicles.size() == 1) {
119  ce->follow = 0;
120  continue;
121  }
122  ce->follow = *(vehicles.rbegin() + 1);
123  }
124 }
125 
126 
127 bool
129  // Find change-candidate. If it is on an allowed lane, try to change
130  // to the right (there is a rule in Germany that you have to change
131  // to the right, unless you are overtaking). If change to the right
132  // isn't possible, check if there is a possibility to overtake (on the
133  // left.
134  // If candidate isn't on an allowed lane, changing to an allowed has
135  // priority.
137  MSVehicle* vehicle = veh(myCandi);
138 #ifdef DEBUG_VEHICLE_GUI_SELECTION
139  if (gSelected.isSelected(GLO_VEHICLE, static_cast<const GUIVehicle*>(vehicle)->getGlID())) {
140  int bla = 0;
141  }
142 #endif
143  if (vehicle->getLane() != (*myCandi).lane || vehicle->getLaneChangeModel().isChangingLanes()) {
144  // vehicles shadows and changing vehicles are not eligible
145  registerUnchanged(vehicle);
146  return false;
147  }
148 #ifndef NO_TRACI
149  if (vehicle->hasInfluencer() && vehicle->getInfluencer().isVTDControlled()) {
150  return false; // !!! temporary; just because it broke, here
151  }
152 #endif
153  vehicle->updateBestLanes(); // needed?
154  for (int i = 0; i < (int) myChanger.size(); ++i) {
155  vehicle->adaptBestLanesOccupation(i, myChanger[i].dens);
156  }
157  const std::vector<MSVehicle::LaneQ>& preb = vehicle->getBestLanes();
158  std::pair<MSVehicle* const, SUMOReal> leader = getRealThisLeader(myCandi);
159  // check whether the vehicle wants and is able to change to right lane
160  int state1 = 0;
161  if (myCandi != myChanger.begin() && (myCandi - 1)->lane->allowsVehicleClass(veh(myCandi)->getVehicleType().getVehicleClass())) {
162  state1 = checkChange(-1, leader, preb);
163  bool changingAllowed1 = (state1 & LCA_BLOCKED) == 0;
164  // change if the vehicle wants to and is allowed to change
165  if ((state1 & LCA_RIGHT) != 0 && changingAllowed1) {
166  startChange(vehicle, myCandi, -1);
167  return true;
168  }
169  if ((state1 & LCA_RIGHT) != 0 && (state1 & LCA_URGENT) != 0) {
170  (myCandi - 1)->lastBlocked = vehicle;
171  if ((myCandi - 1)->firstBlocked == 0) {
172  (myCandi - 1)->firstBlocked = vehicle;
173  }
174  }
175  }
176 
177 
178 
179  // check whether the vehicle wants and is able to change to left lane
180  int state2 = 0;
181  if ((myCandi + 1) != myChanger.end() && (myCandi + 1)->lane->allowsVehicleClass(veh(myCandi)->getVehicleType().getVehicleClass())) {
182  state2 = checkChange(1, leader, preb);
183  bool changingAllowed2 = (state2 & LCA_BLOCKED) == 0;
184  // change if the vehicle wants to and is allowed to change
185  if ((state2 & LCA_LEFT) != 0 && changingAllowed2) {
186  startChange(vehicle, myCandi, 1);
187  return true;
188  }
189  if ((state2 & LCA_LEFT) != 0 && (state2 & LCA_URGENT) != 0) {
190  (myCandi + 1)->lastBlocked = vehicle;
191  if ((myCandi + 1)->firstBlocked == 0) {
192  (myCandi + 1)->firstBlocked = vehicle;
193  }
194  }
195  }
196 
197  if ((state1 & (LCA_URGENT)) != 0 && (state2 & (LCA_URGENT)) != 0) {
198  // ... wants to go to the left AND to the right
199  // just let them go to the right lane...
200  state2 = 0;
201  }
202  vehicle->getLaneChangeModel().setOwnState(state2 | state1);
203 
204  // check whether the vehicles should be swapped
205  if (myAllowsSwap && ((state1 & (LCA_URGENT)) != 0 || (state2 & (LCA_URGENT)) != 0)) {
206  // get the direction ...
207  ChangerIt target;
208  int direction = 0;
209  if ((state1 & (LCA_URGENT)) != 0) {
210  // ... wants to go right
211  target = myCandi - 1;
212  direction = -1;
213  }
214  if ((state2 & (LCA_URGENT)) != 0) {
215  // ... wants to go left
216  target = myCandi + 1;
217  direction = 1;
218  }
219  MSVehicle* prohibitor = target->lead;
220  if (target->hoppedVeh != 0) {
221  SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
222  if (prohibitor == 0 || (hoppedPos > vehicle->getPositionOnLane() && prohibitor->getPositionOnLane() > hoppedPos)) {
223  prohibitor = 0;// !!! vehicles should not jump over more than one lanetarget->hoppedVeh;
224  }
225  }
226  if (prohibitor != 0
227  &&
228  ((prohibitor->getLaneChangeModel().getOwnState() & (LCA_URGENT/*|LCA_SPEEDGAIN*/)) != 0
229  &&
230  (prohibitor->getLaneChangeModel().getOwnState() & (LCA_LEFT | LCA_RIGHT))
231  !=
232  (vehicle->getLaneChangeModel().getOwnState() & (LCA_LEFT | LCA_RIGHT))
233  )
234  ) {
235 
236  // check for position and speed
237  if (prohibitor->getVehicleType().getLengthWithGap() - vehicle->getVehicleType().getLengthWithGap() == 0) {
238  // ok, may be swapped
239  // remove vehicle to swap with
240  MSLane::VehCont::iterator i = find(target->lane->myTmpVehicles.begin(), target->lane->myTmpVehicles.end(), prohibitor);
241  if (i != target->lane->myTmpVehicles.end()) {
242  assert(*i == prohibitor);
243  target->lane->myTmpVehicles.erase(i);
244  // set this vehicle
245  target->hoppedVeh = vehicle;
246  target->lane->myTmpVehicles.insert(target->lane->myTmpVehicles.begin(), vehicle);
247  myCandi->hoppedVeh = prohibitor;
248  myCandi->lane->myTmpVehicles.insert(myCandi->lane->myTmpVehicles.begin(), prohibitor);
249 
250  // leave lane and detectors
253  // patch position and speed
254  SUMOReal p1 = vehicle->getPositionOnLane();
255  vehicle->myState.myPos = prohibitor->myState.myPos;
256  prohibitor->myState.myPos = p1;
257  p1 = vehicle->getSpeed();
258  vehicle->myState.mySpeed = prohibitor->myState.mySpeed;
259  prohibitor->myState.mySpeed = p1;
260  // enter lane and detectors
261  vehicle->enterLaneAtLaneChange(target->lane);
262  prohibitor->enterLaneAtLaneChange(myCandi->lane);
263  // mark lane change
264  vehicle->getLaneChangeModel().changed(direction);
265  prohibitor->getLaneChangeModel().changed(-direction);
266  (myCandi)->dens += prohibitor->getVehicleType().getLengthWithGap();
267  (target)->dens += vehicle->getVehicleType().getLengthWithGap();
268  return true;
269  }
270  }
271  }
272  }
273  registerUnchanged(vehicle);
274  return false;
275 }
276 
277 
278 void
280  myCandi->lane->myTmpVehicles.insert(myCandi->lane->myTmpVehicles.begin(), veh(myCandi));
281  vehicle->getLaneChangeModel().unchanged();
282  (myCandi)->dens += vehicle->getVehicleType().getLengthWithGap();
283 }
284 
285 
286 void
287 MSLaneChanger::startChange(MSVehicle* vehicle, ChangerIt& from, int direction) {
288  ChangerIt to = from + direction;
289  to->hoppedVeh = vehicle;
290  // @todo delay entering the target lane until the vehicle intersects it
291  // physically (considering lane width and vehicle width)
292  to->lane->myTmpVehicles.insert(to->lane->myTmpVehicles.begin(), vehicle);
293  const bool continuous = vehicle->getLaneChangeModel().startLaneChangeManeuver(from->lane, to->lane, direction);
294  if (continuous) {
295  from->lane->myTmpVehicles.insert(from->lane->myTmpVehicles.begin(), vehicle);
296  from->dens += vehicle->getVehicleType().getLengthWithGap();
297  }
298  to->dens += to->hoppedVeh->getVehicleType().getLengthWithGap();
299 }
300 
301 
302 std::pair<MSVehicle* const, SUMOReal>
304  // get the leading vehicle on the lane to change to
305  MSVehicle* leader = target->lead;
306  if (leader == 0) {
307  MSLane* targetLane = target->lane;
308  MSVehicle* predP = targetLane->getPartialOccupator();
309  if (predP != 0) {
310  return std::pair<MSVehicle*, SUMOReal>(predP, targetLane->getPartialOccupatorEnd() - veh(myCandi)->getPositionOnLane());
311  }
312  const std::vector<MSLane*>& bestLaneConts = veh(myCandi)->getBestLanesContinuation();
313  MSLinkCont::const_iterator link = MSLane::succLinkSec(*veh(myCandi), 1, *targetLane, bestLaneConts);
314  if (targetLane->isLinkEnd(link)) {
315  return std::pair<MSVehicle*, SUMOReal>(static_cast<MSVehicle*>(0), -1);
316  }
317  MSLane* nextLane = (*link)->getLane();
318  if (nextLane == 0) {
319  return std::pair<MSVehicle*, SUMOReal>(static_cast<MSVehicle*>(0), -1);
320  }
321  leader = nextLane->getLastVehicle();
322  if (leader == 0) {
323  return std::pair<MSVehicle*, SUMOReal>(static_cast<MSVehicle*>(0), -1);
324  }
325  SUMOReal gap =
326  leader->getPositionOnLane() - leader->getVehicleType().getLength()
327  +
328  (myCandi->lane->getLength() - veh(myCandi)->getPositionOnLane() - veh(myCandi)->getVehicleType().getMinGap()); // !!! recheck
329  return std::pair<MSVehicle* const, SUMOReal>(leader, MAX2((SUMOReal) 0, gap));
330  } else {
331  MSVehicle* candi = veh(myCandi);
332  SUMOReal gap = leader->getPositionOnLane() - leader->getVehicleType().getLength() - candi->getPositionOnLane() - candi->getVehicleType().getMinGap();
333  return std::pair<MSVehicle* const, SUMOReal>(leader, MAX2((SUMOReal) 0, gap));
334  }
335 }
336 
337 
338 std::pair<MSVehicle* const, SUMOReal>
340  // get the leading vehicle on the lane to change to
341  MSVehicle* neighLead = target->lead;
342  // check whether the hopped vehicle became the leader
343  if (target->hoppedVeh != 0) {
344  SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
345  if (hoppedPos > veh(myCandi)->getPositionOnLane() && (neighLead == 0 || neighLead->getPositionOnLane() > hoppedPos)) {
346  neighLead = target->hoppedVeh;
347  }
348  }
349  if (neighLead == 0) {
350  MSLane* targetLane = target->lane;
351  MSVehicle* predP = targetLane->getPartialOccupator();
352  if (predP != 0) {
353  return std::pair<MSVehicle*, SUMOReal>(predP, targetLane->getPartialOccupatorEnd() - veh(myCandi)->getPositionOnLane() - veh(myCandi)->getVehicleType().getMinGap());
354  }
355  SUMOReal seen = myCandi->lane->getLength() - veh(myCandi)->getPositionOnLane();
356  SUMOReal speed = veh(myCandi)->getSpeed();
358  if (seen > dist) {
359  return std::pair<MSVehicle* const, SUMOReal>(static_cast<MSVehicle*>(0), -1);
360  }
361  const std::vector<MSLane*>& bestLaneConts = veh(myCandi)->getBestLanesContinuation(targetLane);
362  return target->lane->getLeaderOnConsecutive(dist, seen, speed, *veh(myCandi), bestLaneConts);
363  } else {
364  MSVehicle* candi = veh(myCandi);
365  return std::pair<MSVehicle* const, SUMOReal>(neighLead, neighLead->getPositionOnLane() - neighLead->getVehicleType().getLength() - candi->getPositionOnLane() - candi->getVehicleType().getMinGap());
366  }
367 }
368 
369 
370 std::pair<MSVehicle* const, SUMOReal>
372  MSVehicle* neighFollow = veh(target);
373  // check whether the hopped vehicle became the follower
374  if (target->hoppedVeh != 0) {
375  SUMOReal hoppedPos = target->hoppedVeh->getPositionOnLane();
376  if (hoppedPos <= veh(myCandi)->getPositionOnLane() && (neighFollow == 0 || neighFollow->getPositionOnLane() < hoppedPos)) {
377  neighFollow = target->hoppedVeh;
378  }
379  }
380  if (neighFollow == 0) {
381  MSVehicle* candi = veh(myCandi);
382  return target->lane->getFollowerOnConsecutive(
383  candi->getPositionOnLane() - candi->getVehicleType().getLength(),
384  candi->getSpeed(), candi->getCarFollowModel().getMaxDecel());
385  } else {
386  MSVehicle* candi = veh(myCandi);
387  return std::pair<MSVehicle* const, SUMOReal>(neighFollow,
388  candi->getPositionOnLane() - candi->getVehicleType().getLength() - neighFollow->getPositionOnLane() - neighFollow->getVehicleType().getMinGap());
389  }
390 }
391 
392 
393 
394 
395 void
396 MSLaneChanger::updateChanger(bool vehHasChanged) {
397  assert(myCandi->veh != myCandi->lane->myVehicles.rend());
398 
399  // "Push" the vehicles to the back, i.e. follower becomes vehicle,
400  // vehicle becomes leader, and leader becomes predecessor of vehicle,
401  // if it exists.
402  if (!vehHasChanged) {
403  myCandi->lead = veh(myCandi);
404  }
405  myCandi->veh = myCandi->veh + 1;
406 
407  if (veh(myCandi) == 0) {
408  assert(myCandi->follow == 0);
409  // leader already 0.
410  return;
411  }
412  if (myCandi->veh + 1 == myCandi->lane->myVehicles.rend()) {
413  myCandi->follow = 0;
414  } else {
415  myCandi->follow = *(myCandi->veh + 1);
416  }
417  return;
418 }
419 
420 
421 void
423 
424  // Update the lane's vehicle-container.
425  // First: it is bad style to change other classes members, but for
426  // this release, other attempts were too time-consuming. In a next
427  // release we will change from this lane-centered design to a vehicle-
428  // centered. This will solve many problems.
429  // Second: this swap would be faster if vehicle-containers would have
430  // been pointers, but then I had to change too much of the MSLane code.
431  for (ChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
432 
433  ce->lane->swapAfterLaneChange(t);
434  }
435 }
436 
437 
440  // Find the vehicle in myChanger with the smallest position. If there
441  // is no vehicle in myChanger (shouldn't happen) , return
442  // myChanger.end().
443  ChangerIt max = myChanger.end();
444  for (ChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
445  if (veh(ce) == 0) {
446  continue;
447  }
448  if (max == myChanger.end()) {
449  max = ce;
450  continue;
451  }
452  assert(veh(ce) != 0);
453  assert(veh(max) != 0);
454  if (veh(max)->getPositionOnLane() < veh(ce)->getPositionOnLane()) {
455  max = ce;
456  }
457  }
458  assert(max != myChanger.end());
459  assert(veh(max) != 0);
460  return max;
461 }
462 
463 int
465  int laneOffset,
466  const std::pair<MSVehicle* const, SUMOReal>& leader,
467  const std::vector<MSVehicle::LaneQ>& preb) const {
468  std::pair<MSVehicle* const, SUMOReal> neighLead = getRealLeader(myCandi + laneOffset);
469  std::pair<MSVehicle* const, SUMOReal> neighFollow = getRealFollower(myCandi + laneOffset);
470  MSVehicle* vehicle = veh(myCandi);
471  ChangerIt target = myCandi + laneOffset;
472  int blocked = 0;
473  int blockedByLeader = (laneOffset == -1 ? LCA_BLOCKED_BY_RIGHT_LEADER : LCA_BLOCKED_BY_LEFT_LEADER);
474  int blockedByFollower = (laneOffset == -1 ? LCA_BLOCKED_BY_RIGHT_FOLLOWER : LCA_BLOCKED_BY_LEFT_FOLLOWER);
475  // overlap
476  if (neighFollow.first != 0 && neighFollow.second < 0) {
477  blocked |= (blockedByFollower | LCA_OVERLAPPING);
478  }
479  if (neighLead.first != 0 && neighLead.second < 0) {
480  blocked |= (blockedByLeader | LCA_OVERLAPPING);
481  }
482  // safe back gap
483  if (neighFollow.first != 0) {
484  // !!! eigentlich: vsafe braucht die Max. Geschwindigkeit beider Spuren
485  if (neighFollow.second < neighFollow.first->getCarFollowModel().getSecureGap(neighFollow.first->getSpeed(), vehicle->getSpeed(), vehicle->getCarFollowModel().getMaxDecel())) {
486  blocked |= blockedByFollower;
487  }
488  }
489 
490  // safe front gap
491  if (neighLead.first != 0) {
492  // !!! eigentlich: vsafe braucht die Max. Geschwindigkeit beider Spuren
493  if (neighLead.second < vehicle->getCarFollowModel().getSecureGap(vehicle->getSpeed(), neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel())) {
494  blocked |= blockedByLeader;
495  }
496  }
497 
498  MSAbstractLaneChangeModel::MSLCMessager msg(leader.first, neighLead.first, neighFollow.first);
499  int state = blocked | vehicle->getLaneChangeModel().wantsChange(
500  laneOffset, msg, blocked, leader, neighLead, neighFollow, *(target->lane), preb, &(myCandi->lastBlocked), &(myCandi->firstBlocked));
501 
502  if (blocked == 0 && (state & LCA_WANTS_LANECHANGE) != 0 && neighLead.first != 0) {
503  // do are more carefull (but expensive) check to ensure that a
504  // safety-critical leader is not being overloocked
505  const SUMOReal seen = myCandi->lane->getLength() - vehicle->getPositionOnLane();
506  const SUMOReal speed = vehicle->getSpeed();
507  const SUMOReal dist = vehicle->getCarFollowModel().brakeGap(speed) + vehicle->getVehicleType().getMinGap();
508  const MSLane* targetLane = (myCandi + laneOffset)->lane;
509  if (seen < dist) {
510  std::pair<MSVehicle* const, SUMOReal> neighLead2 = targetLane->getCriticalLeader(dist, seen, speed, *vehicle);
511  if (neighLead2.first != 0 && neighLead2.first != neighLead.first
512  && (neighLead2.second < vehicle->getCarFollowModel().getSecureGap(
513  vehicle->getSpeed(), neighLead2.first->getSpeed(), neighLead2.first->getCarFollowModel().getMaxDecel()))) {
514  state |= blockedByLeader;
515  }
516  }
517  }
518 #ifndef NO_TRACI
519  // let TraCI influence the wish to change lanes and the security to take
520  //const int oldstate = state;
521  state = vehicle->influenceChangeDecision(state);
522  //if (vehicle->getID() == "150_2_36000000") {
523  // std::cout << STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep()) << " veh=" << vehicle->getID() << " oldstate=" << oldstate << " newstate=" << state << "\n";
524  //}
525 #endif
526  return state;
527 }
528 
529 /****************************************************************************/
530 
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge'e lanes.
MSVehicle * firstBlocked
the first vehicle on this edge that wants to change to this lane
Definition: MSLaneChanger.h:85
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
bool isLinkEnd(MSLinkCont::const_iterator &i) const
Definition: MSLane.cpp:944
MSLane * lane
the lane the vehicle is on
Definition: MSLaneChanger.h:77
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition: MSVehicle.h:540
State myState
This Vehicles driving state (pos and speed)
Definition: MSVehicle.h:1152
a vehicles
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
std::pair< MSVehicle *const, SUMOReal > getRealLeader(const ChangerIt &target) const
bool hasInfluencer() const
Definition: MSVehicle.h:1087
SUMOReal getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
MSLane::VehCont::reverse_iterator veh
the regarded vehicle
Definition: MSLaneChanger.h:79
bool isVTDControlled() const
Definition: MSVehicle.h:1019
void initChanger()
Initialize the changer before looping over all vehicles.
std::vector< MSVehicle * > VehCont
Container for vehicles.
Definition: MSLane.h:88
SUMOReal getLength() const
Get vehicle's length [m].
T MAX2(T a, T b)
Definition: StdDefs.h:74
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
MSVehicle * veh(ConstChangerIt ce) const
SUMOReal getSecureGap(const SUMOReal speed, const SUMOReal leaderSpeed, const SUMOReal leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum.
Definition: MSCFModel.h:270
SUMOReal mySpeed
the stored speed
Definition: MSVehicle.h:120
void startChange(MSVehicle *vehicle, ChangerIt &from, int direction)
start the lane change maneuver (and finish it instantly if gLaneChangeDuration == 0) ...
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:286
std::pair< MSVehicle *const, SUMOReal > getCriticalLeader(SUMOReal dist, SUMOReal seen, SUMOReal speed, const MSVehicle &veh) const
Returns the most dangerous leader and the distance to him.
Definition: MSLane.cpp:1278
MSVehicle * lead
the vehicle in front of the current vehicle
Definition: MSLaneChanger.h:75
The action is urgent (to be defined by lc-model)
MSVehicle * follow
the vehicle following the current vehicle
Definition: MSLaneChanger.h:73
ChangerIt findCandidate()
Find current candidate. If there is none, myChanger.end() is returned.
void enterLaneAtLaneChange(MSLane *enteredLane)
Update when the vehicle enters a new lane in the laneChange step.
Definition: MSVehicle.cpp:1759
static MSLinkCont::const_iterator succLinkSec(const SUMOVehicle &veh, unsigned int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts)
Definition: MSLane.cpp:978
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:1884
SUMOReal getPartialOccupatorEnd() const
Returns the position of the in-lapping vehicle's end.
Definition: MSLane.h:261
A class responsible for exchanging messages between cars involved in lane-change interaction.
The vehicle changes lanes (micro only)
Wants go to the left.
#define max(a, b)
Definition: polyfonts.c:65
std::pair< MSVehicle *const, SUMOReal > getRealFollower(const ChangerIt &target) const
SUMOReal brakeGap(const SUMOReal speed) const
Returns the distance the vehicle needs to halt including driver's reaction time.
Definition: MSCFModel.h:232
void updateChanger(bool vehHasChanged)
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the subpart of best lanes that describes the vehicle's current lane and their successors...
Definition: MSVehicle.cpp:2168
void updateBestLanes(bool forceRebuild=false, const MSLane *startLane=0)
computes the best lanes to use in order to continue the route
Definition: MSVehicle.cpp:1902
The vehicle is blocked by left follower.
std::pair< MSVehicle *const, SUMOReal > getRealThisLeader(const ChangerIt &target) const
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
Definition: MSCFModel.h:184
MSVehicle * getLastVehicle() const
returns the last vehicle
Definition: MSLane.cpp:960
MSLaneChanger()
Default constructor.
int checkChange(int laneOffset, const std::pair< MSVehicle *const, SUMOReal > &leader, const std::vector< MSVehicle::LaneQ > &preb) const
void updateLanes(SUMOTime t)
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
Definition: MSVehicle.cpp:1896
Wants go to the right.
MSVehicle * lastBlocked
the vehicle that really wants to change to this lane
Definition: MSLaneChanger.h:83
bool startLaneChangeManeuver(MSLane *source, MSLane *target, int direction)
start the lane change maneuver and return whether it continues
void leaveLane(const MSMoveReminder::Notification reason)
Update of members if vehicle leaves a new lane in the lane change step or at arrival.
Definition: MSVehicle.cpp:1844
Influencer & getInfluencer()
Returns the velocity/lane influencer.
Definition: MSVehicle.cpp:2510
bool myAllowsSwap
Whether blocking vehicles may be swapped.
~MSLaneChanger()
Destructor.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:90
Changer::iterator ChangerIt
the iterator moving over the ChangeElems
Definition: MSLaneChanger.h:97
SUMOReal getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:294
int SUMOTime
Definition: SUMOTime.h:43
virtual void changed(int dir)=0
SUMOReal myPos
the stored position
Definition: MSVehicle.h:113
Changer myChanger
Container for ChangeElemements, one for every lane in the edge.
MSVehicle * getPartialOccupator() const
Returns the vehicle which laps into this lane.
Definition: MSLane.h:253
void registerUnchanged(MSVehicle *vehicle)
#define SUMOReal
Definition: config.h:218
The vehicle is blocked by right follower.
void adaptBestLanesOccupation(int laneIndex, SUMOReal density)
update occupation from MSLaneChanger
Definition: MSVehicle.cpp:2206
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...
The vehicle is blocked by left leader.
MSVehicle * hoppedVeh
last vehicle that changed into this lane
Definition: MSLaneChanger.h:81
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:331
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
Definition: MSVehicle.cpp:2528
bool vehInChanger() const
Check if there is a single change-candidate in the changer. Returns true if there is one...
GUISelectedStorage gSelected
A global holder of selected objects.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
The vehicle is blocked by right leader.
ChangerIt myCandi