00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00046
00047
00048
00049
00050 MSMeanData_HBEFA::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane * const lane, const bool doAdd,
00051 const std::set<std::string>* const vTypes,
00052 const MSMeanData_HBEFA *parent) throw()
00053 : MSMeanData::MeanDataValues(lane, 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() 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 bool
00088 MSMeanData_HBEFA::MSLaneMeanDataValues::isStillActive(MSVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) throw() {
00089 if (!vehicleApplies(veh)) {
00090 return false;
00091 }
00092 bool ret = true;
00093 SUMOReal timeOnLane = (SUMOReal) DELTA_T / 1000.;
00094 if (oldPos<0&&newSpeed!=0) {
00095 timeOnLane = (oldPos+SPEED2DIST(newSpeed)) / newSpeed;
00096 }
00097 if (oldPos+SPEED2DIST(newSpeed)>getLane()->getLength()&&newSpeed!=0) {
00098 timeOnLane -= (oldPos+SPEED2DIST(newSpeed) - getLane()->getLength()) / newSpeed;
00099 ret = false;
00100 }
00101 if (timeOnLane<0) {
00102 MsgHandler::getErrorInstance()->inform("Negative vehicle step fraction on lane '" + getLane()->getID() + "'.");
00103 return false;
00104 }
00105 if (timeOnLane==0) {
00106 return false;
00107 }
00108 sampleSeconds += timeOnLane;
00109 travelledDistance += newSpeed * timeOnLane;
00110 SUMOReal a = veh.getPreDawdleAcceleration();
00111 CO += (timeOnLane * HelpersHBEFA::computeCO(veh.getVehicleType().getEmissionClass(), (double) newSpeed, (double) a));
00112 CO2 += (timeOnLane * HelpersHBEFA::computeCO2(veh.getVehicleType().getEmissionClass(), (double) newSpeed, (double) a));
00113 HC += (timeOnLane * HelpersHBEFA::computeHC(veh.getVehicleType().getEmissionClass(), (double) newSpeed, (double) a));
00114 NOx += (timeOnLane * HelpersHBEFA::computeNOx(veh.getVehicleType().getEmissionClass(), (double) newSpeed, (double) a));
00115 PMx += (timeOnLane * HelpersHBEFA::computePMx(veh.getVehicleType().getEmissionClass(), (double) newSpeed, (double) a));
00116 fuel += (timeOnLane * HelpersHBEFA::computeFuel(veh.getVehicleType().getEmissionClass(), (double) newSpeed, (double) a));
00117 return ret;
00118 }
00119
00120
00121 void
00122 MSMeanData_HBEFA::MSLaneMeanDataValues::write(OutputDevice &dev, const SUMOTime period,
00123 const SUMOReal numLanes, const SUMOReal length, const int numVehicles) const throw(IOError) {
00124 dev<<std::resetiosflags(std::ios::floatfield);
00125 const SUMOReal normFactor = SUMOReal(3600. * 1000. / STEPS2TIME(period) / length);
00126 dev << "\" CO_abs=\""<<SUMOReal(CO*1000.) <<
00127 "\" CO2_abs=\""<<SUMOReal(CO2*1000.) <<
00128 "\" HC_abs=\""<<SUMOReal(HC*1000.) <<
00129 "\" PMx_abs=\""<<SUMOReal(PMx*1000.) <<
00130 "\" NOx_abs=\""<<SUMOReal(NOx*1000.) <<
00131 "\" fuel_abs=\""<<SUMOReal(fuel*1000.) <<
00132 "\"\n CO_normed=\""<<normFactor * CO <<
00133 "\" CO2_normed=\""<<normFactor * CO2<<
00134 "\" HC_normed=\""<<normFactor * HC <<
00135 "\" PMx_normed=\""<<normFactor * PMx <<
00136 "\" NOx_normed=\""<<normFactor * NOx <<
00137 "\" fuel_normed=\""<<normFactor * fuel;
00138 if (sampleSeconds > myParent->myMinSamples) {
00139 SUMOReal vehFactor = myParent->myMaxTravelTime / sampleSeconds;
00140 SUMOReal traveltime = myParent->myMaxTravelTime;
00141 if (travelledDistance > 0.f) {
00142 vehFactor = MIN2(vehFactor, length / travelledDistance);
00143 traveltime = MIN2(traveltime, length * sampleSeconds / travelledDistance);
00144 }
00145 dev<<"\"\n traveltime=\"" << traveltime<<
00146 "\" CO_perVeh=\""<<CO*vehFactor<<
00147 "\" CO2_perVeh=\""<<CO2*vehFactor<<
00148 "\" HC_perVeh=\""<<HC*vehFactor<<
00149 "\" PMx_perVeh=\""<<PMx*vehFactor<<
00150 "\" NOx_perVeh=\""<<NOx*vehFactor<<
00151 "\" fuel_perVeh=\""<<fuel*vehFactor;
00152 }
00153 dev<<"\"/>\n";
00154 dev<<std::setiosflags(std::ios::fixed);
00155 }
00156
00157
00158
00159
00160
00161
00162 MSMeanData_HBEFA::MSMeanData_HBEFA(const std::string &id,
00163 const SUMOTime dumpBegin, const SUMOTime dumpEnd,
00164 const bool useLanes, const bool withEmpty,
00165 const bool trackVehicles,
00166 const SUMOReal maxTravelTime, const SUMOReal minSamples,
00167 const std::set<std::string> vTypes) throw()
00168 : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, trackVehicles, maxTravelTime, minSamples, vTypes) {
00169 }
00170
00171
00172 MSMeanData_HBEFA::~MSMeanData_HBEFA() throw() {}
00173
00174
00175 MSMeanData::MeanDataValues*
00176 MSMeanData_HBEFA::createValues(MSLane * const lane, const bool doAdd) const throw(IOError) {
00177 return new MSLaneMeanDataValues(lane, doAdd, &myVehicleTypes, this);
00178 }
00179
00180
00181
00182