SUMO - Simulation of Urban MObility

MSLCM_DK2004.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A lane change model developed by D. Krajzewicz between 2004 and 2010
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 MSLCM_DK2004_h
00020 #define MSLCM_DK2004_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 <microsim/MSAbstractLaneChangeModel.h>
00033 #include <vector>
00034 
00035 // ===========================================================================
00036 // enumeration definition
00037 // ===========================================================================
00038 enum MyLCAEnum {
00039     LCA_AMBLOCKINGLEADER = 256, // 0
00040     LCA_AMBLOCKINGFOLLOWER = 512,// 1
00041     LCA_MRIGHT = 1024, // 2
00042     LCA_MLEFT = 2048,// 3
00043     // !!! never set LCA_UNBLOCK = 4096,// 4
00044     LCA_AMBLOCKINGFOLLOWER_DONTBRAKE = 8192,// 5
00045     // !!! never used LCA_AMBLOCKINGSECONDFOLLOWER = 16384, // 6
00046     // !!! never read LCA_KEEP1 = 65536,// 8
00047     // !!! never used LCA_KEEP2 = 131072,// 9
00048     LCA_AMBACKBLOCKER = 262144,// 10
00049     LCA_AMBACKBLOCKER_STANDING = 524288// 11
00050 
00051 };
00052 
00053 // ===========================================================================
00054 // class definitions
00055 // ===========================================================================
00060 class MSLCM_DK2004 : public MSAbstractLaneChangeModel {
00061 public:
00062     MSLCM_DK2004(MSVehicle& v);
00063 
00064     virtual ~MSLCM_DK2004();
00065 
00069     virtual int wantsChangeToRight(
00070         MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
00071         const std::pair<MSVehicle*, SUMOReal> &leader,
00072         const std::pair<MSVehicle*, SUMOReal> &neighLead,
00073         const std::pair<MSVehicle*, SUMOReal> &neighFollow,
00074         const MSLane& neighLane,
00075         const std::vector<MSVehicle::LaneQ> &preb,
00076         MSVehicle** lastBlocked);
00077 
00081     virtual int wantsChangeToLeft(
00082         MSAbstractLaneChangeModel::MSLCMessager& msgPass, int blocked,
00083         const std::pair<MSVehicle*, SUMOReal> &leader,
00084         const std::pair<MSVehicle*, SUMOReal> &neighLead,
00085         const std::pair<MSVehicle*, SUMOReal> &neighFollow,
00086         const MSLane& neighLane,
00087         const std::vector<MSVehicle::LaneQ> &preb,
00088         MSVehicle** lastBlocked);
00089 
00090     virtual void* inform(void* info, MSVehicle* sender);
00091 
00100     virtual SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
00101                                 const MSCFModel& cfModel);
00102 
00103     virtual void changed();
00104 
00105     SUMOReal getProb() const;
00106     virtual void prepareStep();
00107 
00108     SUMOReal getChangeProbability() const {
00109         return myChangeProbability;
00110     }
00111 
00112 
00113 protected:
00114     void informBlocker(MSAbstractLaneChangeModel::MSLCMessager& msgPass,
00115                        int& blocked, int dir,
00116                        const std::pair<MSVehicle*, SUMOReal> &neighLead,
00117                        const std::pair<MSVehicle*, SUMOReal> &neighFollow);
00118 
00119     inline bool amBlockingLeader() {
00120         return (myOwnState&LCA_AMBLOCKINGLEADER)!=0;
00121     }
00122     inline bool amBlockingFollower() {
00123         return (myOwnState&LCA_AMBLOCKINGFOLLOWER)!=0;
00124     }
00125     inline bool amBlockingFollowerNB() {
00126         return (myOwnState&LCA_AMBLOCKINGFOLLOWER_DONTBRAKE)!=0;
00127     }
00128     inline bool amBlockingFollowerPlusNB() {
00129         return (myOwnState&(LCA_AMBLOCKINGFOLLOWER|LCA_AMBLOCKINGFOLLOWER_DONTBRAKE))!=0;
00130     }
00131     inline bool currentDistDisallows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist) {
00132         return dist/(abs(laneOffset))<lookForwardDist;
00133     }
00134     inline bool currentDistAllows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist) {
00135         return dist/abs(laneOffset)>lookForwardDist;
00136     }
00137 
00138     typedef std::pair<SUMOReal, int> Info;
00139 
00140 
00141 
00142 protected:
00143     SUMOReal myChangeProbability;
00144 
00145     SUMOReal myLeadingBlockerLength;
00146     SUMOReal myLeftSpace;
00147 
00148     std::vector<SUMOReal> myVSafes;
00149     bool myDontBrake;
00150 
00151 };
00152 
00153 
00154 #endif
00155 
00156 /****************************************************************************/
00157 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines