|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // A connnection between lanes 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 00024 // =========================================================================== 00025 // included modules 00026 // =========================================================================== 00027 #ifdef _MSC_VER 00028 #include <windows_config.h> 00029 #else 00030 #include <config.h> 00031 #endif 00032 00033 #include "MSLink.h" 00034 #include "MSLane.h" 00035 #include <iostream> 00036 #include <cassert> 00037 00038 #ifdef CHECK_MEMORY_LEAKS 00039 #include <foreign/nvwa/debug_new.h> 00040 #endif // CHECK_MEMORY_LEAKS 00041 00042 00043 // =========================================================================== 00044 // static member variables 00045 // =========================================================================== 00046 SUMOTime MSLink::myLookaheadTime = TIME2STEPS(3); 00047 00048 00049 // =========================================================================== 00050 // member method definitions 00051 // =========================================================================== 00052 #ifndef HAVE_INTERNAL_LANES 00053 MSLink::MSLink(MSLane* succLane, 00054 LinkDirection dir, LinkState state, 00055 SUMOReal length) 00056 : 00057 myLane(succLane), 00058 myRequestIdx(0), myRespondIdx(0), 00059 myState(state), myDirection(dir), myLength(length) {} 00060 #else 00061 MSLink::MSLink(MSLane* succLane, MSLane* via, 00062 LinkDirection dir, LinkState state, SUMOReal length) 00063 : 00064 myLane(succLane), 00065 myRequestIdx(0), myRespondIdx(0), 00066 myState(state), myDirection(dir), myLength(length), 00067 myJunctionInlane(via) {} 00068 #endif 00069 00070 00071 MSLink::~MSLink() {} 00072 00073 00074 void 00075 MSLink::setRequestInformation(unsigned int requestIdx, unsigned int respondIdx, bool isCrossing, bool isCont, 00076 const std::vector<MSLink*> &foeLinks, 00077 const std::vector<MSLane*> &foeLanes) { 00078 myRequestIdx = requestIdx; 00079 myRespondIdx = respondIdx; 00080 myIsCrossing = isCrossing; 00081 myAmCont = isCont; 00082 myFoeLinks = foeLinks; 00083 myFoeLanes = foeLanes; 00084 } 00085 00086 00087 void 00088 MSLink::setApproaching(SUMOVehicle* approaching, SUMOTime arrivalTime, SUMOReal speed, bool setRequest) { 00089 LinkApproachingVehicles::iterator i = find_if(myApproachingVehicles.begin(), myApproachingVehicles.end(), vehicle_in_request_finder(approaching)); 00090 if (i != myApproachingVehicles.end()) { 00091 myApproachingVehicles.erase(i); 00092 } 00093 const SUMOTime leaveTime = arrivalTime + TIME2STEPS((approaching->getVehicleType().getLengthWithGap() + getLength()) / speed); 00094 ApproachingVehicleInformation approachInfo(arrivalTime, leaveTime, approaching, setRequest); 00095 myApproachingVehicles.push_back(approachInfo); 00096 } 00097 00098 00099 void 00100 MSLink::addBlockedLink(MSLink* link) { 00101 myBlockedFoeLinks.insert(link); 00102 } 00103 00104 00105 00106 bool 00107 MSLink::willHaveBlockedFoe() const { 00108 for (std::set<MSLink*>::const_iterator i = myBlockedFoeLinks.begin(); i != myBlockedFoeLinks.end(); ++i) { 00109 if ((*i)->isBlockingAnyone()) { 00110 return true; 00111 } 00112 } 00113 return false; 00114 } 00115 00116 00117 void 00118 MSLink::removeApproaching(SUMOVehicle* veh) { 00119 LinkApproachingVehicles::iterator i = find_if(myApproachingVehicles.begin(), myApproachingVehicles.end(), vehicle_in_request_finder(veh)); 00120 if (i != myApproachingVehicles.end()) { 00121 myApproachingVehicles.erase(i); 00122 } 00123 } 00124 00125 00126 bool 00127 MSLink::opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal vehicleLength) const { 00128 if (myState == LINKSTATE_TL_RED) { 00129 return false; 00130 } 00131 if (myAmCont) { 00132 return true; 00133 } 00134 #ifdef HAVE_INTERNAL_LANES 00135 const SUMOReal length = myJunctionInlane == 0 ? getLength() : myJunctionInlane->getLength(); 00136 #else 00137 const SUMOReal length = getLength(); 00138 #endif 00139 const SUMOTime leaveTime = arrivalTime + TIME2STEPS((length + vehicleLength) / arrivalSpeed); 00140 for (std::vector<MSLink*>::const_iterator i = myFoeLinks.begin(); i != myFoeLinks.end(); ++i) { 00141 #ifdef HAVE_MESOSIM 00142 if (MSGlobals::gUseMesoSim) { 00143 if ((*i)->getState() == LINKSTATE_TL_RED) { 00144 continue; 00145 } 00146 } 00147 #endif 00148 if ((*i)->blockedAtTime(arrivalTime, leaveTime)) { 00149 return false; 00150 } 00151 } 00152 for (std::vector<MSLane*>::const_iterator i = myFoeLanes.begin(); i != myFoeLanes.end(); ++i) { 00153 if ((*i)->getVehicleNumber() > 0 || (*i)->getPartialOccupator() != 0) { 00154 return false; 00155 } 00156 } 00157 return true; 00158 } 00159 00160 00161 bool 00162 MSLink::blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime) const { 00163 for (LinkApproachingVehicles::const_iterator i = myApproachingVehicles.begin(); i != myApproachingVehicles.end(); ++i) { 00164 if (!(*i).willPass) { 00165 continue; 00166 } 00167 if (!(((*i).leavingTime + myLookaheadTime < arrivalTime) || ((*i).arrivalTime - myLookaheadTime > leaveTime))) { 00168 return true; 00169 } 00170 } 00171 return false; 00172 } 00173 00174 00175 bool 00176 MSLink::hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime) const { 00177 for (std::vector<MSLink*>::const_iterator i = myFoeLinks.begin(); i != myFoeLinks.end(); ++i) { 00178 if ((*i)->blockedAtTime(arrivalTime, leaveTime)) { 00179 return true; 00180 } 00181 } 00182 for (std::vector<MSLane*>::const_iterator i = myFoeLanes.begin(); i != myFoeLanes.end(); ++i) { 00183 if ((*i)->getVehicleNumber() > 0 || (*i)->getPartialOccupator() != 0) { 00184 return true; 00185 } 00186 } 00187 return false; 00188 } 00189 00190 00191 LinkDirection 00192 MSLink::getDirection() const { 00193 return myDirection; 00194 } 00195 00196 00197 void 00198 MSLink::setTLState(LinkState state, SUMOTime /*t*/) { 00199 myState = state; 00200 } 00201 00202 00203 MSLane* 00204 MSLink::getLane() const { 00205 return myLane; 00206 } 00207 00208 00209 #ifdef HAVE_INTERNAL_LANES 00210 MSLane* 00211 MSLink::getViaLane() const { 00212 return myJunctionInlane; 00213 } 00214 #endif 00215 00216 00217 unsigned int 00218 MSLink::getRespondIndex() const { 00219 return myRespondIdx; 00220 } 00221 00222 00223 00224 /****************************************************************************/ 00225