|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Emission 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/MSLane.h> 00031 #include <microsim/MSVehicle.h> 00032 #include <utils/common/SUMOTime.h> 00033 #include <utils/common/ToString.h> 00034 #include <utils/iodevices/OutputDevice.h> 00035 #include "MSMeanData_HBEFA.h" 00036 #include <utils/common/HelpersHBEFA.h> 00037 #include <limits> 00038 00039 #ifdef CHECK_MEMORY_LEAKS 00040 #include <foreign/nvwa/debug_new.h> 00041 #endif // CHECK_MEMORY_LEAKS 00042 00043 00044 // =========================================================================== 00045 // method definitions 00046 // =========================================================================== 00047 // --------------------------------------------------------------------------- 00048 // MSMeanData_HBEFA::MSLaneMeanDataValues - methods 00049 // --------------------------------------------------------------------------- 00050 MSMeanData_HBEFA::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane, const SUMOReal length, const bool doAdd, 00051 const std::set<std::string>* const vTypes, 00052 const MSMeanData_HBEFA* parent) throw() 00053 : MSMeanData::MeanDataValues(lane, length, doAdd, vTypes), myParent(parent), CO2(0), CO(0), HC(0), NOx(0), PMx(0), fuel(0) {} 00054 00055 00056 MSMeanData_HBEFA::MSLaneMeanDataValues::~MSLaneMeanDataValues() throw() { 00057 } 00058 00059 00060 void 00061 MSMeanData_HBEFA::MSLaneMeanDataValues::reset(bool) throw() { 00062 sampleSeconds = 0.; 00063 travelledDistance = 0.; 00064 CO2 = 0; 00065 CO = 0; 00066 HC = 0; 00067 NOx = 0; 00068 PMx = 0; 00069 fuel = 0; 00070 } 00071 00072 00073 void 00074 MSMeanData_HBEFA::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const throw() { 00075 MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val; 00076 v.sampleSeconds += sampleSeconds; 00077 v.travelledDistance += travelledDistance; 00078 v.CO2 += CO2; 00079 v.CO += CO; 00080 v.HC += HC; 00081 v.NOx += NOx; 00082 v.PMx += PMx; 00083 v.fuel += fuel; 00084 } 00085 00086 00087 void 00088 MSMeanData_HBEFA::MSLaneMeanDataValues::notifyMoveInternal(SUMOVehicle& veh, SUMOReal timeOnLane, SUMOReal speed) throw() { 00089 sampleSeconds += timeOnLane; 00090 travelledDistance += speed * timeOnLane; 00091 const double a = veh.getPreDawdleAcceleration(); 00092 CO += (timeOnLane * HelpersHBEFA::computeCO(veh.getVehicleType().getEmissionClass(), (double) speed, a)); 00093 CO2 += (timeOnLane * HelpersHBEFA::computeCO2(veh.getVehicleType().getEmissionClass(), (double) speed, a)); 00094 HC += (timeOnLane * HelpersHBEFA::computeHC(veh.getVehicleType().getEmissionClass(), (double) speed, a)); 00095 NOx += (timeOnLane * HelpersHBEFA::computeNOx(veh.getVehicleType().getEmissionClass(), (double) speed, a)); 00096 PMx += (timeOnLane * HelpersHBEFA::computePMx(veh.getVehicleType().getEmissionClass(), (double) speed, a)); 00097 fuel += (timeOnLane * HelpersHBEFA::computeFuel(veh.getVehicleType().getEmissionClass(), (double) speed, a)); 00098 } 00099 00100 00101 void 00102 MSMeanData_HBEFA::MSLaneMeanDataValues::write(OutputDevice& dev, const SUMOTime period, 00103 const SUMOReal /*numLanes*/, const int /*numVehicles*/) const throw(IOError) { 00104 const SUMOReal normFactor = SUMOReal(3600. * 1000. / STEPS2TIME(period) / myLaneLength); 00105 dev << "\" CO_abs=\""<<OutputDevice::realString(CO*1000., 6) << 00106 "\" CO2_abs=\""<<OutputDevice::realString(CO2*1000., 6) << 00107 "\" HC_abs=\""<<OutputDevice::realString(HC*1000., 6) << 00108 "\" PMx_abs=\""<<OutputDevice::realString(PMx*1000., 6) << 00109 "\" NOx_abs=\""<<OutputDevice::realString(NOx*1000., 6) << 00110 "\" fuel_abs=\""<<OutputDevice::realString(fuel*1000., 6) << 00111 "\"\n CO_normed=\""<<OutputDevice::realString(normFactor * CO, 6) << 00112 "\" CO2_normed=\""<<OutputDevice::realString(normFactor * CO2, 6)<< 00113 "\" HC_normed=\""<<OutputDevice::realString(normFactor * HC, 6) << 00114 "\" PMx_normed=\""<<OutputDevice::realString(normFactor * PMx, 6) << 00115 "\" NOx_normed=\""<<OutputDevice::realString(normFactor * NOx, 6) << 00116 "\" fuel_normed=\""<<OutputDevice::realString(normFactor * fuel, 6); 00117 if (sampleSeconds > myParent->myMinSamples) { 00118 SUMOReal vehFactor = myParent->myMaxTravelTime / sampleSeconds; 00119 SUMOReal traveltime = myParent->myMaxTravelTime; 00120 if (travelledDistance > 0.f) { 00121 vehFactor = MIN2(vehFactor, myLaneLength / travelledDistance); 00122 traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance); 00123 } 00124 dev<<"\"\n traveltime=\"" << OutputDevice::realString(traveltime)<< 00125 "\" CO_perVeh=\""<<OutputDevice::realString(CO*vehFactor, 6)<< 00126 "\" CO2_perVeh=\""<<OutputDevice::realString(CO2*vehFactor, 6)<< 00127 "\" HC_perVeh=\""<<OutputDevice::realString(HC*vehFactor, 6)<< 00128 "\" PMx_perVeh=\""<<OutputDevice::realString(PMx*vehFactor, 6)<< 00129 "\" NOx_perVeh=\""<<OutputDevice::realString(NOx*vehFactor, 6)<< 00130 "\" fuel_perVeh=\""<<OutputDevice::realString(fuel*vehFactor, 6); 00131 } 00132 dev<<"\"/>\n"; 00133 } 00134 00135 00136 00137 // --------------------------------------------------------------------------- 00138 // MSMeanData_HBEFA - methods 00139 // --------------------------------------------------------------------------- 00140 MSMeanData_HBEFA::MSMeanData_HBEFA(const std::string& id, 00141 const SUMOTime dumpBegin, const SUMOTime dumpEnd, 00142 const bool useLanes, const bool withEmpty, const bool withInternal, 00143 const bool trackVehicles, 00144 const SUMOReal maxTravelTime, const SUMOReal minSamples, 00145 const std::set<std::string> vTypes) throw() 00146 : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, withInternal, trackVehicles, maxTravelTime, minSamples, vTypes) { 00147 } 00148 00149 00150 MSMeanData_HBEFA::~MSMeanData_HBEFA() throw() {} 00151 00152 00153 MSMeanData::MeanDataValues* 00154 MSMeanData_HBEFA::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const throw(IOError) { 00155 return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this); 00156 } 00157 00158 00159 /****************************************************************************/ 00160