SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSAbstractLaneChangeModel.cpp
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 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
35 #include "MSLCM_DK2008.h"
36 #include "MSLCM_LC2013.h"
37 #include "MSLCM_JE2013.h"
38 #include "MSNet.h"
39 #include "MSEdge.h"
40 #include "MSLane.h"
41 #include "MSGlobals.h"
42 
43 /* -------------------------------------------------------------------------
44  * MSAbstractLaneChangeModel-methods
45  * ----------------------------------------------------------------------- */
46 
49  switch (lcm) {
50  case LCM_DK2008:
51  return new MSLCM_DK2008(v);
52  case LCM_LC2013:
53  return new MSLCM_LC2013(v);
54  case LCM_JE2013:
55  return new MSLCM_JE2013(v);
56  default:
57  throw ProcessError("Lane change model '" + toString(lcm) + "' not implemented");
58  }
59 }
60 
61 
63  myVehicle(v),
64  myOwnState(0),
65  myLastLaneChangeOffset(0),
66  myLaneChangeCompletion(1.0),
67  myLaneChangeDirection(0),
68  myLaneChangeMidpointPassed(false),
69  myAlreadyMoved(false),
70  myShadowLane(0),
71  myHaveShadow(false),
72  myCarFollowModel(v.getCarFollowModel()) {
73 }
74 
75 
77  if (myShadowLane != 0 && myHaveShadow) {
79  }
80 }
81 
82 
83 bool
85  if (neighLeader == 0) {
86  return false;
87  }
88  // Congested situation are relevant only on highways (maxSpeed > 70km/h)
89  // and congested on German Highways means that the vehicles have speeds
90  // below 60km/h. Overtaking on the right is allowed then.
91  if ((myVehicle.getLane()->getSpeedLimit() <= 70.0 / 3.6) || (neighLeader->getLane()->getSpeedLimit() <= 70.0 / 3.6)) {
92 
93  return false;
94  }
95  if (myVehicle.congested() && neighLeader->congested()) {
96  return true;
97  }
98  return false;
99 }
100 
101 
102 bool
104  if (leader == 0) {
105  return false;
106  }
107  // let's check it on highways only
108  if (leader->getSpeed() < (80.0 / 3.6)) {
109  return false;
110  }
112  return gap < myCarFollowModel.interactionGap(&myVehicle, leader->getSpeed());
113 }
114 
115 
116 bool
118  target->enteredByLaneChange(&myVehicle);
121  myShadowLane = target;
122  myHaveShadow = true;
124  myLaneChangeDirection = direction;
126  return true;
127  } else {
129  source->leftByLaneChange(&myVehicle);
132  changed();
133  return false;
134  }
135 }
136 
137 
138 void
140  if (moved && myHaveShadow) {
141  // move shadow to next lane
144  myShadowLane = myVehicle.getLane()->getParallelLane(shadowDirection);
145  if (myShadowLane == 0) {
146  // abort lane change
147  WRITE_WARNING("Vehicle '" + myVehicle.getID() + "' could not finish continuous lane change (lane disappeared) time=" +
148  time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
150  return;
151  }
152  myHaveShadow = true;
153  }
157  // maneuver midpoint reached, swap myLane and myShadowLane
159  MSLane* tmp = myVehicle.getLane();
162  myShadowLane = tmp;
163  if (myVehicle.fixPosition()) {
164  WRITE_WARNING("vehicle '" + myVehicle.getID() + "' set back by " + toString(myVehicle.getPositionOnLane() - myVehicle.getLane()->getLength()) +
165  "m when changing lanes on lane '" + myVehicle.getLane()->getID() + " time=" +
166  time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
167  }
169  changed();
170  myAlreadyMoved = true;
171  }
172  // remove shadow as soon as the vehicle leaves the original lane geometrically
174  const SUMOReal sourceHalfWidth = myShadowLane->getWidth() / 2.0;
175  const SUMOReal targetHalfWidth = myVehicle.getLane()->getWidth() / 2.0;
176  if (myLaneChangeCompletion * (sourceHalfWidth + targetHalfWidth) - myVehicle.getVehicleType().getWidth() / 2.0 > sourceHalfWidth) {
178  }
179  }
180  // finish maneuver
181  if (!isChangingLanes()) {
184  }
185 }
186 
187 
188 void
190  if (myShadowLane != 0 && myHaveShadow) {
192  myHaveShadow = false;
193  }
194 }
MSAbstractLaneChangeModel(MSVehicle &v)
Constructor.
bool myHaveShadow
Wether a vehicle shadow exists.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
bool congested() const
Definition: MSVehicle.h:396
SUMOReal getLength() const
Returns the lane's length.
Definition: MSLane.h:370
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
SUMOReal getLength() const
Get vehicle's length [m].
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition: MSLane.cpp:1011
SUMOReal getWidth() const
Returns the lane's width.
Definition: MSLane.h:386
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:154
The vehicle got vaporized.
void leftByLaneChange(MSVehicle *v)
Definition: MSLane.cpp:1252
virtual bool predInteraction(const MSVehicle *const leader)
MSLane * myShadowLane
The lane the vehicle shadow is on during a continuous lane change.
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:283
void enterLaneAtLaneChange(MSLane *enteredLane)
Update when the vehicle enters a new lane in the laneChange step.
Definition: MSVehicle.cpp:1625
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:196
A lane change model developed by J. Erdmann.
Definition: MSLCM_JE2013.h:45
const std::string & getID() const
Returns the id.
Definition: Named.h:60
LaneChangeModel
The vehicle changes lanes (micro only)
A lane change model developed by D. Krajzewicz, J. Erdmann et al. between 2004 and 2013...
Definition: MSLCM_LC2013.h:49
void removeLaneChangeShadow()
remove the shadow copy of a lane change maneuver
virtual SUMOReal interactionGap(const MSVehicle *const veh, SUMOReal vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
Definition: MSCFModel.cpp:71
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
bool myLaneChangeMidpointPassed
whether myLane has already been set to the target of the lane-change maneuver
void enteredByLaneChange(MSVehicle *v)
Definition: MSLane.cpp:1259
MSLane * getParallelLane(int offset) const
Returns the lane with the given offset parallel to this one or 0 if it does not exist.
Definition: MSLane.cpp:1028
SUMOReal getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition: MSLane.h:362
int myLaneChangeDirection
direction of the lane change maneuver -1 means right, 1 means left
virtual void changed()=0
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:52
bool myAlreadyMoved
whether the vehicle has already moved this step
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:1709
SUMOReal getWidth() const
Get the width which vehicles of this class shall have when being drawn.
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
SUMOTime myLastLaneChangeOffset
information how long ago the vehicle has performed a lane-change
bool fixPosition()
repair errors in vehicle position after changing between internal edges
Definition: MSVehicle.cpp:2063
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:94
SUMOReal getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:291
A lane change model developed by D. Krajzewicz between 2004 and 2010.
Definition: MSLCM_DK2008.h:46
#define SUMOReal
Definition: config.h:215
#define DELTA_T
Definition: SUMOTime.h:50
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:328
SUMOReal myLaneChangeCompletion
progress of the lane change maneuver 0:started, 1:complete
static SUMOTime gLaneChangeDuration
Definition: MSGlobals.h:82
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.
Interface for lane-change models.
const std::string & getID() const
Returns the name of the vehicle.
virtual bool congested(const MSVehicle *const neighLeader)
virtual ~MSAbstractLaneChangeModel()
Destructor.