SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // A connnection between lanes 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 #ifndef MSLink_h 00023 #define MSLink_h 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <vector> 00036 #include <set> 00037 #include <utils/common/SUMOTime.h> 00038 #include <utils/xml/SUMOXMLDefinitions.h> 00039 00040 00041 // =========================================================================== 00042 // class declarations 00043 // =========================================================================== 00044 class MSLane; 00045 class SUMOVehicle; 00046 00047 00048 // =========================================================================== 00049 // class definitions 00050 // =========================================================================== 00071 class MSLink { 00072 public: 00073 #ifndef HAVE_INTERNAL_LANES 00074 00081 MSLink(MSLane* succLane, 00082 LinkDirection dir, LinkState state, SUMOReal length) ; 00083 #else 00084 00092 MSLink(MSLane* succLane, MSLane* via, 00093 LinkDirection dir, LinkState state, 00094 SUMOReal length) ; 00095 #endif 00096 00098 ~MSLink() ; 00099 00100 00112 void setRequestInformation(unsigned int requestIdx, unsigned int respondIdx, bool isCrossing, bool isCont, 00113 const std::vector<MSLink*> &foeLinks, const std::vector<MSLane*> &foeLanes) ; 00114 00115 00122 void setApproaching(SUMOVehicle* approaching, SUMOTime arrivalTime, SUMOReal speed, bool setRequest) ; 00123 00124 void addBlockedLink(MSLink* link) ; 00125 00126 00127 00128 void removeApproaching(SUMOVehicle* veh); 00129 00130 00131 00138 bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal vehicleLength) const ; 00139 00140 bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime) const ; 00141 bool isBlockingAnyone() const { 00142 return myApproachingVehicles.size() != 0; 00143 } 00144 00145 bool willHaveBlockedFoe() const ; 00146 00147 00148 00155 bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime) const ; 00156 00157 00162 LinkState getState() const { 00163 return myState; 00164 } 00165 00166 00171 LinkDirection getDirection() const ; 00172 00173 00178 void setTLState(LinkState state, SUMOTime t) ; 00179 00180 00185 MSLane* getLane() const ; 00186 00187 00192 unsigned int getRespondIndex() const ; 00193 00194 00198 bool havePriority() const { 00199 return myState >= 'A' && myState <= 'Z'; 00200 } 00201 00202 00207 SUMOReal getLength() const { 00208 return myLength; 00209 } 00210 00215 bool isCrossing() const { 00216 return myIsCrossing; 00217 } 00218 00219 00220 bool isCont() const { 00221 return myAmCont; 00222 } 00223 00224 #ifdef HAVE_INTERNAL_LANES 00225 00229 MSLane* getViaLane() const ; 00230 #endif 00231 00232 private: 00233 struct ApproachingVehicleInformation { 00234 ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime, SUMOVehicle* _vehicle, const bool _willPass) 00235 : arrivalTime(_arrivalTime), leavingTime(_leavingTime), vehicle(_vehicle), willPass(_willPass) {} 00236 SUMOTime arrivalTime; 00237 SUMOTime leavingTime; 00238 SUMOVehicle* vehicle; 00239 bool willPass; 00240 }; 00241 00242 typedef std::vector<ApproachingVehicleInformation> LinkApproachingVehicles; 00243 00244 class vehicle_in_request_finder { 00245 public: 00246 explicit vehicle_in_request_finder(const SUMOVehicle* const v) : myVehicle(v) { } 00247 bool operator()(const ApproachingVehicleInformation& vo) { 00248 return vo.vehicle == myVehicle; 00249 } 00250 private: 00251 vehicle_in_request_finder& operator=(const vehicle_in_request_finder&); // just to avoid a compiler warning 00252 private: 00253 const SUMOVehicle* const myVehicle; 00254 00255 }; 00256 00257 00258 private: 00260 MSLane* myLane; 00261 00262 LinkApproachingVehicles myApproachingVehicles; 00263 std::set<MSLink*> myBlockedFoeLinks; 00264 00266 unsigned int myRequestIdx; 00267 00269 unsigned int myRespondIdx; 00270 00272 LinkState myState; 00273 00275 LinkDirection myDirection; 00276 00278 SUMOReal myLength; 00279 00281 bool myIsCrossing; 00282 00283 bool myAmCont; 00284 00285 #ifdef HAVE_INTERNAL_LANES 00286 00287 MSLane* const myJunctionInlane; 00288 #endif 00289 00290 std::vector<MSLink*> myFoeLinks; 00291 std::vector<MSLane*> myFoeLanes; 00292 static SUMOTime myLookaheadTime; 00293 00294 00295 private: 00297 MSLink(const MSLink& s); 00298 00300 MSLink& operator=(const MSLink& s); 00301 00302 }; 00303 00304 00305 #endif 00306 00307 /****************************************************************************/ 00308