|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // A detector which joins E2Collectors over consecutive lanes (backward) 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00012 /****************************************************************************/ 00013 // 00014 // This file is part of SUMO. 00015 // SUMO is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 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 "MS_E2_ZS_CollectorOverLanes.h" 00033 #include "MSE2Collector.h" 00034 #include <microsim/MSLane.h> 00035 00036 #ifdef CHECK_MEMORY_LEAKS 00037 #include <foreign/nvwa/debug_new.h> 00038 #endif // CHECK_MEMORY_LEAKS 00039 00040 00041 // =========================================================================== 00042 // method definitions 00043 // =========================================================================== 00044 MS_E2_ZS_CollectorOverLanes::MS_E2_ZS_CollectorOverLanes(const std::string& id, 00045 DetectorUsage usage, 00046 MSLane* lane, 00047 SUMOReal startPos, 00048 SUMOTime haltingTimeThreshold, 00049 SUMOReal haltingSpeedThreshold, 00050 SUMOReal jamDistThreshold) 00051 : MSDetectorFileOutput(id), 00052 startPosM(startPos), haltingTimeThresholdM(haltingTimeThreshold), 00053 haltingSpeedThresholdM(haltingSpeedThreshold), jamDistThresholdM(jamDistThreshold), 00054 myID(id), myStartLaneID(lane->getID()), myUsage(usage) {} 00055 00056 00057 void 00058 MS_E2_ZS_CollectorOverLanes::init(MSLane* lane, SUMOReal detLength) { 00059 myLength = detLength; 00060 if (startPosM == 0) { 00061 startPosM = (SUMOReal) 0.1; 00062 } 00063 SUMOReal length = lane->getLength() - startPosM - (SUMOReal) 0.1; 00064 SUMOReal dlength = detLength; 00065 if (length > dlength) { 00066 length = dlength; 00067 } 00068 myLengths.push_back(length); 00069 myLaneCombinations.push_back(LaneVector()); 00070 myLaneCombinations[0].push_back(lane); 00071 myDetectorCombinations.push_back(DetectorVector()); 00072 MSE2Collector* c = 00073 buildCollector(0, 0, lane, startPosM, length); 00074 myDetectorCombinations[0].push_back(c); 00075 myAlreadyBuild[lane] = c; 00076 extendTo(detLength); 00077 } 00078 00079 00080 MS_E2_ZS_CollectorOverLanes::~MS_E2_ZS_CollectorOverLanes() {} 00081 00082 00083 void 00084 MS_E2_ZS_CollectorOverLanes::extendTo(SUMOReal length) { 00085 bool done = false; 00086 while (!done) { 00087 done = true; 00088 LengthVector::iterator leni = myLengths.begin(); 00089 LaneVectorVector::iterator lanei = myLaneCombinations.begin(); 00090 DetectorVectorVector::iterator deti = myDetectorCombinations.begin(); 00091 for (; leni != myLengths.end(); leni++, lanei++, deti++) { 00092 if ((*leni) < length) { 00093 done = false; 00094 // copy current values 00095 LaneVector lv = *lanei; 00096 DetectorVector dv = *deti; 00097 SUMOReal clength = *leni; 00098 assert(lv.size() > 0); 00099 assert(dv.size() > 0); 00100 // erase previous elements 00101 assert(leni != myLengths.end()); 00102 myLengths.erase(leni); 00103 myLaneCombinations.erase(lanei); 00104 myDetectorCombinations.erase(deti); 00105 // get the lane to look before 00106 MSLane* toExtend = lv.back(); 00107 // and her predecessors 00108 std::vector<MSLane*> predeccessors = getLanePredeccessorLanes(toExtend); 00109 if (predeccessors.size() == 0) { 00110 int off = 1; 00111 MSEdge& e = toExtend->getEdge(); 00112 const std::vector<MSLane*> &lanes = e.getLanes(); 00113 int idx = (int) distance(lanes.begin(), find(lanes.begin(), lanes.end(), toExtend)); 00114 while (predeccessors.size() == 0) { 00115 if (idx - off >= 0) { 00116 MSLane* tryMe = lanes[idx - off]; 00117 predeccessors = getLanePredeccessorLanes(tryMe); 00118 } 00119 if (predeccessors.size() == 0 && idx + off < (int) lanes.size()) { 00120 MSLane* tryMe = lanes[idx + off]; 00121 predeccessors = getLanePredeccessorLanes(tryMe); 00122 } 00123 off++; 00124 } 00125 } 00126 00127 /* LaneContinuations::const_iterator conts = 00128 laneContinuations.find(toExtend->id()); 00129 assert(conts!=laneContinuations.end()); 00130 const std::vector<std::string> &predeccessors = 00131 (*conts).second;*/ 00132 // go through the predeccessors and extend the detector 00133 for (std::vector<MSLane*>::const_iterator i = predeccessors.begin(); i != predeccessors.end(); i++) { 00134 // get the lane 00135 MSLane* l = *i; 00136 // compute detector length 00137 SUMOReal lanelen = length - clength; 00138 if (lanelen > l->getLength()) { 00139 lanelen = l->getLength() - (SUMOReal) 0.2; 00140 } 00141 // build new info 00142 LaneVector nlv = lv; 00143 nlv.push_back(l); 00144 DetectorVector ndv = dv; 00145 MSE2Collector* coll = 0; 00146 if (myAlreadyBuild.find(l) == myAlreadyBuild.end()) { 00147 coll = buildCollector(0, 0, l, (SUMOReal) 0.1, lanelen); 00148 } else { 00149 coll = myAlreadyBuild.find(l)->second; 00150 } 00151 myAlreadyBuild[l] = coll; 00152 ndv.push_back(coll); 00153 // store new info 00154 myLaneCombinations.push_back(nlv); 00155 myDetectorCombinations.push_back(ndv); 00156 myLengths.push_back(clength + lanelen); 00157 } 00158 // restart 00159 leni = myLengths.end() - 1; 00160 } 00161 } 00162 } 00163 } 00164 00165 00166 std::vector<MSLane*> 00167 MS_E2_ZS_CollectorOverLanes::getLanePredeccessorLanes(MSLane* l) { 00168 std::string eid = l->getEdge().getID(); 00169 // get predecessing edges 00170 const std::vector<MSEdge*> &predEdges = l->getEdge().getIncomingEdges(); 00171 std::vector<MSLane*> ret; 00172 // find predecessing lanes 00173 std::vector<MSEdge*>::const_iterator i = predEdges.begin(); 00174 for (; i != predEdges.end(); ++i) { 00175 MSEdge* e = *i; 00176 assert(e != 0); 00177 typedef std::vector<MSLane*> LaneVector; 00178 const LaneVector* cl = e->allowedLanes(l->getEdge(), SVC_UNKNOWN); 00179 bool fastAbort = false; 00180 if (cl != 0) { 00181 for (LaneVector::const_iterator j = cl->begin(); !fastAbort && j != cl->end(); j++) { 00182 const MSLinkCont& lc = (*j)->getLinkCont(); 00183 for (MSLinkCont::const_iterator k = lc.begin(); !fastAbort && k != lc.end(); k++) { 00184 if ((*k)->getLane() == l) { 00185 ret.push_back(*j); 00186 fastAbort = true; 00187 } 00188 } 00189 } 00190 } 00191 } 00192 return ret; 00193 } 00194 00195 00196 MSE2Collector* 00197 MS_E2_ZS_CollectorOverLanes::buildCollector(size_t c, size_t r, MSLane* l, 00198 SUMOReal start, SUMOReal end) { 00199 std::string id = makeID(l->getID(), c, r); 00200 if (start + end < l->getLength()) { 00201 start = l->getLength() - end - (SUMOReal) 0.1; 00202 } 00203 return new MSE2Collector(id, myUsage, 00204 l, start, end, haltingTimeThresholdM, 00205 haltingSpeedThresholdM, jamDistThresholdM); 00206 } 00207 00208 00209 void 00210 MS_E2_ZS_CollectorOverLanes::writeXMLOutput(OutputDevice& /*&dev*/, 00211 SUMOTime /*startTime*/, SUMOTime /*stopTime*/) { 00212 /* 00213 dev<<"<interval begin=\""<<time2string(startTime)<<"\" end=\""<< 00214 time2string(stopTime)<<"\" "<<"id=\""<<myID<<"\" "; 00215 if (hasDetector(E2::QUEUE_LENGTH_AHEAD_OF_TRAFFIC_LIGHTS_IN_VEHICLES)) { 00216 dev<<"collQueueLengthAheadOfTrafficLightsInVehiclesMax=\""; 00217 dev<<toString(getCurrent(E2::QUEUE_LENGTH_AHEAD_OF_TRAFFIC_LIGHTS_IN_VEHICLES)); 00218 dev<<"\" "; 00219 resetQueueLengthAheadOfTrafficLights(); 00220 } 00221 myDetectorCombinations[0][0]->writeXMLOutput(dev, startTime, stopTime); 00222 dev<<"/>\n"; 00223 */ 00224 } 00225 00226 00227 void 00228 MS_E2_ZS_CollectorOverLanes::writeXMLDetectorProlog(OutputDevice& dev) const { 00229 dev.writeXMLHeader("detector"); 00230 } 00231 00232 00233 size_t bla = 0; 00234 00235 std::string 00236 MS_E2_ZS_CollectorOverLanes::makeID(const std::string& baseID , 00237 size_t /*col*/, size_t /*row*/) const { 00238 std::string add; 00239 switch (myUsage) { 00240 case DU_USER_DEFINED: 00241 add = "(u)"; 00242 break; 00243 case DU_SUMO_INTERNAL: 00244 add = "(i)"; 00245 break; 00246 case DU_TL_CONTROL: 00247 add = "(c)"; 00248 break; 00249 default: 00250 break; 00251 } 00252 std::string ret = baseID + add + toString<size_t>(bla++); 00253 return ret; 00254 } 00255 00256 00257 const std::string& 00258 MS_E2_ZS_CollectorOverLanes::getID() const { 00259 return myID; 00260 } 00261 00262 00263 const std::string& 00264 MS_E2_ZS_CollectorOverLanes::getStartLaneID() const { 00265 return myStartLaneID; 00266 } 00267 00268 00269 /****************************************************************************/ 00270