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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // Performs lane changing of vehicles
22 /****************************************************************************/
23 #pragma once
24 #include <config.h>
25 
26 #include "MSLane.h"
27 #include "MSEdge.h"
28 #include "MSVehicle.h"
29 #include <vector>
31 
32 
33 // ===========================================================================
34 // class declarations
35 // ===========================================================================
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
46 public:
48  MSLaneChanger(const std::vector<MSLane*>* lanes, bool allowChanging);
49 
51  virtual ~MSLaneChanger();
52 
54  void laneChange(SUMOTime t);
55 
56 public:
61  struct ChangeElem {
62 
63  ChangeElem(MSLane* _lane);
64 
66  void registerHop(MSVehicle* vehicle);
67 
78 
79  double dens;
80 
84 
87  std::vector<int> siblings;
88 
91  // the vehicles in from of the current vehicle (only on the current edge, continously updated during change() )
93 
94  // the vehicles in from of the current vehicle (including those on the next edge, contiously update during change() ))
97 
98  };
99 
100 public:
103  typedef std::vector< ChangeElem > Changer;
104 
106  typedef Changer::iterator ChangerIt;
107 
109  typedef Changer::const_iterator ConstChangerIt;
110 
111 protected:
113  virtual void initChanger();
114 
117  bool vehInChanger() const {
118  // If there is at least one valid vehicle under the veh's in myChanger
119  // return true.
120  for (ConstChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
121  if (veh(ce) != 0) {
122  return true;
123  }
124  }
125  return false;
126  }
127 
131  // If ce has a valid vehicle, return it. Otherwise return 0.
132  if (!ce->lane->myVehicles.empty()) {
133  return ce->lane->myVehicles.back();
134  } else {
135  return 0;
136  }
137  }
138 
139 
141  virtual bool change();
142 
143 
145  virtual bool changeOpposite(std::pair<MSVehicle*, double> leader);
146 
148  void registerUnchanged(MSVehicle* vehicle);
149 
152  void checkTraCICommands(MSVehicle* vehicle);
153 
157  bool applyTraCICommands(MSVehicle* vehicle);
158 
160  virtual void updateChanger(bool vehHasChanged);
161 
165  void updateLanes(SUMOTime t);
166 
170 
171  /* @brief check whether lane changing in the given direction is desirable
172  * and possible */
174  int laneOffset,
175  const std::pair<MSVehicle* const, double>& leader,
176  const std::vector<MSVehicle::LaneQ>& preb) const;
177 
178  /* @brief check whether lane changing in the given direction is desirable
179  * and possible */
180  int checkChange(
181  int laneOffset,
182  const MSLane* targetLane,
183  const std::pair<MSVehicle* const, double>& leader,
184  const std::pair<MSVehicle* const, double>& neighLead,
185  const std::pair<MSVehicle* const, double>& neighFollow,
186  const std::vector<MSVehicle::LaneQ>& preb) const;
187 
188  /* @brief start the lane change maneuver (and finish it instantly if gLaneChangeDuration == 0)
189  * @return False when aborting the change due to being remote controlled*/
190  bool startChange(MSVehicle* vehicle, ChangerIt& from, int direction);
191 
193  bool continueChange(MSVehicle* vehicle, ChangerIt& from);
194 
195  std::pair<MSVehicle* const, double> getRealFollower(const ChangerIt& target) const;
196 
197  std::pair<MSVehicle* const, double> getRealLeader(const ChangerIt& target) const;
198 
200  bool mayChange(int direction) const;
201 
203  static MSVehicle* getCloserFollower(const double maxPos, MSVehicle* follow1, MSVehicle* follow2);
204 
212  static void computeOvertakingTime(const MSVehicle* vehicle, const MSVehicle* leader, double gap, double& timeToOvertake, double& spaceToOvertake);
213 
214  // @brief return leader vehicle that is to be overtaken
215  static std::pair<MSVehicle*, double> getColumnleader(MSVehicle* vehicle, std::pair<MSVehicle*, double> leader, double maxLookAhead = std::numeric_limits<double>::max());
216 
218  static MSLane* getLaneAfter(const MSLane* lane, const std::vector<MSLane*>& conts);
219 
220 protected:
223 
228 
229  /* @brief Whether vehicles may start to change lanes on this edge
230  * (finishing a change in progress is always permitted) */
231  const bool myAllowsChanging;
232 
234  const bool myChangeToOpposite;
235 
236 private:
239 
242 
245 };
long long int SUMOTime
Definition: SUMOTime.h:31
Performs lane changing of vehicles.
Definition: MSLaneChanger.h:45
virtual ~MSLaneChanger()
Destructor.
bool applyTraCICommands(MSVehicle *vehicle)
Execute TraCI LC-commands.
bool continueChange(MSVehicle *vehicle, ChangerIt &from)
continue a lane change maneuver and return whether the vehicle has completely moved onto the new lane...
const bool myChangeToOpposite
whether this edge allows changing to the opposite direction edge
MSLaneChanger(const MSLaneChanger &)
Copy constructor.
static std::pair< MSVehicle *, double > getColumnleader(MSVehicle *vehicle, std::pair< MSVehicle *, double > leader, double maxLookAhead=std::numeric_limits< double >::max())
MSLaneChanger()
Default constructor.
void checkTraCICommands(MSVehicle *vehicle)
Take into account traci LC-commands.
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge'e lanes.
virtual void initChanger()
Initialize the changer before looping over all vehicles.
bool vehInChanger() const
Check if there is a single change-candidate in the changer. Returns true if there is one.
std::pair< MSVehicle *const, double > getRealFollower(const ChangerIt &target) const
virtual bool change()
std::vector< ChangeElem > Changer
The list of changers; For each lane, a ChangeElem is being build.
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
bool startChange(MSVehicle *vehicle, ChangerIt &from, int direction)
const bool myAllowsChanging
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.
int checkChangeWithinEdge(int laneOffset, const std::pair< MSVehicle *const, double > &leader, const std::vector< MSVehicle::LaneQ > &preb) const
MSVehicle * veh(ConstChangerIt ce) const
Changer myChanger
Container for ChangeElemements, one for every lane in the edge.
virtual bool changeOpposite(std::pair< MSVehicle *, double > leader)
ChangerIt findCandidate()
Find current candidate. If there is none, myChanger.end() is returned.
bool mayChange(int direction) const
whether changing to the lane in the given direction should be considered
Changer::const_iterator ConstChangerIt
the iterator moving over the ChangeElems
static MSVehicle * getCloserFollower(const double maxPos, MSVehicle *follow1, MSVehicle *follow2)
return the closer follower of ego
MSLaneChanger & operator=(const MSLaneChanger &)
Assignment operator.
void registerUnchanged(MSVehicle *vehicle)
void updateLanes(SUMOTime t)
ChangerIt myCandi
std::pair< MSVehicle *const, double > getRealLeader(const ChangerIt &target) const
Changer::iterator ChangerIt
the iterator moving over the ChangeElems
static MSLane * getLaneAfter(const MSLane *lane, const std::vector< MSLane * > &conts)
return the next lane in conts beyond lane or nullptr
virtual void updateChanger(bool vehHasChanged)
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:130
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
std::vector< int > siblings
Definition: MSLaneChanger.h:87
bool mayChangeRight
whether changing is possible to either direction
Definition: MSLaneChanger.h:82
MSVehicle * lead
the leader vehicle for the current change candidate
Definition: MSLaneChanger.h:69
MSLeaderDistanceInfo aheadNext
Definition: MSLaneChanger.h:95
MSLane * lane
the lane corresponding to this ChangeElem (the current change candidate is on this lane)
Definition: MSLaneChanger.h:71
MSVehicle * lastBlocked
the next vehicle downstream of the ego vehicle that is blocked from changing to this lane
Definition: MSLaneChanger.h:75
MSVehicle * firstBlocked
the farthest downstream vehicle on this edge that is blocked from changing to this lane
Definition: MSLaneChanger.h:77
void registerHop(MSVehicle *vehicle)
Register that vehicle belongs to Changer Item to after LC decisions.
MSVehicle * hoppedVeh
last vehicle that changed into this lane
Definition: MSLaneChanger.h:73