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;
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 registerUnchanged(MSVehicle* vehicle);
132 
134  void updateChanger(bool vehHasChanged);
135 
139  void updateLanes(SUMOTime t);
140 
144 
145  int change2right(
146  const std::pair<MSVehicle* const, SUMOReal>& leader,
147  const std::pair<MSVehicle* const, SUMOReal>& rLead,
148  const std::pair<MSVehicle* const, SUMOReal>& rFollow,
149  const std::vector<MSVehicle::LaneQ>& preb) const;
150 
151  int change2left(
152  const std::pair<MSVehicle* const, SUMOReal>& leader,
153  const std::pair<MSVehicle* const, SUMOReal>& rLead,
154  const std::pair<MSVehicle* const, SUMOReal>& rFollow,
155  const std::vector<MSVehicle::LaneQ>& preb) const;
156 
157 
159  void startChange(MSVehicle* vehicle, ChangerIt& from, int direction);
160 
161 
164  bool overlapWithHopped(ChangerIt target) const {
165  MSVehicle* v1 = target->hoppedVeh;
166  MSVehicle* v2 = veh(myCandi);
167  if (v1 != 0 && v2 != 0) {
168  return MSVehicle::overlap(v1, v2);
169  }
170  return false;
171  }
172 
173  std::pair<MSVehicle* const, SUMOReal> getRealThisLeader(const ChangerIt& target) const;
174 
175  std::pair<MSVehicle* const, SUMOReal> getRealFollower(const ChangerIt& target) const;
176 
177  std::pair<MSVehicle* const, SUMOReal> getRealLeader(const ChangerIt& target) const;
178 
179 protected:
182 
187 
190 
191 private:
193  MSLaneChanger();
194 
197 
200 };
201 
202 
203 #endif
204 
205 /****************************************************************************/
206