SUMO - Simulation of Urban MObility
MSLaneChanger.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // Performs lane changing of vehicles
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2002-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef MSLaneChanger_h
24 #define MSLaneChanger_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include "MSLane.h"
37 #include "MSEdge.h"
38 #include "MSVehicle.h"
39 #include <vector>
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
56 public:
58  MSLaneChanger(const std::vector<MSLane*>* lanes, bool allowChanging);
59 
61  virtual ~MSLaneChanger();
62 
64  void laneChange(SUMOTime t);
65 
66 public:
71  struct ChangeElem {
72 
73  ChangeElem(MSLane* _lane);
74 
85 
86  double dens;
87 
90  // the vehicles in from of the current vehicle
93 
94  };
95 
96 public:
99  typedef std::vector< ChangeElem > Changer;
100 
102  typedef Changer::iterator ChangerIt;
103 
105  typedef Changer::const_iterator ConstChangerIt;
106 
107 protected:
109  virtual void initChanger();
110 
113  bool vehInChanger() const {
114  // If there is at least one valid vehicle under the veh's in myChanger
115  // return true.
116  for (ConstChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
117  if (veh(ce) != 0) {
118  return true;
119  }
120  }
121  return false;
122  }
123 
126  MSVehicle* veh(ConstChangerIt ce) const {
127  // If ce has a valid vehicle, return it. Otherwise return 0.
128  if (!ce->lane->myVehicles.empty()) {
129  return ce->lane->myVehicles.back();
130  } else {
131  return 0;
132  }
133  }
134 
135 
137  virtual bool change();
138 
139 
141  virtual bool changeOpposite(std::pair<MSVehicle*, double> leader);
142 
144  void registerUnchanged(MSVehicle* vehicle);
145 
147  virtual void updateChanger(bool vehHasChanged);
148 
152  void updateLanes(SUMOTime t);
153 
156  ChangerIt findCandidate();
157 
158  /* @brief check whether lane changing in the given direction is desirable
159  * and possible */
161  int laneOffset,
162  const std::pair<MSVehicle* const, double>& leader,
163  const std::vector<MSVehicle::LaneQ>& preb) const;
164 
165  /* @brief check whether lane changing in the given direction is desirable
166  * and possible */
167  int checkChange(
168  int laneOffset,
169  const MSLane* targetLane,
170  const std::pair<MSVehicle* const, double>& leader,
171  const std::pair<MSVehicle* const, double>& neighLead,
172  const std::pair<MSVehicle* const, double>& neighFollow,
173  const std::vector<MSVehicle::LaneQ>& preb) const;
174 
176  void startChange(MSVehicle* vehicle, ChangerIt& from, int direction);
177 
179  bool continueChange(MSVehicle* vehicle, ChangerIt& from);
180 
181  std::pair<MSVehicle* const, double> getRealFollower(const ChangerIt& target) const;
182 
183  std::pair<MSVehicle* const, double> getRealLeader(const ChangerIt& target) const;
184 
186  bool mayChange(int direction) const;
187 
189  static MSVehicle* getCloserFollower(const double maxPos, MSVehicle* follow1, MSVehicle* follow2);
190 
198  static void computeOvertakingTime(const MSVehicle* vehicle, const MSVehicle* leader, double gap, double& timeToOvertake, double& spaceToOvertake);
199 
200 protected:
202  Changer myChanger;
203 
207  ChangerIt myCandi;
208 
209  /* @brief Whether vehicles may start to change lanes on this edge
210  * (finishing a change in progress is always permitted) */
211  const bool myAllowsChanging;
212 
214  const bool myChangeToOpposite;
215 
216 private:
218  MSLaneChanger();
219 
222 
225 };
226 
227 
228 #endif
229 
230 /****************************************************************************/
231 
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:84
static MSVehicle * getCloserFollower(const double maxPos, MSVehicle *follow1, MSVehicle *follow2)
return the closer follower of ego
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
MSLane * lane
the lane the vehicle is on
Definition: MSLaneChanger.h:78
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:76
ChangerIt findCandidate()
Find current candidate. If there is none, myChanger.end() is returned.
Performs lane changing of vehicles.
Definition: MSLaneChanger.h:55
virtual bool change()
virtual void updateChanger(bool vehHasChanged)
Changer::const_iterator ConstChangerIt
the iterator moving over the ChangeElems
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:82
std::vector< ChangeElem > Changer
The list of changers; For each lane, a ChangeElem is being build.
Definition: MSLaneChanger.h:99
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:52
std::pair< MSVehicle *const, double > getRealFollower(const ChangerIt &target) const
MSVehicle * hoppedVeh
last vehicle that changed into this lane
Definition: MSLaneChanger.h:80
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:79
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