SUMO - Simulation of Urban MObility

MSAbstractLaneChangeModel.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Interface for lane-change models
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 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 "MSLane.h"
00033 #include "MSVehicle.h"
00034 
00035 
00036 // ===========================================================================
00037 // used enumeration
00038 // ===========================================================================
00042 enum LaneChangeAction {
00045 
00047     LCA_NONE = 0,
00049     LCA_URGENT = 1,
00051     LCA_SPEEDGAIN = 2,
00053     LCA_LEFT = 4,
00055     LCA_RIGHT = 8,
00056 
00057     LCA_WANTS_LANECHANGE = LCA_URGENT | LCA_SPEEDGAIN | LCA_LEFT | LCA_RIGHT,
00059 
00060 
00063 
00065     LCA_BLOCKED_BY_LEFT_LEADER = 16,
00067     LCA_BLOCKED_BY_LEFT_FOLLOWER = 32,
00068 
00070     LCA_BLOCKED_BY_RIGHT_LEADER = 64,
00072     LCA_BLOCKED_BY_RIGHT_FOLLOWER = 128,
00073 
00074     LCA_BLOCKED_LEFT = LCA_BLOCKED_BY_LEFT_LEADER | LCA_BLOCKED_BY_LEFT_FOLLOWER,
00075     LCA_BLOCKED_RIGHT = LCA_BLOCKED_BY_RIGHT_LEADER | LCA_BLOCKED_BY_RIGHT_FOLLOWER,
00076     LCA_BLOCKED_BY_LEADER = LCA_BLOCKED_BY_LEFT_LEADER | LCA_BLOCKED_BY_RIGHT_LEADER,
00077     LCA_BLOCKED_BY_FOLLOWER = LCA_BLOCKED_BY_LEFT_FOLLOWER | LCA_BLOCKED_BY_RIGHT_FOLLOWER,
00078     LCA_BLOCKED = LCA_BLOCKED_LEFT | LCA_BLOCKED_RIGHT
00079 
00080                   // The vehicle is blocked being overlapping
00081                   // This is currently not used, but I'll keep it while working on this, as
00082                   //  overlapping may be interested, but surely divided by leader/follower
00083                   // LCA_OVERLAPPING = 64
00085 
00086 };
00087 
00088 
00089 
00090 
00091 
00092 // ===========================================================================
00093 // class definitions
00094 // ===========================================================================
00099 class MSAbstractLaneChangeModel {
00100 public:
00104     class MSLCMessager {
00105     public:
00111         MSLCMessager(MSVehicle* leader,  MSVehicle* neighLead, MSVehicle* neighFollow) throw()
00112             : myLeader(leader), myNeighLeader(neighLead),
00113               myNeighFollower(neighFollow) { }
00114 
00115 
00117         ~MSLCMessager() { }
00118 
00119 
00125         void* informLeader(void* info, MSVehicle* sender) throw() {
00126             assert(myLeader!=0);
00127             return myLeader->getLaneChangeModel().inform(info, sender);
00128         }
00129 
00130 
00136         void* informNeighLeader(void* info, MSVehicle* sender) throw() {
00137             assert(myNeighLeader!=0);
00138             return myNeighLeader->getLaneChangeModel().inform(info, sender);
00139         }
00140 
00141 
00147         void* informNeighFollower(void* info, MSVehicle* sender) throw() {
00148             assert(myNeighFollower!=0);
00149             return myNeighFollower->getLaneChangeModel().inform(info, sender);
00150         }
00151 
00152 
00153     private:
00155         MSVehicle* myLeader;
00157         MSVehicle* myNeighLeader;
00159         MSVehicle* myNeighFollower;
00160 
00161     };
00162 
00163 
00164 
00168     MSAbstractLaneChangeModel(MSVehicle& v) throw()
00169         : myVehicle(v), myOwnState(0),
00170 #ifndef NO_TRACI
00171           myChangeRequest(MSVehicle::REQUEST_NONE),
00172 #endif
00173           myCarFollowModel(v.getCarFollowModel()) {
00174     }
00175 
00176 
00178     virtual ~MSAbstractLaneChangeModel() { }
00179 
00180 
00181 
00182     int getOwnState() const {
00183         return myOwnState;
00184     }
00185 
00186     void setOwnState(int state) {
00187         myOwnState = state;
00188     }
00189 
00190     virtual void prepareStep() { }
00191 
00195     virtual int wantsChangeToRight(
00196         MSLCMessager& msgPass, int blocked,
00197         const std::pair<MSVehicle*, SUMOReal> &leader,
00198         const std::pair<MSVehicle*, SUMOReal> &neighLead,
00199         const std::pair<MSVehicle*, SUMOReal> &neighFollow,
00200         const MSLane& neighLane,
00201         const std::vector<MSVehicle::LaneQ> &preb,
00202         MSVehicle** lastBlocked) = 0;
00203 
00207     virtual int wantsChangeToLeft(
00208         MSLCMessager& msgPass, int blocked,
00209         const std::pair<MSVehicle*, SUMOReal> &leader,
00210         const std::pair<MSVehicle*, SUMOReal> &neighLead,
00211         const std::pair<MSVehicle*, SUMOReal> &neighFollow,
00212         const MSLane& neighLane,
00213         const std::vector<MSVehicle::LaneQ> &preb,
00214         MSVehicle** lastBlocked) = 0;
00215 
00216     virtual void* inform(void* info, MSVehicle* sender) = 0;
00217 
00229     virtual SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max,
00230                                 const MSCFModel& cfModel) = 0;
00231 
00232     virtual void changed() = 0;
00233 
00234 #ifndef NO_TRACI
00235 
00241     virtual void requestLaneChange(MSVehicle::ChangeRequest request) {
00242         myChangeRequest = request;
00243     };
00244 
00251     virtual void fulfillChangeRequest(MSVehicle::ChangeRequest request) {
00252         if (request == myChangeRequest) {
00253             myChangeRequest = MSVehicle::REQUEST_NONE;
00254         }
00255     }
00256 #endif
00257 
00258 protected:
00259     virtual bool congested(const MSVehicle* const neighLeader) {
00260         if (neighLeader==0) {
00261             return false;
00262         }
00263         // Congested situation are relevant only on highways (maxSpeed > 70km/h)
00264         // and congested on German Highways means that the vehicles have speeds
00265         // below 60km/h. Overtaking on the right is allowed then.
00266         if ((myVehicle.getLane()->getMaxSpeed() <= 70.0 / 3.6) || (neighLeader->getLane()->getMaxSpeed() <= 70.0 / 3.6)) {
00267 
00268             return false;
00269         }
00270         if (myVehicle.congested() && neighLeader->congested()) {
00271             return true;
00272         }
00273         return false;
00274     }
00275 
00276     virtual bool predInteraction(const MSVehicle* const leader) {
00277         if (leader==0) {
00278             return false;
00279         }
00280         // let's check it on highways only
00281         if (leader->getSpeed()<(80.0/3.6)) {
00282             return false;
00283         }
00284         SUMOReal gap = leader->getPositionOnLane() - leader->getVehicleType().getLengthWithGap() - myVehicle.getPositionOnLane();
00285         return gap < myCarFollowModel.interactionGap(&myVehicle, leader->getSpeed());
00286     }
00287 
00288 
00289 
00290 protected:
00292     MSVehicle& myVehicle;
00293 
00295     int myOwnState;
00296 
00297 
00298 #ifndef NO_TRACI
00299     MSVehicle::ChangeRequest myChangeRequest;
00300 #endif
00301 
00303     const MSCFModel& myCarFollowModel;
00304 
00305 };
00306 
00307 
00308 #endif
00309 
00310 /****************************************************************************/
00311 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines