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 /****************************************************************************/
9 // Performs lane changing of vehicles
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef MSLaneChanger_h
23 #define MSLaneChanger_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include "MSLane.h"
36 #include "MSEdge.h"
37 #include "MSVehicle.h"
38 #include <vector>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
55 public:
57  MSLaneChanger(std::vector<MSLane*>* lanes, bool allowSwap);
58 
61 
63  void laneChange(SUMOTime t);
64 
65 public:
70  struct ChangeElem {
78  MSLane::VehCont::reverse_iterator veh;
85 
87 
88  };
89 
90 public:
93  typedef std::vector< ChangeElem > Changer;
94 
96  typedef Changer::iterator ChangerIt;
97 
99  typedef Changer::const_iterator ConstChangerIt;
100 
101 protected:
103  void initChanger();
104 
107  bool vehInChanger() const {
108  // If there is at least one valid vehicle under the veh's in myChanger
109  // return true.
110  for (ConstChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
111  if (veh(ce) != 0) {
112  return true;
113  }
114  }
115  return false;
116  }
117 
121  // If ce has a valid vehicle, return it. Otherwise return 0.
122  if (ce->veh != ce->lane->myVehicles.rend()) {
123  return *(ce->veh);
124  }
125  return 0;
126  }
127 
128 
130  bool change();
131 
133  void registerUnchanged(MSVehicle* vehicle);
134 
136  void updateChanger(bool vehHasChanged);
137 
141  void updateLanes(SUMOTime t);
142 
146 
147  /* @brief check whether lane changing in the given direction is desirable
148  * and possible */
149  int checkChange(
150  int laneOffset,
151  const std::pair<MSVehicle* const, SUMOReal>& leader,
152  const std::vector<MSVehicle::LaneQ>& preb) const;
153 
155  void startChange(MSVehicle* vehicle, ChangerIt& from, int direction);
156 
157 
160  bool overlapWithHopped(ChangerIt target) const {
161  MSVehicle* v1 = target->hoppedVeh;
162  MSVehicle* v2 = veh(myCandi);
163  if (v1 != 0 && v2 != 0) {
164  return MSVehicle::overlap(v1, v2);
165  }
166  return false;
167  }
168 
169  std::pair<MSVehicle* const, SUMOReal> getRealThisLeader(const ChangerIt& target) const;
170 
171  std::pair<MSVehicle* const, SUMOReal> getRealFollower(const ChangerIt& target) const;
172 
173  std::pair<MSVehicle* const, SUMOReal> getRealLeader(const ChangerIt& target) const;
174 
175 protected:
178 
183 
186 
187 private:
189  MSLaneChanger();
190 
193 
196 };
197 
198 
199 #endif
200 
201 /****************************************************************************/
202