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 allowSwap);
59 
62 
64  void laneChange(SUMOTime t);
65 
66 public:
71  struct ChangeElem {
79  MSLane::VehCont::reverse_iterator veh;
86 
88 
89  };
90 
91 public:
94  typedef std::vector< ChangeElem > Changer;
95 
97  typedef Changer::iterator ChangerIt;
98 
100  typedef Changer::const_iterator ConstChangerIt;
101 
102 protected:
104  void initChanger();
105 
108  bool vehInChanger() const {
109  // If there is at least one valid vehicle under the veh's in myChanger
110  // return true.
111  for (ConstChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
112  if (veh(ce) != 0) {
113  return true;
114  }
115  }
116  return false;
117  }
118 
121  MSVehicle* veh(ConstChangerIt ce) const {
122  // If ce has a valid vehicle, return it. Otherwise return 0.
123  if (ce->veh != ce->lane->myVehicles.rend()) {
124  return *(ce->veh);
125  }
126  return 0;
127  }
128 
129 
131  bool change();
132 
134  void registerUnchanged(MSVehicle* vehicle);
135 
137  void updateChanger(bool vehHasChanged);
138 
142  void updateLanes(SUMOTime t);
143 
146  ChangerIt findCandidate();
147 
148  /* @brief check whether lane changing in the given direction is desirable
149  * and possible */
150  int checkChange(
151  int laneOffset,
152  const std::pair<MSVehicle* const, SUMOReal>& leader,
153  const std::vector<MSVehicle::LaneQ>& preb) const;
154 
156  void startChange(MSVehicle* vehicle, ChangerIt& from, int direction);
157 
158  std::pair<MSVehicle* const, SUMOReal> getRealFollower(const ChangerIt& target) const;
159 
160  std::pair<MSVehicle* const, SUMOReal> getRealLeader(const ChangerIt& target) const;
161 
162 protected:
164  Changer myChanger;
165 
169  ChangerIt myCandi;
170 
173 
174 private:
176  MSLaneChanger();
177 
180 
183 };
184 
185 
186 #endif
187 
188 /****************************************************************************/
189 
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:85
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:43
MSLane * lane
the lane the vehicle is on
Definition: MSLaneChanger.h:77
std::pair< MSVehicle *const, SUMOReal > getRealLeader(const ChangerIt &target) const
MSLane::VehCont::reverse_iterator veh
the regarded vehicle
Definition: MSLaneChanger.h:79
void initChanger()
Initialize the changer before looping over all vehicles.
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:75
MSVehicle * follow
the vehicle following the current vehicle
Definition: MSLaneChanger.h:73
ChangerIt findCandidate()
Find current candidate. If there is none, myChanger.end() is returned.
Performs lane changing of vehicles.
Definition: MSLaneChanger.h:55
std::pair< MSVehicle *const, SUMOReal > getRealFollower(const ChangerIt &target) const
void updateChanger(bool vehHasChanged)
Changer::const_iterator ConstChangerIt
the iterator moving over the ChangeElems
MSLaneChanger()
Default constructor.
int checkChange(int laneOffset, const std::pair< MSVehicle *const, SUMOReal > &leader, const std::vector< MSVehicle::LaneQ > &preb) const
void updateLanes(SUMOTime t)
MSVehicle * lastBlocked
the vehicle that really wants to change to this lane
Definition: MSLaneChanger.h:83
std::vector< ChangeElem > Changer
The list of changers; For each lane, a ChangeElem is being build.
Definition: MSLaneChanger.h:94
bool myAllowsSwap
Whether blocking vehicles may be swapped.
MSLaneChanger & operator=(const MSLaneChanger &)
Assignment operator.
~MSLaneChanger()
Destructor.
Changer::iterator ChangerIt
the iterator moving over the ChangeElems
Definition: MSLaneChanger.h:97
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:81
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
ChangerIt myCandi