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
92 
93 
94  void addLink(MSLink* link);
96 
97  };
98 
99 public:
102  typedef std::vector< ChangeElem > Changer;
103 
105  typedef Changer::iterator ChangerIt;
106 
108  typedef Changer::const_iterator ConstChangerIt;
109 
110 protected:
112  void initChanger();
113 
116  bool vehInChanger() const {
117  // If there is at least one valid vehicle under the veh's in myChanger
118  // return true.
119  for (ConstChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
120  if (veh(ce) != 0) {
121  return true;
122  }
123  }
124  return false;
125  }
126 
129  MSVehicle* veh(ConstChangerIt ce) const {
130  // If ce has a valid vehicle, return it. Otherwise return 0.
131  if (!ce->lane->myVehicles.empty()) {
132  return ce->lane->myVehicles.back();
133  } else {
134  return 0;
135  }
136  }
137 
138 
140  virtual bool change();
141 
142 
144  virtual bool changeOpposite(std::pair<MSVehicle*, double> leader);
145 
147  void registerUnchanged(MSVehicle* vehicle);
148 
150  virtual void updateChanger(bool vehHasChanged);
151 
155  void updateLanes(SUMOTime t);
156 
159  ChangerIt findCandidate();
160 
161  /* @brief check whether lane changing in the given direction is desirable
162  * and possible */
164  int laneOffset,
165  const std::pair<MSVehicle* const, double>& leader,
166  const std::vector<MSVehicle::LaneQ>& preb) const;
167 
168  /* @brief check whether lane changing in the given direction is desirable
169  * and possible */
170  int checkChange(
171  int laneOffset,
172  const MSLane* targetLane,
173  const std::pair<MSVehicle* const, double>& leader,
174  const std::pair<MSVehicle* const, double>& neighLead,
175  const std::pair<MSVehicle* const, double>& neighFollow,
176  const std::vector<MSVehicle::LaneQ>& preb) const;
177 
179  void startChange(MSVehicle* vehicle, ChangerIt& from, int direction);
180 
182  bool continueChange(MSVehicle* vehicle, ChangerIt& from);
183 
184  std::pair<MSVehicle* const, double> getRealFollower(const ChangerIt& target) const;
185 
186  std::pair<MSVehicle* const, double> getRealLeader(const ChangerIt& target) const;
187 
189  bool mayChange(int direction) const;
190 
192  static MSVehicle* getCloserFollower(const double maxPos, MSVehicle* follow1, MSVehicle* follow2);
193 
201  static void computeOvertakingTime(const MSVehicle* vehicle, const MSVehicle* leader, double gap, double& timeToOvertake, double& spaceToOvertake);
202 
203 protected:
205  Changer myChanger;
206 
210  ChangerIt myCandi;
211 
212  /* @brief Whether vehicles may start to change lanes on this edge
213  * (finishing a change in progress is always permitted) */
214  const bool myAllowsChanging;
215 
217  const bool myChangeToOpposite;
218 
219 private:
221  MSLaneChanger();
222 
225 
228 };
229 
230 
231 #endif
232 
233 /****************************************************************************/
234 
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...
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.
void addLink(MSLink *link)
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.
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