SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
13 // Copyright (C) 2002-2014 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(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 
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 
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> getRealThisLeader(const ChangerIt& target) const;
159 
160  std::pair<MSVehicle* const, SUMOReal> getRealFollower(const ChangerIt& target) const;
161 
162  std::pair<MSVehicle* const, SUMOReal> getRealLeader(const ChangerIt& target) const;
163 
164 protected:
167 
172 
175 
176 private:
178  MSLaneChanger();
179 
182 
185 };
186 
187 
188 #endif
189 
190 /****************************************************************************/
191