SUMO - Simulation of Urban MObility

MSLink.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A connnection between lanes
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 MSLink_h
00020 #define MSLink_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 <vector>
00033 #include <set>
00034 #include <utils/common/SUMOTime.h>
00035 #include <utils/xml/SUMOXMLDefinitions.h>
00036 
00037 
00038 // ===========================================================================
00039 // class declarations
00040 // ===========================================================================
00041 class MSLane;
00042 class SUMOVehicle;
00043 
00044 
00045 // ===========================================================================
00046 // class definitions
00047 // ===========================================================================
00068 class MSLink {
00069 public:
00070 #ifndef HAVE_INTERNAL_LANES
00071 
00078     MSLink(MSLane* succLane,
00079            LinkDirection dir, LinkState state, SUMOReal length) throw();
00080 #else
00081 
00089     MSLink(MSLane* succLane, MSLane* via,
00090            LinkDirection dir, LinkState state,
00091            SUMOReal length) throw();
00092 #endif
00093 
00095     ~MSLink() throw();
00096 
00097 
00109     void setRequestInformation(unsigned int requestIdx, unsigned int respondIdx, bool isCrossing, bool isCont,
00110                                const std::vector<MSLink*> &foeLinks, const std::vector<MSLane*> &foeLanes) throw();
00111 
00112 
00119     void setApproaching(SUMOVehicle* approaching, SUMOTime arrivalTime, SUMOReal speed, bool setRequest) throw();
00120 
00121     void addBlockedLink(MSLink* link) throw();
00122 
00123 
00124 
00125     void removeApproaching(SUMOVehicle* veh);
00126 
00127 
00128 
00135     bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal vehicleLength) const throw();
00136 
00137     bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime) const throw();
00138     bool isBlockingAnyone() const throw() {
00139         return myApproachingVehicles.size()!=0;
00140     }
00141 
00142     bool willHaveBlockedFoe() const throw();
00143 
00144 
00145 
00152     bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime) const throw();
00153 
00154 
00159     LinkState getState() const throw() {
00160         return myState;
00161     }
00162 
00163 
00168     LinkDirection getDirection() const throw();
00169 
00170 
00175     void setTLState(LinkState state, SUMOTime t) throw();
00176 
00177 
00182     MSLane* getLane() const throw();
00183 
00184 
00189     unsigned int getRespondIndex() const throw();
00190 
00191 
00195     bool havePriority() const throw() {
00196         return myState>='A'&&myState<='Z';
00197     }
00198 
00199 
00204     SUMOReal getLength() const throw() {
00205         return myLength;
00206     }
00207 
00212     bool isCrossing() const throw() {
00213         return myIsCrossing;
00214     }
00215 
00216 
00217     bool isCont() const throw() {
00218         return myAmCont;
00219     }
00220 
00221 #ifdef HAVE_INTERNAL_LANES
00222 
00226     MSLane* getViaLane() const throw();
00227 #endif
00228 
00229 private:
00230     struct ApproachingVehicleInformation {
00231         ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime, SUMOVehicle* _vehicle, const bool _willPass)
00232             : arrivalTime(_arrivalTime), leavingTime(_leavingTime), vehicle(_vehicle), willPass(_willPass) {}
00233         SUMOTime arrivalTime;
00234         SUMOTime leavingTime;
00235         SUMOVehicle* vehicle;
00236         bool willPass;
00237     };
00238 
00239     typedef std::vector<ApproachingVehicleInformation> LinkApproachingVehicles;
00240 
00241     class vehicle_in_request_finder {
00242     public:
00243         explicit vehicle_in_request_finder(const SUMOVehicle* const v) : myVehicle(v) { }
00244         bool operator()(const ApproachingVehicleInformation& vo) {
00245             return vo.vehicle == myVehicle;
00246         }
00247     private:
00248         vehicle_in_request_finder& operator=(const vehicle_in_request_finder&); // just to avoid a compiler warning
00249     private:
00250         const SUMOVehicle* const myVehicle;
00251 
00252     };
00253 
00254 
00255 private:
00257     MSLane* myLane;
00258 
00259     LinkApproachingVehicles myApproachingVehicles;
00260     std::set<MSLink*> myBlockedFoeLinks;
00261 
00263     unsigned int myRequestIdx;
00264 
00266     unsigned int myRespondIdx;
00267 
00269     LinkState myState;
00270 
00272     LinkDirection myDirection;
00273 
00275     SUMOReal myLength;
00276 
00278     bool myIsCrossing;
00279 
00280     bool myAmCont;
00281 
00282 #ifdef HAVE_INTERNAL_LANES
00283 
00284     MSLane* const myJunctionInlane;
00285 #endif
00286 
00287     std::vector<MSLink*> myFoeLinks;
00288     std::vector<MSLane*> myFoeLanes;
00289     static SUMOTime myLookaheadTime;
00290 
00291 
00292 private:
00294     MSLink(const MSLink& s);
00295 
00297     MSLink& operator=(const MSLink& s);
00298 
00299 };
00300 
00301 
00302 #endif
00303 
00304 /****************************************************************************/
00305 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines