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 /****************************************************************************/
18 // Performs lane changing of vehicles
19 /****************************************************************************/
20 #ifndef MSLaneChanger_h
21 #define MSLaneChanger_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include "MSLane.h"
30 #include "MSEdge.h"
31 #include "MSVehicle.h"
32 #include <vector>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
49 public:
51  MSLaneChanger(const std::vector<MSLane*>* lanes, bool allowChanging);
52 
54  virtual ~MSLaneChanger();
55 
57  void laneChange(SUMOTime t);
58 
59 public:
64  struct ChangeElem {
65 
66  ChangeElem(MSLane* _lane);
67 
69  void registerHop(MSVehicle* vehicle);
70 
81 
82  double dens;
83 
87 
90  std::vector<int> siblings;
91 
94  // the vehicles in from of the current vehicle (only on the current edge, continously updated during change() )
96 
97  // the vehicles in from of the current vehicle (including those on the next edge, contiously update during change() ))
100 
101  };
102 
103 public:
106  typedef std::vector< ChangeElem > Changer;
107 
109  typedef Changer::iterator ChangerIt;
110 
112  typedef Changer::const_iterator ConstChangerIt;
113 
114 protected:
116  virtual void initChanger();
117 
120  bool vehInChanger() const {
121  // If there is at least one valid vehicle under the veh's in myChanger
122  // return true.
123  for (ConstChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
124  if (veh(ce) != 0) {
125  return true;
126  }
127  }
128  return false;
129  }
130 
133  MSVehicle* veh(ConstChangerIt ce) const {
134  // If ce has a valid vehicle, return it. Otherwise return 0.
135  if (!ce->lane->myVehicles.empty()) {
136  return ce->lane->myVehicles.back();
137  } else {
138  return 0;
139  }
140  }
141 
142 
144  virtual bool change();
145 
146 
148  virtual bool changeOpposite(std::pair<MSVehicle*, double> leader);
149 
151  void registerUnchanged(MSVehicle* vehicle);
152 
155  void checkTraCICommands(MSVehicle* vehicle);
156 
160  bool applyTraCICommands(MSVehicle* vehicle);
161 
163  virtual void updateChanger(bool vehHasChanged);
164 
168  void updateLanes(SUMOTime t);
169 
172  ChangerIt findCandidate();
173 
174  /* @brief check whether lane changing in the given direction is desirable
175  * and possible */
177  int laneOffset,
178  const std::pair<MSVehicle* const, double>& leader,
179  const std::vector<MSVehicle::LaneQ>& preb) const;
180 
181  /* @brief check whether lane changing in the given direction is desirable
182  * and possible */
183  int checkChange(
184  int laneOffset,
185  const MSLane* targetLane,
186  const std::pair<MSVehicle* const, double>& leader,
187  const std::pair<MSVehicle* const, double>& neighLead,
188  const std::pair<MSVehicle* const, double>& neighFollow,
189  const std::vector<MSVehicle::LaneQ>& preb) const;
190 
191  /* @brief start the lane change maneuver (and finish it instantly if gLaneChangeDuration == 0)
192  * @return False when aborting the change due to being remote controlled*/
193  bool startChange(MSVehicle* vehicle, ChangerIt& from, int direction);
194 
196  bool continueChange(MSVehicle* vehicle, ChangerIt& from);
197 
198  std::pair<MSVehicle* const, double> getRealFollower(const ChangerIt& target) const;
199 
200  std::pair<MSVehicle* const, double> getRealLeader(const ChangerIt& target) const;
201 
203  bool mayChange(int direction) const;
204 
206  static MSVehicle* getCloserFollower(const double maxPos, MSVehicle* follow1, MSVehicle* follow2);
207 
215  static void computeOvertakingTime(const MSVehicle* vehicle, const MSVehicle* leader, double gap, double& timeToOvertake, double& spaceToOvertake);
216 
217  // @brief return leader vehicle that is to be overtaken
218  static std::pair<MSVehicle*, double> getColumnleader(MSVehicle* vehicle, std::pair<MSVehicle*, double> leader, double maxLookAhead = std::numeric_limits<double>::max());
219 
221  static MSLane* getLaneAfter(MSLane* lane, const std::vector<MSLane*>& conts);
222 
223 protected:
225  Changer myChanger;
226 
230  ChangerIt myCandi;
231 
232  /* @brief Whether vehicles may start to change lanes on this edge
233  * (finishing a change in progress is always permitted) */
234  const bool myAllowsChanging;
235 
237  const bool myChangeToOpposite;
238 
239 private:
241  MSLaneChanger();
242 
245 
248 };
249 
250 
251 #endif
252 
253 /****************************************************************************/
254 
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge&#39;e lanes.
MSVehicle * firstBlocked
the farthest downstream vehicle on this edge that is blocked from changing to this lane ...
Definition: MSLaneChanger.h:80
static MSVehicle * getCloserFollower(const double maxPos, MSVehicle *follow1, MSVehicle *follow2)
return the closer follower of ego
saves leader/follower vehicles and their distances relative to an ego vehicle
Definition: MSLeaderInfo.h:133
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:35
MSLane * lane
the lane corresponding to this ChangeElem (the current change candidate is on this lane) ...
Definition: MSLaneChanger.h:74
static std::pair< MSVehicle *, double > getColumnleader(MSVehicle *vehicle, std::pair< MSVehicle *, double > leader, double maxLookAhead=std::numeric_limits< double >::max())
MSLeaderDistanceInfo aheadNext
Definition: MSLaneChanger.h:98
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 continueChange(MSVehicle *vehicle, ChangerIt &from)
continue a lane change maneuver and return whether the vehicle has completely moved onto the new lane...
virtual void initChanger()
Initialize the changer before looping over all vehicles.
virtual bool changeOpposite(std::pair< MSVehicle *, double > leader)
const bool myAllowsChanging
MSVehicle * veh(ConstChangerIt ce) const
static MSLane * getLaneAfter(MSLane *lane, const std::vector< MSLane *> &conts)
return the next lane in conts beyond lane or nullptr
std::pair< MSVehicle *const, double > getRealLeader(const ChangerIt &target) const
const bool myChangeToOpposite
whether this edge allows changing to the opposite direction edge
bool startChange(MSVehicle *vehicle, ChangerIt &from, int direction)
MSVehicle * lead
the leader vehicle for the current change candidate
Definition: MSLaneChanger.h:72
ChangerIt findCandidate()
Find current candidate. If there is none, myChanger.end() is returned.
bool vehInChanger() const
Check if there is a single change-candidate in the changer. Returns true if there is one...
bool applyTraCICommands(MSVehicle *vehicle)
Execute TraCI LC-commands.
void checkTraCICommands(MSVehicle *vehicle)
Take into account traci LC-commands.
Performs lane changing of vehicles.
Definition: MSLaneChanger.h:48
virtual bool change()
virtual void updateChanger(bool vehHasChanged)
Changer::const_iterator ConstChangerIt
the iterator moving over the ChangeElems
std::vector< int > siblings
Definition: MSLaneChanger.h:90
void registerHop(MSVehicle *vehicle)
Register that vehicle belongs to Changer Item to after LC decisions.
bool mayChangeRight
whether changing is possible to either direction
Definition: MSLaneChanger.h:85
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.
MSLaneChanger()
Default constructor.
void updateLanes(SUMOTime t)
int checkChangeWithinEdge(int laneOffset, const std::pair< MSVehicle *const, double > &leader, const std::vector< MSVehicle::LaneQ > &preb) const
std::pair< MSVehicle *const, double > getRealFollower(const ChangerIt &target) const
MSVehicle * lastBlocked
the next vehicle downstream of the ego vehicle that is blocked from changing to this lane ...
Definition: MSLaneChanger.h:78
std::vector< ChangeElem > Changer
The list of changers; For each lane, a ChangeElem is being build.
MSLaneChanger & operator=(const MSLaneChanger &)
Assignment operator.
virtual ~MSLaneChanger()
Destructor.
Changer::iterator ChangerIt
the iterator moving over the ChangeElems
Changer myChanger
Container for ChangeElemements, one for every lane in the edge.
void registerUnchanged(MSVehicle *vehicle)
MSVehicle * hoppedVeh
last vehicle that changed into this lane
Definition: MSLaneChanger.h:76
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
bool mayChange(int direction) const
whether changing to the lane in the given direction should be considered
ChangerIt myCandi