SUMO - Simulation of Urban MObility
MSLaneChanger.h
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // Performs lane changing of vehicles
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
00022 #ifndef MSLaneChanger_h
00023 #define MSLaneChanger_h
00024 
00025 
00026 // ===========================================================================
00027 // included modules
00028 // ===========================================================================
00029 #ifdef _MSC_VER
00030 #include <windows_config.h>
00031 #else
00032 #include <config.h>
00033 #endif
00034 
00035 #include "MSLane.h"
00036 #include "MSEdge.h"
00037 #include "MSVehicle.h"
00038 #include <vector>
00039 #include <utils/iodevices/OutputDevice.h>
00040 
00041 
00042 // ===========================================================================
00043 // class declarations
00044 // ===========================================================================
00045 
00046 
00047 // ===========================================================================
00048 // class definitions
00049 // ===========================================================================
00054 class MSLaneChanger {
00055 public:
00057     MSLaneChanger(std::vector<MSLane*>* lanes, bool allowSwap);
00058 
00060     ~MSLaneChanger();
00061 
00063     void laneChange(SUMOTime t);
00064 
00065 public:
00070     struct ChangeElem {
00072         MSVehicle*                follow;
00074         MSVehicle*                lead;
00076         MSLane*                   lane;
00078         MSLane::VehCont::reverse_iterator veh;
00080         MSVehicle*                hoppedVeh;
00082         MSVehicle*                lastBlocked;
00083 
00084         SUMOReal dens;
00085 
00086     };
00087 
00088 public:
00091     typedef std::vector< ChangeElem > Changer;
00092 
00094     typedef Changer::iterator ChangerIt;
00095 
00097     typedef Changer::const_iterator ConstChangerIt;
00098 
00099 protected:
00101     void initChanger();
00102 
00105     bool vehInChanger() const {
00106         // If there is at least one valid vehicle under the veh's in myChanger
00107         // return true.
00108         for (ConstChangerIt ce = myChanger.begin(); ce != myChanger.end(); ++ce) {
00109             if (veh(ce) != 0) {
00110                 return true;
00111             }
00112         }
00113         return false;
00114     }
00115 
00118     MSVehicle* veh(ConstChangerIt ce) const {
00119         // If ce has a valid vehicle, return it. Otherwise return 0.
00120         if (ce->veh != ce->lane->myVehicles.rend()) {
00121             return *(ce->veh);
00122         }
00123         return 0;
00124     }
00125 
00126 
00128     bool change();
00129 
00131     void updateChanger(bool vehHasChanged);
00132 
00136     void updateLanes(SUMOTime t);
00137 
00140     ChangerIt findCandidate();
00141 
00142     int change2right(
00143         const std::pair<MSVehicle* const, SUMOReal> &leader,
00144         const std::pair<MSVehicle* const, SUMOReal> &rLead,
00145         const std::pair<MSVehicle* const, SUMOReal> &rFollow,
00146         const std::vector<MSVehicle::LaneQ> &preb) const ;
00147 
00148     int change2left(
00149         const std::pair<MSVehicle* const, SUMOReal> &leader,
00150         const std::pair<MSVehicle* const, SUMOReal> &rLead,
00151         const std::pair<MSVehicle* const, SUMOReal> &rFollow,
00152         const std::vector<MSVehicle::LaneQ> &preb) const ;
00153 
00154 
00155 
00156 
00159     bool overlapWithHopped(ChangerIt target) const {
00160         MSVehicle* v1 = target->hoppedVeh;
00161         MSVehicle* v2 = veh(myCandi);
00162         if (v1 != 0 && v2 != 0) {
00163             return MSVehicle::overlap(v1, v2);
00164         }
00165         return false;
00166     }
00167 
00168     std::pair<MSVehicle* const, SUMOReal> getRealThisLeader(const ChangerIt& target) const ;
00169 
00170     std::pair<MSVehicle* const, SUMOReal> getRealFollower(const ChangerIt& target) const ;
00171 
00172     std::pair<MSVehicle* const, SUMOReal> getRealLeader(const ChangerIt& target) const ;
00173 
00174 protected:
00176     Changer   myChanger;
00177 
00181     ChangerIt myCandi;
00182 
00184     bool myAllowsSwap;
00185 
00186 private:
00188     MSLaneChanger();
00189 
00191     MSLaneChanger(const MSLaneChanger&);
00192 
00194     MSLaneChanger& operator=(const MSLaneChanger&);
00195 };
00196 
00197 
00198 #endif
00199 
00200 /****************************************************************************/
00201 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines