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