|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Performs lane changing of vehicles 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 #ifndef MSLaneChanger_h 00020 #define MSLaneChanger_h 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #include "MSLane.h" 00033 #include "MSEdge.h" 00034 #include <vector> 00035 #include <utils/iodevices/OutputDevice.h> 00036 00037 00038 // =========================================================================== 00039 // class declarations 00040 // =========================================================================== 00041 class MSVehicle; 00042 00043 00044 // =========================================================================== 00045 // class definitions 00046 // =========================================================================== 00051 class MSLaneChanger { 00052 public: 00054 MSLaneChanger(std::vector<MSLane*>* lanes, bool allowSwap); 00055 00057 ~MSLaneChanger(); 00058 00060 void laneChange(SUMOTime t); 00061 00062 public: 00067 struct ChangeElem { 00069 MSVehicle* follow; 00071 MSVehicle* lead; 00073 MSLane* lane; 00075 MSLane::VehCont::reverse_iterator veh; 00077 MSVehicle* hoppedVeh; 00079 MSVehicle* lastBlocked; 00080 00081 SUMOReal dens; 00082 00083 }; 00084 00085 public: 00088 typedef std::vector< ChangeElem > Changer; 00089 00091 typedef Changer::iterator ChangerIt; 00092 00094 typedef Changer::const_iterator ConstChangerIt; 00095 00096 protected: 00098 void initChanger(); 00099 00102 bool vehInChanger() const throw() { 00103 // If there is at least one valid vehicle under the veh's in myChanger 00104 // return true. 00105 for (ConstChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) { 00106 if (veh(ce) != 0) { 00107 return true; 00108 } 00109 } 00110 return false; 00111 } 00112 00115 MSVehicle* veh(ConstChangerIt ce) const throw() { 00116 // If ce has a valid vehicle, return it. Otherwise return 0. 00117 if (ce->veh != ce->lane->myVehicles.rend()) { 00118 return *(ce->veh); 00119 } 00120 return 0; 00121 } 00122 00123 00125 bool change(); 00126 00128 void updateChanger(bool vehHasChanged); 00129 00133 void updateLanes(SUMOTime t); 00134 00137 ChangerIt findCandidate(); 00138 00139 int change2right( 00140 const std::pair<MSVehicle* const, SUMOReal> &leader, 00141 const std::pair<MSVehicle* const, SUMOReal> &rLead, 00142 const std::pair<MSVehicle* const, SUMOReal> &rFollow, 00143 const std::vector<MSVehicle::LaneQ> &preb) const throw(); 00144 00145 int change2left( 00146 const std::pair<MSVehicle* const, SUMOReal> &leader, 00147 const std::pair<MSVehicle* const, SUMOReal> &rLead, 00148 const std::pair<MSVehicle* const, SUMOReal> &rFollow, 00149 const std::vector<MSVehicle::LaneQ> &preb) const throw(); 00150 00151 00152 00153 00156 bool overlapWithHopped(ChangerIt target) const throw() { 00157 MSVehicle* v1 = target->hoppedVeh; 00158 MSVehicle* v2 = veh(myCandi); 00159 if (v1!=0 && v2!=0) { 00160 return MSVehicle::overlap(v1, v2); 00161 } 00162 return false; 00163 } 00164 00165 std::pair<MSVehicle* const, SUMOReal> getRealThisLeader(const ChangerIt& target) const throw(); 00166 00167 std::pair<MSVehicle* const, SUMOReal> getRealFollower(const ChangerIt& target) const throw(); 00168 00169 std::pair<MSVehicle* const, SUMOReal> getRealLeader(const ChangerIt& target) const throw(); 00170 00171 protected: 00173 Changer myChanger; 00174 00178 ChangerIt myCandi; 00179 00181 bool myAllowsSwap; 00182 00183 private: 00185 MSLaneChanger(); 00186 00188 MSLaneChanger(const MSLaneChanger&); 00189 00191 MSLaneChanger& operator=(const MSLaneChanger&); 00192 }; 00193 00194 00195 #endif 00196 00197 /****************************************************************************/ 00198