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