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.sourceforge.net/
12 // Copyright (C) 2001-2012 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;
83 
85 
86  };
87 
88 public:
91  typedef std::vector< ChangeElem > Changer;
92 
94  typedef Changer::iterator ChangerIt;
95 
97  typedef Changer::const_iterator ConstChangerIt;
98 
99 protected:
101  void initChanger();
102 
105  bool vehInChanger() const {
106  // If there is at least one valid vehicle under the veh's in myChanger
107  // return true.
108  for (ConstChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
109  if (veh(ce) != 0) {
110  return true;
111  }
112  }
113  return false;
114  }
115 
119  // If ce has a valid vehicle, return it. Otherwise return 0.
120  if (ce->veh != ce->lane->myVehicles.rend()) {
121  return *(ce->veh);
122  }
123  return 0;
124  }
125 
126 
128  bool change();
129 
131  void updateChanger(bool vehHasChanged);
132 
136  void updateLanes(SUMOTime t);
137 
141 
142  int change2right(
143  const std::pair<MSVehicle* const, SUMOReal> &leader,
144  const std::pair<MSVehicle* const, SUMOReal> &rLead,
145  const std::pair<MSVehicle* const, SUMOReal> &rFollow,
146  const std::vector<MSVehicle::LaneQ> &preb) const ;
147 
148  int change2left(
149  const std::pair<MSVehicle* const, SUMOReal> &leader,
150  const std::pair<MSVehicle* const, SUMOReal> &rLead,
151  const std::pair<MSVehicle* const, SUMOReal> &rFollow,
152  const std::vector<MSVehicle::LaneQ> &preb) const ;
153 
154 
155 
156 
159  bool overlapWithHopped(ChangerIt target) const {
160  MSVehicle* v1 = target->hoppedVeh;
161  MSVehicle* v2 = veh(myCandi);
162  if (v1 != 0 && v2 != 0) {
163  return MSVehicle::overlap(v1, v2);
164  }
165  return false;
166  }
167 
168  std::pair<MSVehicle* const, SUMOReal> getRealThisLeader(const ChangerIt& target) const ;
169 
170  std::pair<MSVehicle* const, SUMOReal> getRealFollower(const ChangerIt& target) const ;
171 
172  std::pair<MSVehicle* const, SUMOReal> getRealLeader(const ChangerIt& target) const ;
173 
174 protected:
177 
182 
185 
186 private:
188  MSLaneChanger();
189 
192 
195 };
196 
197 
198 #endif
199 
200 /****************************************************************************/
201