Eclipse SUMO - Simulation of Urban MObility
MSLaneChanger.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Performs lane changing of vehicles
18 /****************************************************************************/
19 #ifndef MSLaneChanger_h
20 #define MSLaneChanger_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include "MSLane.h"
29 #include "MSEdge.h"
30 #include "MSVehicle.h"
31 #include <vector>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
48 public:
50  MSLaneChanger(const std::vector<MSLane*>* lanes, bool allowChanging);
51 
53  virtual ~MSLaneChanger();
54 
56  void laneChange(SUMOTime t);
57 
58 public:
63  struct ChangeElem {
64 
65  ChangeElem(MSLane* _lane);
66 
68  void registerHop(MSVehicle* vehicle);
69 
80 
81  double dens;
82 
86 
89  std::vector<int> siblings;
90 
93  // the vehicles in from of the current vehicle (only on the current edge, continously updated during change() )
95 
96  // the vehicles in from of the current vehicle (including those on the next edge, contiously update during change() ))
99 
100  };
101 
102 public:
105  typedef std::vector< ChangeElem > Changer;
106 
108  typedef Changer::iterator ChangerIt;
109 
111  typedef Changer::const_iterator ConstChangerIt;
112 
113 protected:
115  virtual void initChanger();
116 
119  bool vehInChanger() const {
120  // If there is at least one valid vehicle under the veh's in myChanger
121  // return true.
122  for (ConstChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
123  if (veh(ce) != 0) {
124  return true;
125  }
126  }
127  return false;
128  }
129 
133  // If ce has a valid vehicle, return it. Otherwise return 0.
134  if (!ce->lane->myVehicles.empty()) {
135  return ce->lane->myVehicles.back();
136  } else {
137  return 0;
138  }
139  }
140 
141 
143  virtual bool change();
144 
145 
147  virtual bool changeOpposite(std::pair<MSVehicle*, double> leader);
148 
150  void registerUnchanged(MSVehicle* vehicle);
151 
154  void checkTraCICommands(MSVehicle* vehicle);
155 
159  bool applyTraCICommands(MSVehicle* vehicle);
160 
162  virtual void updateChanger(bool vehHasChanged);
163 
167  void updateLanes(SUMOTime t);
168 
172 
173  /* @brief check whether lane changing in the given direction is desirable
174  * and possible */
176  int laneOffset,
177  const std::pair<MSVehicle* const, double>& leader,
178  const std::vector<MSVehicle::LaneQ>& preb) const;
179 
180  /* @brief check whether lane changing in the given direction is desirable
181  * and possible */
182  int checkChange(
183  int laneOffset,
184  const MSLane* targetLane,
185  const std::pair<MSVehicle* const, double>& leader,
186  const std::pair<MSVehicle* const, double>& neighLead,
187  const std::pair<MSVehicle* const, double>& neighFollow,
188  const std::vector<MSVehicle::LaneQ>& preb) const;
189 
190  /* @brief start the lane change maneuver (and finish it instantly if gLaneChangeDuration == 0)
191  * @return False when aborting the change due to being remote controlled*/
192  bool startChange(MSVehicle* vehicle, ChangerIt& from, int direction);
193 
195  bool continueChange(MSVehicle* vehicle, ChangerIt& from);
196 
197  std::pair<MSVehicle* const, double> getRealFollower(const ChangerIt& target) const;
198 
199  std::pair<MSVehicle* const, double> getRealLeader(const ChangerIt& target) const;
200 
202  bool mayChange(int direction) const;
203 
205  static MSVehicle* getCloserFollower(const double maxPos, MSVehicle* follow1, MSVehicle* follow2);
206 
214  static void computeOvertakingTime(const MSVehicle* vehicle, const MSVehicle* leader, double gap, double& timeToOvertake, double& spaceToOvertake);
215 
216  // @brief return leader vehicle that is to be overtaken
217  static std::pair<MSVehicle*, double> getColumnleader(MSVehicle* vehicle, std::pair<MSVehicle*, double> leader, double maxLookAhead = std::numeric_limits<double>::max());
218 
220  static MSLane* getLaneAfter(MSLane* lane, const std::vector<MSLane*>& conts);
221 
222 protected:
225 
230 
231  /* @brief Whether vehicles may start to change lanes on this edge
232  * (finishing a change in progress is always permitted) */
233  const bool myAllowsChanging;
234 
236  const bool myChangeToOpposite;
237 
238 private:
240  MSLaneChanger();
241 
244 
247 };
248 
249 
250 #endif
251 
252 /****************************************************************************/
253 
MSLaneChanger::veh
MSVehicle * veh(ConstChangerIt ce) const
Definition: MSLaneChanger.h:132
MSLaneChanger::myChangeToOpposite
const bool myChangeToOpposite
whether this edge allows changing to the opposite direction edge
Definition: MSLaneChanger.h:236
MSLaneChanger::ChangeElem::registerHop
void registerHop(MSVehicle *vehicle)
Register that vehicle belongs to Changer Item to after LC decisions.
Definition: MSLaneChanger.cpp:81
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSLaneChanger::ChangeElem::lastBlocked
MSVehicle * lastBlocked
the next vehicle downstream of the ego vehicle that is blocked from changing to this lane
Definition: MSLaneChanger.h:77
MSLaneChanger::initChanger
virtual void initChanger()
Initialize the changer before looping over all vehicles.
Definition: MSLaneChanger.cpp:143
MSLaneChanger
Performs lane changing of vehicles.
Definition: MSLaneChanger.h:47
MSLeaderDistanceInfo
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:132
MSLaneChanger::mayChange
bool mayChange(int direction) const
whether changing to the lane in the given direction should be considered
Definition: MSLaneChanger.cpp:234
MSLaneChanger::ChangeElem::mayChangeRight
bool mayChangeRight
whether changing is possible to either direction
Definition: MSLaneChanger.h:84
MSLaneChanger::changeOpposite
virtual bool changeOpposite(std::pair< MSVehicle *, double > leader)
Definition: MSLaneChanger.cpp:1019
MSLaneChanger::myAllowsChanging
const bool myAllowsChanging
Definition: MSLaneChanger.h:233
MSLaneChanger::getColumnleader
static std::pair< MSVehicle *, double > getColumnleader(MSVehicle *vehicle, std::pair< MSVehicle *, double > leader, double maxLookAhead=std::numeric_limits< double >::max())
Definition: MSLaneChanger.cpp:1454
MSLaneChanger::ChangeElem
Definition: MSLaneChanger.h:63
MSLaneChanger::getCloserFollower
static MSVehicle * getCloserFollower(const double maxPos, MSVehicle *follow1, MSVehicle *follow2)
return the closer follower of ego
Definition: MSLaneChanger.cpp:669
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSLaneChanger::continueChange
bool continueChange(MSVehicle *vehicle, ChangerIt &from)
continue a lane change maneuver and return whether the vehicle has completely moved onto the new lane...
Definition: MSLaneChanger.cpp:440
MSLaneChanger::applyTraCICommands
bool applyTraCICommands(MSVehicle *vehicle)
Execute TraCI LC-commands.
Definition: MSLaneChanger.cpp:398
MSEdge.h
MSVehicle.h
MSLaneChanger::startChange
bool startChange(MSVehicle *vehicle, ChangerIt &from, int direction)
Definition: MSLaneChanger.cpp:420
MSLaneChanger::ChangeElem::hoppedVeh
MSVehicle * hoppedVeh
last vehicle that changed into this lane
Definition: MSLaneChanger.h:75
MSLaneChanger::getRealLeader
std::pair< MSVehicle *const, double > getRealLeader(const ChangerIt &target) const
Definition: MSLaneChanger.cpp:498
MSLeaderInfo
Definition: MSLeaderInfo.h:49
MSLaneChanger::vehInChanger
bool vehInChanger() const
Check if there is a single change-candidate in the changer. Returns true if there is one.
Definition: MSLaneChanger.h:119
MSLaneChanger::getLaneAfter
static MSLane * getLaneAfter(MSLane *lane, const std::vector< MSLane * > &conts)
return the next lane in conts beyond lane or nullptr
Definition: MSLaneChanger.cpp:1590
MSLaneChanger::checkTraCICommands
void checkTraCICommands(MSVehicle *vehicle)
Take into account traci LC-commands.
Definition: MSLaneChanger.cpp:377
MSLaneChanger::findCandidate
ChangerIt findCandidate()
Find current candidate. If there is none, myChanger.end() is returned.
Definition: MSLaneChanger.cpp:195
MSLaneChanger::checkChangeWithinEdge
int checkChangeWithinEdge(int laneOffset, const std::pair< MSVehicle *const, double > &leader, const std::vector< MSVehicle::LaneQ > &preb) const
Definition: MSLaneChanger.cpp:684
OutputDevice.h
MSLaneChanger::MSLaneChanger
MSLaneChanger()
Default constructor.
MSLaneChanger::operator=
MSLaneChanger & operator=(const MSLaneChanger &)
Assignment operator.
MSLaneChanger::ChangeElem::dens
double dens
Definition: MSLaneChanger.h:81
MSLaneChanger::change
virtual bool change()
Definition: MSLaneChanger.cpp:252
MSLaneChanger::ChangeElem::ahead
MSLeaderInfo ahead
Definition: MSLaneChanger.h:94
MSLaneChanger::ChangeElem::firstBlocked
MSVehicle * firstBlocked
the farthest downstream vehicle on this edge that is blocked from changing to this lane
Definition: MSLaneChanger.h:79
MSLaneChanger::~MSLaneChanger
virtual ~MSLaneChanger()
Destructor.
Definition: MSLaneChanger.cpp:115
MSLaneChanger::updateChanger
virtual void updateChanger(bool vehHasChanged)
Definition: MSLaneChanger.cpp:159
MSLaneChanger::ChangeElem::lane
MSLane * lane
the lane corresponding to this ChangeElem (the current change candidate is on this lane)
Definition: MSLaneChanger.h:73
MSLaneChanger::Changer
std::vector< ChangeElem > Changer
The list of changers; For each lane, a ChangeElem is being build.
Definition: MSLaneChanger.h:105
MSLaneChanger::ConstChangerIt
Changer::const_iterator ConstChangerIt
the iterator moving over the ChangeElems
Definition: MSLaneChanger.h:111
MSLaneChanger::myChanger
Changer myChanger
Container for ChangeElemements, one for every lane in the edge.
Definition: MSLaneChanger.h:224
MSLaneChanger::getRealFollower
std::pair< MSVehicle *const, double > getRealFollower(const ChangerIt &target) const
Definition: MSLaneChanger.cpp:596
MSLaneChanger::registerUnchanged
void registerUnchanged(MSVehicle *vehicle)
Definition: MSLaneChanger.cpp:367
MSLaneChanger::ChangeElem::aheadNext
MSLeaderDistanceInfo aheadNext
Definition: MSLaneChanger.h:97
MSLaneChanger::computeOvertakingTime
static void computeOvertakingTime(const MSVehicle *vehicle, const MSVehicle *leader, double gap, double &timeToOvertake, double &spaceToOvertake)
Compute the time and space required for overtaking the given leader.
Definition: MSLaneChanger.cpp:1349
MSLaneChanger::ChangerIt
Changer::iterator ChangerIt
the iterator moving over the ChangeElems
Definition: MSLaneChanger.h:108
MSLaneChanger::ChangeElem::ChangeElem
ChangeElem(MSLane *_lane)
Definition: MSLaneChanger.cpp:70
MSLaneChanger::updateLanes
void updateLanes(SUMOTime t)
Definition: MSLaneChanger.cpp:177
MSLaneChanger::myCandi
ChangerIt myCandi
Definition: MSLaneChanger.h:229
config.h
MSLaneChanger::ChangeElem::lead
MSVehicle * lead
the leader vehicle for the current change candidate
Definition: MSLaneChanger.h:71
MSLane.h
MSLaneChanger::ChangeElem::siblings
std::vector< int > siblings
Definition: MSLaneChanger.h:89
MSLaneChanger::laneChange
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge'e lanes.
Definition: MSLaneChanger.cpp:120
MSLaneChanger::ChangeElem::mayChangeLeft
bool mayChangeLeft
Definition: MSLaneChanger.h:85
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
MSLaneChanger::checkChange
int checkChange(int laneOffset, const MSLane *targetLane, const std::pair< MSVehicle *const, double > &leader, const std::pair< MSVehicle *const, double > &neighLead, const std::pair< MSVehicle *const, double > &neighFollow, const std::vector< MSVehicle::LaneQ > &preb) const
Definition: MSLaneChanger.cpp:701