SUMO - Simulation of Urban MObility
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.dlr.de/
14 // Copyright (C) 2001-2016 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 
36 #include "MSLCM_DK2008.h"
37 #include "MSLCM_LC2013.h"
38 #include "MSLCM_JE2013.h"
39 #include <microsim/MSNet.h>
40 #include <microsim/MSEdge.h>
41 #include <microsim/MSLane.h>
42 #include <microsim/MSGlobals.h>
43 
44 /* -------------------------------------------------------------------------
45  * static members
46  * ----------------------------------------------------------------------- */
48 
49 /* -------------------------------------------------------------------------
50  * MSAbstractLaneChangeModel-methods
51  * ----------------------------------------------------------------------- */
52 
53 void
55  myAllowOvertakingRight = oc.getBool("lanechange.overtake-right");
56 }
57 
58 
61  switch (lcm) {
62  case LCM_DK2008:
63  return new MSLCM_DK2008(v);
64  case LCM_LC2013:
65  return new MSLCM_LC2013(v);
66  case LCM_JE2013:
67  return new MSLCM_JE2013(v);
68  default:
69  throw ProcessError("Lane change model '" + toString(lcm) + "' not implemented");
70  }
71 }
72 
73 
75  myVehicle(v),
76  myOwnState(0),
80  myAlreadyMoved(false),
81  myShadowLane(0),
82  myHaveShadow(false),
83  myCarFollowModel(v.getCarFollowModel()),
85 }
86 
87 
89  if (myShadowLane != 0 && myHaveShadow) {
91  }
92 }
93 
94 
95 bool
97  if (neighLeader == 0) {
98  return false;
99  }
100  // Congested situation are relevant only on highways (maxSpeed > 70km/h)
101  // and congested on German Highways means that the vehicles have speeds
102  // below 60km/h. Overtaking on the right is allowed then.
103  if ((myVehicle.getLane()->getSpeedLimit() <= 70.0 / 3.6) || (neighLeader->getLane()->getSpeedLimit() <= 70.0 / 3.6)) {
104 
105  return false;
106  }
107  if (myVehicle.congested() && neighLeader->congested()) {
108  return true;
109  }
110  return false;
111 }
112 
113 
114 bool
116  if (leader == 0) {
117  return false;
118  }
119  // let's check it on highways only
120  if (leader->getSpeed() < (80.0 / 3.6)) {
121  return false;
122  }
124  return gap < myCarFollowModel.interactionGap(&myVehicle, leader->getSpeed());
125 }
126 
127 
128 bool
130  target->enteredByLaneChange(&myVehicle);
132  // initialize further lanes for shadow vehicle
133  // (must come before myLaneChangeCompletion is initialized)
134  const std::vector<MSLane*>& further = myVehicle.getFurtherLanes();
136  MSLane* lane = target;
137  for (int i = 0; i < (int)further.size(); i++) {
138  lane = lane->getLogicalPredecessorLane(further[i]->getEdge());
139  if (lane != 0) {
140  leftLength -= lane->setPartialOccupation(&myVehicle, leftLength);
142  } else {
143  break;
144  }
145  }
147  myShadowLane = target;
148  myHaveShadow = true;
150  myLaneChangeDirection = direction;
154  return true;
155  } else {
157  source->leftByLaneChange(&myVehicle);
159  changed(direction);
160  return false;
161  }
162 }
163 
164 
165 MSLane*
169  return lane->getParallelLane(shadowDirection);
170  } else {
171  return 0;
172  }
173 }
174 
175 
176 void
178  if (moved && myHaveShadow) {
179  // move shadow to next lane
182  if (myShadowLane == 0) {
183  // abort lane change
184  WRITE_WARNING("Vehicle '" + myVehicle.getID() + "' could not finish continuous lane change (lane disappeared) time=" +
185  time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
187  return;
188  }
189  myHaveShadow = true;
190  }
194  // maneuver midpoint reached, swap myLane and myShadowLane
196  MSLane* tmp = myVehicle.getLane();
197  // removing partial occupator shadows - will be rebuilt in enterLaneAtLaneChange
198  for (std::vector<MSLane*>::const_iterator it = myPartiallyOccupatedByShadow.begin(); it != myPartiallyOccupatedByShadow.end(); ++it) {
200  }
204  myShadowLane = tmp;
205  if (myVehicle.fixPosition()) {
206  WRITE_WARNING("Vehicle '" + myVehicle.getID() + "' set back by " + toString(myVehicle.getPositionOnLane() - myVehicle.getLane()->getLength()) +
207  "m when changing lanes on lane '" + myVehicle.getLane()->getID() + "' time=" +
208  time2string(MSNet::getInstance()->getCurrentTimeStep()) + ".");
209  }
211  myAlreadyMoved = true;
212  }
213  // remove shadow as soon as the vehicle leaves the original lane geometrically
215  const SUMOReal sourceHalfWidth = myShadowLane->getWidth() / 2.0;
216  const SUMOReal targetHalfWidth = myVehicle.getLane()->getWidth() / 2.0;
217  if (myLaneChangeCompletion * (sourceHalfWidth + targetHalfWidth) - myVehicle.getVehicleType().getWidth() / 2.0 > sourceHalfWidth) {
218  // removing partial occupator shadows - will be rebuilt in enterLaneAtLaneChange
219  for (std::vector<MSLane*>::const_iterator it = myPartiallyOccupatedByShadow.begin(); it != myPartiallyOccupatedByShadow.end(); ++it) {
220  (*it)->resetPartialOccupation(&myVehicle);
221  }
224  }
225  }
226  // finish maneuver
227  if (!isChangingLanes()) {
230  }
231 }
232 
233 
234 void
236  if (myShadowLane != 0 && myHaveShadow) {
237  myShadowLane->removeVehicle(&myVehicle, reason, notify);
238  myHaveShadow = false;
239  // maintain pointer to myShadowLane for interpolating position
240  }
241 }
242 
243 void
245  removeLaneChangeShadow(reason);
247  myShadowLane = 0;
248  // removing partial occupator shadows
249  for (std::vector<MSLane*>::const_iterator it = myPartiallyOccupatedByShadow.begin(); it != myPartiallyOccupatedByShadow.end(); ++it) {
251  }
254 }
255 
256 bool
258  int ret = myVehicle.influenceChangeDecision(state);
259  return ret != state;
260 }
261 
262 
263 void
265  if (dir > 0) {
267  } else if (dir < 0) {
269  }
270 }
MSAbstractLaneChangeModel(MSVehicle &v)
Constructor.
std::vector< MSLane * > myPartiallyOccupatedByShadow
list of lanes where the shadow vehicle is partial occupator
bool myHaveShadow
Wether a vehicle shadow exists.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
The vehicle arrived at a junction.
bool congested() const
Definition: MSVehicle.h:474
SUMOReal getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:375
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
SUMOReal getLength() const
Get vehicle&#39;s length [m].
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition: MSLane.cpp:974
SUMOReal getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:391
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
The vehicle got vaporized.
void leftByLaneChange(MSVehicle *v)
Definition: MSLane.cpp:1370
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&#39;s position along the lane.
Definition: MSVehicle.h:340
void enterLaneAtLaneChange(MSLane *enteredLane)
Update when the vehicle enters a new lane in the laneChange step.
Definition: MSVehicle.cpp:1914
SUMOReal setPartialOccupation(MSVehicle *v, SUMOReal leftVehicleLength)
Sets the information about a vehicle lapping into this lane.
Definition: MSLane.cpp:531
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
A lane change model developed by J. Erdmann.
Definition: MSLCM_JE2013.h:47
Right blinker lights are switched on.
Definition: MSVehicle.h:860
static bool myAllowOvertakingRight
whether overtaking on the right is permitted
const std::string & getID() const
Returns the id.
Definition: Named.h:65
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
Left blinker lights are switched on.
Definition: MSVehicle.h:862
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
Definition: MSLane.cpp:1308
bool cancelRequest(int state)
whether the influencer cancels the given request
std::vector< MSLane * > myNoPartiallyOccupatedByShadow
void resetPartialOccupation(MSVehicle *v)
Removes the information about a vehicle lapping into this lane.
Definition: MSLane.cpp:547
void setShadowPartialOccupator(MSLane *lane)
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:74
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:1377
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:991
SUMOReal getSpeedLimit() const
Returns the lane&#39;s maximum allowed speed.
Definition: MSLane.h:367
int myLaneChangeDirection
direction of the lane change maneuver -1 means right, 1 means left
static void initGlobalOptions(const OptionsCont &oc)
init global model parameters
MSLane * getShadowLane() const
Returns the lane the vehicles shadow is on during continuouss lane change.
int myOwnState
The current state of the vehicle.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
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:1982
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.
const std::vector< MSLane * > & getFurtherLanes() const
Definition: MSVehicle.h:531
bool fixPosition()
repair errors in vehicle position after changing between internal edges
Definition: MSVehicle.cpp:2386
A storage for options typed value containers)
Definition: OptionsCont.h:108
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
Definition: MSBaseVehicle.h:93
SUMOReal getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:348
virtual void changed(int dir)=0
A lane change model developed by D. Krajzewicz between 2004 and 2010.
Definition: MSLCM_DK2008.h:47
#define SUMOReal
Definition: config.h:213
void switchOffSignal(int signal)
Switches the given signal off.
Definition: MSVehicle.h:921
void switchOnSignal(int signal)
Switches the given signal on.
Definition: MSVehicle.h:913
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:385
SUMOReal myLaneChangeCompletion
progress of the lane change maneuver 0:started, 1:complete
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
Definition: MSVehicle.cpp:2844
void removeLaneChangeShadow(const MSMoveReminder::Notification reason, bool notify=true)
remove the shadow copy of a lane change maneuver
static SUMOTime gLaneChangeDuration
Definition: MSGlobals.h:81
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&#39;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)
void endLaneChangeManeuver(const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_LANE_CHANGE)
virtual ~MSAbstractLaneChangeModel()
Destructor.