|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Network state mean data collector for edges/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 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 <microsim/MSEdgeControl.h> 00031 #include <microsim/MSEdge.h> 00032 #include <microsim/MSLane.h> 00033 #include <microsim/MSVehicle.h> 00034 #include <utils/common/SUMOTime.h> 00035 #include <utils/common/ToString.h> 00036 #include <utils/iodevices/OutputDevice.h> 00037 #include "MSMeanData_Net.h" 00038 #include <limits> 00039 00040 #ifdef HAVE_MESOSIM 00041 #include <microsim/MSGlobals.h> 00042 #include <mesosim/MELoop.h> 00043 #include <mesosim/MESegment.h> 00044 #endif 00045 00046 #ifdef CHECK_MEMORY_LEAKS 00047 #include <foreign/nvwa/debug_new.h> 00048 #endif // CHECK_MEMORY_LEAKS 00049 00050 00051 // =========================================================================== 00052 // method definitions 00053 // =========================================================================== 00054 // --------------------------------------------------------------------------- 00055 // MSMeanData_Net::MSLaneMeanDataValues - methods 00056 // --------------------------------------------------------------------------- 00057 MSMeanData_Net::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane, 00058 const SUMOReal length, 00059 const bool doAdd, 00060 const std::set<std::string>* const vTypes, 00061 const MSMeanData_Net* parent) throw() 00062 : MSMeanData::MeanDataValues(lane, length, doAdd, vTypes), myParent(parent), 00063 nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0), 00064 nVehLaneChangeFrom(0), nVehLaneChangeTo(0), waitSeconds(0), vehLengthSum(0) {} 00065 00066 00067 MSMeanData_Net::MSLaneMeanDataValues::~MSLaneMeanDataValues() throw() { 00068 } 00069 00070 00071 void 00072 MSMeanData_Net::MSLaneMeanDataValues::reset(bool) throw() { 00073 nVehDeparted = 0; 00074 nVehArrived = 0; 00075 nVehEntered = 0; 00076 nVehLeft = 0; 00077 nVehLaneChangeFrom = 0; 00078 nVehLaneChangeTo = 0; 00079 sampleSeconds = 0.; 00080 travelledDistance = 0; 00081 waitSeconds = 0; 00082 vehLengthSum = 0; 00083 } 00084 00085 00086 void 00087 MSMeanData_Net::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const throw() { 00088 MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val; 00089 v.nVehDeparted += nVehDeparted; 00090 v.nVehArrived += nVehArrived; 00091 v.nVehEntered += nVehEntered; 00092 v.nVehLeft += nVehLeft; 00093 v.nVehLaneChangeFrom += nVehLaneChangeFrom; 00094 v.nVehLaneChangeTo += nVehLaneChangeTo; 00095 v.sampleSeconds += sampleSeconds; 00096 v.travelledDistance += travelledDistance; 00097 v.waitSeconds += waitSeconds; 00098 v.vehLengthSum += vehLengthSum; 00099 } 00100 00101 00102 void 00103 MSMeanData_Net::MSLaneMeanDataValues::notifyMoveInternal(SUMOVehicle& veh, SUMOReal timeOnLane, SUMOReal speed) throw() { 00104 sampleSeconds += timeOnLane; 00105 travelledDistance += speed * timeOnLane; 00106 vehLengthSum += veh.getVehicleType().getLengthWithGap() * timeOnLane; 00107 if (myParent != 0 && speed < myParent->myHaltSpeed) { 00108 waitSeconds += timeOnLane; 00109 } 00110 } 00111 00112 00113 bool 00114 MSMeanData_Net::MSLaneMeanDataValues::notifyLeave(SUMOVehicle& veh, SUMOReal /*lastPos*/, MSMoveReminder::Notification reason) throw() { 00115 if (vehicleApplies(veh) && (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane())) { 00116 #ifdef HAVE_MESOSIM 00117 if (MSGlobals::gUseMesoSim) { 00118 myLastVehicleUpdateValues.erase(&veh); 00119 } 00120 #endif 00121 if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) { 00122 ++nVehArrived; 00123 } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) { 00124 ++nVehLaneChangeFrom; 00125 } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) { 00126 ++nVehLeft; 00127 } 00128 } 00129 #ifdef HAVE_MESOSIM 00130 if (MSGlobals::gUseMesoSim) { 00131 return false; 00132 } 00133 #endif 00134 return reason == MSMoveReminder::NOTIFICATION_JUNCTION; 00135 } 00136 00137 00138 bool 00139 MSMeanData_Net::MSLaneMeanDataValues::notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) throw() { 00140 if (vehicleApplies(veh)) { 00141 if (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane()) { 00142 if (reason == MSMoveReminder::NOTIFICATION_DEPARTED) { 00143 ++nVehDeparted; 00144 } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) { 00145 ++nVehLaneChangeTo; 00146 } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) { 00147 ++nVehEntered; 00148 } 00149 } 00150 return true; 00151 } 00152 return false; 00153 } 00154 00155 00156 bool 00157 MSMeanData_Net::MSLaneMeanDataValues::isEmpty() const throw() { 00158 return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0 && nVehLeft == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0; 00159 } 00160 00161 00162 void 00163 MSMeanData_Net::MSLaneMeanDataValues::write(OutputDevice& dev, const SUMOTime period, 00164 const SUMOReal numLanes, const int numVehicles) const throw(IOError) { 00165 if (myParent == 0) { 00166 if (sampleSeconds > 0) { 00167 dev << "\" density=\"" << sampleSeconds / STEPS2TIME(period) *(SUMOReal) 1000 / myLaneLength << 00168 "\" occupancy=\"" << vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes *(SUMOReal) 100 << 00169 "\" waitingTime=\"" << waitSeconds << 00170 "\" speed=\"" << travelledDistance / sampleSeconds; 00171 } 00172 dev<<"\" departed=\""<<nVehDeparted<< 00173 "\" arrived=\""<<nVehArrived<< 00174 "\" entered=\""<<nVehEntered<< 00175 "\" left=\""<<nVehLeft<< 00176 "\"/>\n"; 00177 return; 00178 } 00179 if (sampleSeconds > myParent->myMinSamples) { 00180 SUMOReal traveltime = myParent->myMaxTravelTime; 00181 if (travelledDistance > 0.f) { 00182 traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance); 00183 } 00184 if (numVehicles > 0) { 00185 dev << "\" traveltime=\"" << sampleSeconds / numVehicles << 00186 "\" waitingTime=\"" << waitSeconds << 00187 "\" speed=\"" << travelledDistance / sampleSeconds; 00188 } else { 00189 dev << "\" traveltime=\"" << traveltime << 00190 "\" density=\"" << sampleSeconds / STEPS2TIME(period) *(SUMOReal) 1000 / myLaneLength << 00191 "\" occupancy=\"" << vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes *(SUMOReal) 100 << 00192 "\" waitingTime=\"" << waitSeconds << 00193 "\" speed=\"" << travelledDistance / sampleSeconds; 00194 } 00195 } 00196 dev<<"\" departed=\""<<nVehDeparted<< 00197 "\" arrived=\""<<nVehArrived<< 00198 "\" entered=\""<<nVehEntered<< 00199 "\" left=\""<<nVehLeft<< 00200 "\" laneChangedFrom=\""<<nVehLaneChangeFrom<< 00201 "\" laneChangedTo=\""<<nVehLaneChangeTo<< 00202 "\"/>\n"; 00203 } 00204 00205 // --------------------------------------------------------------------------- 00206 // MSMeanData_Net - methods 00207 // --------------------------------------------------------------------------- 00208 MSMeanData_Net::MSMeanData_Net(const std::string& id, 00209 const SUMOTime dumpBegin, const SUMOTime dumpEnd, 00210 const bool useLanes, const bool withEmpty, const bool withInternal, 00211 const bool trackVehicles, 00212 const SUMOReal maxTravelTime, const SUMOReal minSamples, 00213 const SUMOReal haltSpeed, const std::set<std::string> vTypes) throw() 00214 : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, withInternal, trackVehicles, maxTravelTime, minSamples, vTypes), 00215 myHaltSpeed(haltSpeed) { 00216 } 00217 00218 00219 MSMeanData_Net::~MSMeanData_Net() throw() {} 00220 00221 00222 MSMeanData::MeanDataValues* 00223 MSMeanData_Net::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const throw(IOError) { 00224 return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this); 00225 } 00226 00227 00228 /****************************************************************************/ 00229