SUMO - Simulation of Urban MObility
MSAbstractLaneChangeModel.h
Go to the documentation of this file.
00001 /****************************************************************************/
00010 // Interface for lane-change models
00011 /****************************************************************************/
00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00014 /****************************************************************************/
00015 //
00016 //   This file is part of SUMO.
00017 //   SUMO is free software: you can redistribute it and/or modify
00018 //   it under the terms of the GNU General Public License as published by
00019 //   the Free Software Foundation, either version 3 of the License, or
00020 //   (at your option) any later version.
00021 //
00022 /****************************************************************************/
00023 #ifndef MSAbstractLaneChangeModel_h
00024 #define MSAbstractLaneChangeModel_h
00025 
00026 
00027 // ===========================================================================
00028 // included modules
00029 // ===========================================================================
00030 #ifdef _MSC_VER
00031 #include <windows_config.h>
00032 #else
00033 #include <config.h>
00034 #endif
00035 
00036 #include "MSLane.h"
00037 #include "MSVehicle.h"
00038 
00039 
00040 // ===========================================================================
00041 // used enumeration
00042 // ===========================================================================
00046 enum LaneChangeAction {
00049 
00051     LCA_NONE = 0,
00053     LCA_URGENT = 1,
00055     LCA_SPEEDGAIN = 2,
00057     LCA_LEFT = 4,
00059     LCA_RIGHT = 8,
00060 
00061     LCA_WANTS_LANECHANGE = LCA_URGENT | LCA_SPEEDGAIN | LCA_LEFT | LCA_RIGHT,
00063 
00064 
00067 
00069     LCA_BLOCKED_BY_LEFT_LEADER = 16,
00071     LCA_BLOCKED_BY_LEFT_FOLLOWER = 32,
00072 
00074     LCA_BLOCKED_BY_RIGHT_LEADER = 64,
00076     LCA_BLOCKED_BY_RIGHT_FOLLOWER = 128,
00077 
00078     LCA_BLOCKED_LEFT = LCA_BLOCKED_BY_LEFT_LEADER | LCA_BLOCKED_BY_LEFT_FOLLOWER,
00079     LCA_BLOCKED_RIGHT = LCA_BLOCKED_BY_RIGHT_LEADER | LCA_BLOCKED_BY_RIGHT_FOLLOWER,
00080     LCA_BLOCKED_BY_LEADER = LCA_BLOCKED_BY_LEFT_LEADER | LCA_BLOCKED_BY_RIGHT_LEADER,
00081     LCA_BLOCKED_BY_FOLLOWER = LCA_BLOCKED_BY_LEFT_FOLLOWER | LCA_BLOCKED_BY_RIGHT_FOLLOWER,
00082     LCA_BLOCKED = LCA_BLOCKED_LEFT | LCA_BLOCKED_RIGHT
00083 
00084                   // The vehicle is blocked being overlapping
00085                   // This is currently not used, but I'll keep it while working on this, as
00086                   //  overlapping may be interested, but surely divided by leader/follower
00087                   // LCA_OVERLAPPING = 64
00089 
00090 };
00091 
00092 
00093 
00094 
00095 
00096 // ===========================================================================
00097 // class definitions
00098 // ===========================================================================
00103 class MSAbstractLaneChangeModel {
00104 public:
00108     class MSLCMessager {
00109     public:
00115         MSLCMessager(MSVehicle* leader,  MSVehicle* neighLead, MSVehicle* neighFollow)
00116             : myLeader(leader), myNeighLeader(neighLead),
00117               myNeighFollower(neighFollow) { }
00118 
00119 
00121         ~MSLCMessager() { }
00122 
00123 
00129         void* informLeader(void* info, MSVehicle* sender) {
00130             assert(myLeader != 0);
00131             return myLeader->getLaneChangeModel().inform(info, sender);
00132         }
00133 
00134 
00140         void* informNeighLeader(void* info, MSVehicle* sender) {
00141             assert(myNeighLeader != 0);
00142             return myNeighLeader->getLaneChangeModel().inform(info, sender);
00143         }
00144 
00145 
00151         void* informNeighFollower(void* info, MSVehicle* sender) {
00152             assert(myNeighFollower != 0);
00153             return myNeighFollower->getLaneChangeModel().inform(info, sender);
00154         }
00155 
00156 
00157     private:
00159         MSVehicle* myLeader;
00161         MSVehicle* myNeighLeader;
00163         MSVehicle* myNeighFollower;
00164 
00165     };
00166 
00167 
00168 
00172     MSAbstractLaneChangeModel(MSVehicle& v)
00173         : myVehicle(v), myOwnState(0),
00174 #ifndef NO_TRACI
00175           myChangeRequest(MSVehicle::REQUEST_NONE),
00176 #endif
00177           myCarFollowModel(v.getCarFollowModel()) {
00178     }
00179 
00180 
00182     virtual ~MSAbstractLaneChangeModel() { }
00183 
00184 
00185 
00186     int getOwnState() const {
00187         return myOwnState;
00188     }
00189 
00190     void setOwnState(int state) {
00191         myOwnState = state;
00192     }
00193 
00194     virtual void prepareStep() { }
00195 
00199     virtual int wantsChangeToRight(
00200         MSLCMessager& msgPass, int blocked,
00201         const std::pair<MSVehicle*, SUMOReal> &leader,
00202         const std::pair<MSVehicle*, SUMOReal> &neighLead,
00203         const std::pair<MSVehicle*, SUMOReal> &neighFollow,
00204         const MSLane& neighLane,
00205         const std::vector<MSVehicle::LaneQ> &preb,
00206         MSVehicle** lastBlocked) = 0;
00207 
00211     virtual int wantsChangeToLeft(
00212         MSLCMessager& msgPass, int blocked,
00213         const std::pair<MSVehicle*, SUMOReal> &leader,
00214         const std::pair<MSVehicle*, SUMOReal> &neighLead,
00215         const std::pair<MSVehicle*, SUMOReal> &neighFollow,
00216         const MSLane& neighLane,
00217         const std::vector<MSVehicle::LaneQ> &preb,
00218         MSVehicle** lastBlocked) = 0;
00219 
00220     virtual void* inform(void* info, MSVehicle* sender) = 0;
00221 
00233     virtual SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
00234                                 const MSCFModel& cfModel) = 0;
00235 
00236     virtual void changed() = 0;
00237 
00238 #ifndef NO_TRACI
00239 
00245     virtual void requestLaneChange(MSVehicle::ChangeRequest request) {
00246         myChangeRequest = request;
00247     };
00248 
00255     virtual void fulfillChangeRequest(MSVehicle::ChangeRequest request) {
00256         if (request == myChangeRequest) {
00257             myChangeRequest = MSVehicle::REQUEST_NONE;
00258         }
00259     }
00260 #endif
00261 
00262 protected:
00263     virtual bool congested(const MSVehicle* const neighLeader) {
00264         if (neighLeader == 0) {
00265             return false;
00266         }
00267         // Congested situation are relevant only on highways (maxSpeed > 70km/h)
00268         // and congested on German Highways means that the vehicles have speeds
00269         // below 60km/h. Overtaking on the right is allowed then.
00270         if ((myVehicle.getLane()->getMaxSpeed() <= 70.0 / 3.6) || (neighLeader->getLane()->getMaxSpeed() <= 70.0 / 3.6)) {
00271 
00272             return false;
00273         }
00274         if (myVehicle.congested() && neighLeader->congested()) {
00275             return true;
00276         }
00277         return false;
00278     }
00279 
00280     virtual bool predInteraction(const MSVehicle* const leader) {
00281         if (leader == 0) {
00282             return false;
00283         }
00284         // let's check it on highways only
00285         if (leader->getSpeed() < (80.0 / 3.6)) {
00286             return false;
00287         }
00288         SUMOReal gap = leader->getPositionOnLane() - leader->getVehicleType().getLength() - myVehicle.getVehicleType().getMinGap() - myVehicle.getPositionOnLane();
00289         return gap < myCarFollowModel.interactionGap(&myVehicle, leader->getSpeed());
00290     }
00291 
00292 
00293 
00294 protected:
00296     MSVehicle& myVehicle;
00297 
00299     int myOwnState;
00300 
00301 
00302 #ifndef NO_TRACI
00303     MSVehicle::ChangeRequest myChangeRequest;
00304 #endif
00305 
00307     const MSCFModel& myCarFollowModel;
00308 
00309 };
00310 
00311 
00312 #endif
00313 
00314 /****************************************************************************/
00315 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines