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-2016 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 
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*, SUMOReal> 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, SUMOReal>& 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, SUMOReal>& leader,
174  const std::pair<MSVehicle* const, SUMOReal>& neighLead,
175  const std::pair<MSVehicle* const, SUMOReal>& 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, SUMOReal> getRealFollower(const ChangerIt& target) const;
185 
186  std::pair<MSVehicle* const, SUMOReal> getRealLeader(const ChangerIt& target) const;
187 
189  bool mayChange(int direction) const;
190 
192  static MSVehicle* getCloserFollower(const SUMOReal maxPos, MSVehicle* follow1, MSVehicle* follow2);
193 
201  static void computeOvertakingTime(const MSVehicle* vehicle, const MSVehicle* leader, SUMOReal gap, SUMOReal& timeToOvertake, SUMOReal& 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) */
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
std::pair< MSVehicle *const, SUMOReal > getRealLeader(const ChangerIt &target) const
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
long long int SUMOTime
Definition: SUMOTime.h:43
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.
MSVehicle * veh(ConstChangerIt ce) const
const bool myChangeToOpposite
whether this edge allows changing to the opposite direction edge
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
static void computeOvertakingTime(const MSVehicle *vehicle, const MSVehicle *leader, SUMOReal gap, SUMOReal &timeToOvertake, SUMOReal &spaceToOvertake)
Compute the time and space required for overtaking the given leader.
ChangerIt findCandidate()
Find current candidate. If there is none, myChanger.end() is returned.
static MSVehicle * getCloserFollower(const SUMOReal maxPos, MSVehicle *follow1, MSVehicle *follow2)
return the closer follower of ego
bool vehInChanger() const
Check if there is a single change-candidate in the changer. Returns true if there is one...
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
virtual bool changeOpposite(std::pair< MSVehicle *, SUMOReal > leader)
int checkChangeWithinEdge(int laneOffset, const std::pair< MSVehicle *const, SUMOReal > &leader, const std::vector< MSVehicle::LaneQ > &preb) const
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.
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)
#define SUMOReal
Definition: config.h:213
MSVehicle * hoppedVeh
last vehicle that changed into this lane
Definition: MSLaneChanger.h:80
int checkChange(int laneOffset, const MSLane *targetLane, const std::pair< MSVehicle *const, SUMOReal > &leader, const std::pair< MSVehicle *const, SUMOReal > &neighLead, const std::pair< MSVehicle *const, SUMOReal > &neighFollow, const std::vector< MSVehicle::LaneQ > &preb) const
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
std::pair< MSVehicle *const, SUMOReal > getRealFollower(const ChangerIt &target) const
bool mayChange(int direction) const
whether changing to the lane in the given direction should be considered
ChangerIt myCandi