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