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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // Performs lane changing of vehicles
21 /****************************************************************************/
22 #ifndef MSLaneChanger_h
23 #define MSLaneChanger_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include "MSLane.h"
36 #include "MSEdge.h"
37 #include "MSVehicle.h"
38 #include <vector>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
55 public:
57  MSLaneChanger(const std::vector<MSLane*>* lanes, bool allowChanging);
58 
60  virtual ~MSLaneChanger();
61 
63  void laneChange(SUMOTime t);
64 
65 public:
70  struct ChangeElem {
71 
72  ChangeElem(MSLane* _lane);
73 
75  void registerHop(MSVehicle* vehicle);
76 
87 
88  double dens;
89 
93 
96  std::vector<int> siblings;
97 
100  // the vehicles in from of the current vehicle (only on the current edge, continously updated during change() )
102 
103  // the vehicles in from of the current vehicle (including those on the next edge, contiously update during change() ))
106 
107  };
108 
109 public:
112  typedef std::vector< ChangeElem > Changer;
113 
115  typedef Changer::iterator ChangerIt;
116 
118  typedef Changer::const_iterator ConstChangerIt;
119 
120 protected:
122  virtual void initChanger();
123 
126  bool vehInChanger() const {
127  // If there is at least one valid vehicle under the veh's in myChanger
128  // return true.
129  for (ConstChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
130  if (veh(ce) != 0) {
131  return true;
132  }
133  }
134  return false;
135  }
136 
139  MSVehicle* veh(ConstChangerIt ce) const {
140  // If ce has a valid vehicle, return it. Otherwise return 0.
141  if (!ce->lane->myVehicles.empty()) {
142  return ce->lane->myVehicles.back();
143  } else {
144  return 0;
145  }
146  }
147 
148 
150  virtual bool change();
151 
152 
154  virtual bool changeOpposite(std::pair<MSVehicle*, double> leader);
155 
157  void registerUnchanged(MSVehicle* vehicle);
158 
161  void checkTraCICommands(MSVehicle* vehicle);
162 
166  bool applyTraCICommands(MSVehicle* vehicle);
167 
169  virtual void updateChanger(bool vehHasChanged);
170 
174  void updateLanes(SUMOTime t);
175 
178  ChangerIt findCandidate();
179 
180  /* @brief check whether lane changing in the given direction is desirable
181  * and possible */
183  int laneOffset,
184  const std::pair<MSVehicle* const, double>& leader,
185  const std::vector<MSVehicle::LaneQ>& preb) const;
186 
187  /* @brief check whether lane changing in the given direction is desirable
188  * and possible */
189  int checkChange(
190  int laneOffset,
191  const MSLane* targetLane,
192  const std::pair<MSVehicle* const, double>& leader,
193  const std::pair<MSVehicle* const, double>& neighLead,
194  const std::pair<MSVehicle* const, double>& neighFollow,
195  const std::vector<MSVehicle::LaneQ>& preb) const;
196 
198  void startChange(MSVehicle* vehicle, ChangerIt& from, int direction);
199 
201  bool continueChange(MSVehicle* vehicle, ChangerIt& from);
202 
203  std::pair<MSVehicle* const, double> getRealFollower(const ChangerIt& target) const;
204 
205  std::pair<MSVehicle* const, double> getRealLeader(const ChangerIt& target) const;
206 
208  bool mayChange(int direction) const;
209 
211  static MSVehicle* getCloserFollower(const double maxPos, MSVehicle* follow1, MSVehicle* follow2);
212 
220  static void computeOvertakingTime(const MSVehicle* vehicle, const MSVehicle* leader, double gap, double& timeToOvertake, double& spaceToOvertake);
221 
222 protected:
224  Changer myChanger;
225 
229  ChangerIt myCandi;
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 
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge&#39;e lanes.
MSVehicle * firstBlocked
the first vehicle on this edge that wants to change to this lane
Definition: MSLaneChanger.h:86
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:135
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
MSLane * lane
the lane the vehicle is on
Definition: MSLaneChanger.h:80
MSLeaderDistanceInfo aheadNext
bool continueChange(MSVehicle *vehicle, ChangerIt &from)
continue a lane change maneuver and return whether the midpoint was passed in this step (used if gLan...
virtual void initChanger()
Initialize the changer before looping over all vehicles.
virtual bool changeOpposite(std::pair< MSVehicle *, double > leader)
const bool myAllowsChanging
bool mayChange(int direction) const
whether changing to the lane in the given direction should be considered
const bool myChangeToOpposite
whether this edge allows changing to the opposite direction edge
MSVehicle * veh(ConstChangerIt ce) const
void startChange(MSVehicle *vehicle, ChangerIt &from, int direction)
start the lane change maneuver (and finish it instantly if gLaneChangeDuration == 0) ...
MSVehicle * lead
the vehicle in front of the current vehicle
Definition: MSLaneChanger.h:78
ChangerIt findCandidate()
Find current candidate. If there is none, myChanger.end() is returned.
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:54
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:96
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:91
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)
MSVehicle * lastBlocked
the vehicle that really wants to change to this lane
Definition: MSLaneChanger.h:84
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
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)
long long int SUMOTime
Definition: TraCIDefs.h:51
std::pair< MSVehicle *const, double > getRealFollower(const ChangerIt &target) const
MSVehicle * hoppedVeh
last vehicle that changed into this lane
Definition: MSLaneChanger.h:82
bool vehInChanger() const
Check if there is a single change-candidate in the changer. Returns true if there is one...
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
int checkChangeWithinEdge(int laneOffset, const std::pair< MSVehicle *const, double > &leader, const std::vector< MSVehicle::LaneQ > &preb) const
std::pair< MSVehicle *const, double > getRealLeader(const ChangerIt &target) const
ChangerIt myCandi