MSLaneChanger.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Performs lane changing of vehicles
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 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);
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     void setOverlap(const std::pair<MSVehicle * const, SUMOReal> &neighLead,
00152                     const std::pair<MSVehicle * const, SUMOReal> &neighFollow,
00153                     /*const ChangerIt &target,*/ int &blocked) const throw();
00154 
00155     void setIsSafeChange(const std::pair<MSVehicle * const, SUMOReal> &neighLead,
00156                          const std::pair<MSVehicle * const, SUMOReal> &neighFollow,
00157                          const ChangerIt &target, int &blocked) const throw();
00158 
00161     int advan2right(
00162         const std::pair<MSVehicle * const, SUMOReal> &leader,
00163         const std::pair<MSVehicle * const, SUMOReal> &rLead,
00164         const std::pair<MSVehicle * const, SUMOReal> &rFollow,
00165         int blocked,
00166         const std::vector<MSVehicle::LaneQ> &preb) const throw();
00167 
00170     int advan2left(
00171         const std::pair<MSVehicle * const, SUMOReal> &leader,
00172         const std::pair<MSVehicle * const, SUMOReal> &rLead,
00173         const std::pair<MSVehicle * const, SUMOReal> &rFollow,
00174         int blocked,
00175         const std::vector<MSVehicle::LaneQ> &preb) const throw();
00176 
00179     bool overlapWithHopped(ChangerIt target) const throw() {
00180         MSVehicle *v1 = target->hoppedVeh;
00181         MSVehicle *v2 = veh(myCandi);
00182         if (v1!=0 && v2!=0) {
00183             return MSVehicle::overlap(v1, v2);
00184         }
00185         return false;
00186     }
00187 
00188     std::pair<MSVehicle * const, SUMOReal> getRealThisLeader(const ChangerIt &target) const throw();
00189 
00190     std::pair<MSVehicle * const, SUMOReal> getRealFollower(const ChangerIt &target) const throw();
00191     std::pair<MSVehicle * const, SUMOReal> getRealRightFollower() const throw();
00192     std::pair<MSVehicle * const, SUMOReal> getRealLeftFollower() const throw();
00193 
00194     std::pair<MSVehicle * const, SUMOReal> getRealLeader(const ChangerIt &target) const throw();
00195     std::pair<MSVehicle * const, SUMOReal> getRealRightLeader() const throw();
00196     std::pair<MSVehicle * const, SUMOReal> getRealLeftLeader() const throw();
00197 
00198 protected:
00200     Changer   myChanger;
00201 
00205     ChangerIt myCandi;
00206 
00207 private:
00209     MSLaneChanger();
00210 
00212     MSLaneChanger(const MSLaneChanger&);
00213 
00215     MSLaneChanger& operator=(const MSLaneChanger&);
00216 };
00217 
00218 
00219 #endif
00220 
00221 /****************************************************************************/
00222 

Generated on Wed May 5 00:06:31 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6