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-2014 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  std::pair<MSVehicle* const, SUMOReal> getRealThisLeader(const ChangerIt& target) const;
158 
159  std::pair<MSVehicle* const, SUMOReal> getRealFollower(const ChangerIt& target) const;
160 
161  std::pair<MSVehicle* const, SUMOReal> getRealLeader(const ChangerIt& target) const;
162 
163 protected:
166 
171 
174 
175 private:
177  MSLaneChanger();
178 
181 
184 };
185 
186 
187 #endif
188 
189 /****************************************************************************/
190 
void laneChange(SUMOTime t)
Start lane-change-process for all vehicles on the edge'e lanes.
MSVehicle * firstBlocked
the first vehicle on this edge that wants to change to this lane
Definition: MSLaneChanger.h:84
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
MSLane * lane
the lane the vehicle is on
Definition: MSLaneChanger.h:76
std::pair< MSVehicle *const, SUMOReal > getRealLeader(const ChangerIt &target) const
MSLane::VehCont::reverse_iterator veh
the regarded vehicle
Definition: MSLaneChanger.h:78
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:74
MSVehicle * follow
the vehicle following the current vehicle
Definition: MSLaneChanger.h:72
ChangerIt findCandidate()
Find current candidate. If there is none, myChanger.end() is returned.
Performs lane changing of vehicles.
Definition: MSLaneChanger.h:54
std::pair< MSVehicle *const, SUMOReal > getRealFollower(const ChangerIt &target) const
void updateChanger(bool vehHasChanged)
Changer::const_iterator ConstChangerIt
the iterator moving over the ChangeElems
Definition: MSLaneChanger.h:99
std::pair< MSVehicle *const, SUMOReal > getRealThisLeader(const ChangerIt &target) const
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:82
std::vector< ChangeElem > Changer
The list of changers; For each lane, a ChangeElem is being build.
Definition: MSLaneChanger.h:93
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:96
int SUMOTime
Definition: SUMOTime.h:43
Changer myChanger
Container for ChangeElemements, one for every lane in the edge.
void registerUnchanged(MSVehicle *vehicle)
#define SUMOReal
Definition: config.h:215
MSVehicle * hoppedVeh
last vehicle that changed into this lane
Definition: MSLaneChanger.h:80
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