MSAbstractLaneChangeModel.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 //  �missingDescription�
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 MSAbstractLaneChangeModel_h
00020 #define MSAbstractLaneChangeModel_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 "MSLaneChanger.h"
00033 #include "MSCFModel.h"
00034 
00035 // ===========================================================================
00036 // used enumeration
00037 // ===========================================================================
00038 enum LaneChangeAction {
00039     LCA_NONE = 0,
00040     LCA_URGENT = 1,
00041     LCA_SPEEDGAIN = 2,
00042     LCA_LEFT = 4,
00043     LCA_RIGHT = 8,
00044 
00045     LCA_BLOCKEDBY_LEADER = 16,
00046     LCA_BLOCKEDBY_FOLLOWER = 32,
00047     LCA_OVERLAPPING = 64,
00048 
00049     LCA_MAX = 128
00050 };
00051 
00052 enum ChangeRequest {
00053     REQUEST_NONE,  // vehicle doesn't want to change
00054     REQUEST_LEFT,  // vehicle want's to change to left lane
00055     REQUEST_RIGHT, // vehicle want's to change to right lane
00056     REQUEST_HOLD   // vehicle want's to keep the current lane
00057 };
00058 
00059 // ===========================================================================
00060 // class definitions
00061 // ===========================================================================
00065 class MSAbstractLaneChangeModel {
00066 public:
00067     class MSLCMessager {
00068     public:
00069         MSLCMessager(MSVehicle *leader,  MSVehicle *neighLead,
00070                      MSVehicle *neighFollow)
00071                 : myLeader(leader), myNeighLeader(neighLead),
00072                 myNeighFollower(neighFollow) { }
00073 
00074         ~MSLCMessager() { }
00075 
00076         void *informLeader(void *info, MSVehicle *sender) {
00077             assert(myLeader!=0);
00078             return myLeader->getLaneChangeModel().inform(info, sender);
00079         }
00080 
00081         void *informNeighLeader(void *info, MSVehicle *sender) {
00082             assert(myNeighLeader!=0);
00083             return myNeighLeader->getLaneChangeModel().inform(info, sender);
00084         }
00085 
00086         void *informNeighFollower(void *info, MSVehicle *sender) {
00087             assert(myNeighFollower!=0);
00088             return myNeighFollower->getLaneChangeModel().inform(info, sender);
00089         }
00090     private:
00091         MSVehicle *myLeader;
00092         MSVehicle *myNeighLeader;
00093         MSVehicle *myNeighFollower;
00094 
00095     };
00096 
00097 
00098     MSAbstractLaneChangeModel(MSVehicle &v)
00099             : myVehicle(v), myState(0),
00100 #ifndef NO_TRACI
00101             myChangeRequest(REQUEST_NONE),
00102 #endif
00103             myCarFollowModel(v.getCarFollowModel()) {
00104     }
00105 
00106     virtual ~MSAbstractLaneChangeModel() { }
00107 
00108     int getState() const {
00109         return myState;
00110     }
00111 
00112     void setState(int state) {
00113         myState = state;
00114     }
00115 
00116     virtual void prepareStep() { }
00117 
00121     virtual int wantsChangeToRight(
00122         MSLCMessager &msgPass, int blocked,
00123         const std::pair<MSVehicle*, SUMOReal> &leader,
00124         const std::pair<MSVehicle*, SUMOReal> &neighLead,
00125         const std::pair<MSVehicle*, SUMOReal> &neighFollow,
00126         const MSLane &neighLane,
00127         const std::vector<MSVehicle::LaneQ> &preb,
00128         MSVehicle **lastBlocked) = 0;
00129 
00133     virtual int wantsChangeToLeft(
00134         MSLCMessager &msgPass, int blocked,
00135         const std::pair<MSVehicle*, SUMOReal> &leader,
00136         const std::pair<MSVehicle*, SUMOReal> &neighLead,
00137         const std::pair<MSVehicle*, SUMOReal> &neighFollow,
00138         const MSLane &neighLane,
00139         const std::vector<MSVehicle::LaneQ> &preb,
00140         MSVehicle **lastBlocked) = 0;
00141 
00142     virtual void *inform(void *info, MSVehicle *sender) = 0;
00143 
00144     virtual SUMOReal patchSpeed(SUMOReal min, SUMOReal wanted, SUMOReal max,
00145                                 SUMOReal vsafe) = 0;
00146 
00147     virtual void changed() = 0;
00148 
00149 #ifndef NO_TRACI
00150 
00156     virtual void requestLaneChange(ChangeRequest request) {
00157         myChangeRequest = request;
00158     };
00159 
00166     virtual void fulfillChangeRequest(ChangeRequest request) {
00167         if (request == myChangeRequest) {
00168             myChangeRequest = REQUEST_NONE;
00169         }
00170     }
00171 #endif
00172 
00173 protected:
00174     virtual bool congested(const MSVehicle * const neighLeader) {
00175         if (neighLeader==0) {
00176             return false;
00177         }
00178         // Congested situation are relevant only on highways (maxSpeed > 70km/h)
00179         // and congested on German Highways means that the vehicles have speeds
00180         // below 60km/h. Overtaking on the right is allowed then.
00181         if ((myVehicle.getLane().getMaxSpeed() <= 70.0 / 3.6) ||
00182                 (neighLeader->getLane().getMaxSpeed() <= 70.0 / 3.6)) {
00183 
00184             return false;
00185         }
00186         if (myVehicle.congested() && neighLeader->congested()) {
00187             return true;
00188         }
00189         return false;
00190     }
00191 
00192     virtual bool predInteraction(const MSVehicle * const leader) {
00193         if (leader==0) {
00194             return false;
00195         }
00196         // let's check it on highways only
00197         if (leader->getSpeed()<(80.0*3.6)) {
00198             return false;
00199         }
00200         SUMOReal gap = leader->getPositionOnLane() - leader->getVehicleType().getLength() - myVehicle.getPositionOnLane();
00201         return gap < myCarFollowModel.interactionGap(&myVehicle, leader->getSpeed());
00202     }
00203 
00204 
00205 
00206 protected:
00207     MSVehicle &myVehicle;
00208 
00210     const MSCFModel &myCarFollowModel;
00211     int myState;
00212 #ifndef NO_TRACI
00213     ChangeRequest myChangeRequest;
00214 #endif
00215 };
00216 
00217 
00218 #endif
00219 
00220 /****************************************************************************/
00221 

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