|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A device which collects vehicular emissions (using HBEFA-reformulation) 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 // included modules 00022 // =========================================================================== 00023 #ifdef _MSC_VER 00024 #include <windows_config.h> 00025 #else 00026 #include <config.h> 00027 #endif 00028 00029 #include "MSDevice_HBEFA.h" 00030 #include <microsim/MSNet.h> 00031 #include <microsim/MSLane.h> 00032 #include <microsim/MSVehicleControl.h> 00033 #include <utils/options/OptionsCont.h> 00034 #include <utils/common/HelpersHBEFA.h> 00035 #include <utils/iodevices/OutputDevice.h> 00036 00037 #ifdef CHECK_MEMORY_LEAKS 00038 #include <foreign/nvwa/debug_new.h> 00039 #endif // CHECK_MEMORY_LEAKS 00040 00041 00042 // =========================================================================== 00043 // method definitions 00044 // =========================================================================== 00045 // --------------------------------------------------------------------------- 00046 // static initialisation methods 00047 // --------------------------------------------------------------------------- 00048 void 00049 MSDevice_HBEFA::insertOptions() throw() { 00050 OptionsCont& oc = OptionsCont::getOptions(); 00051 oc.addOptionSubTopic("Emissions"); 00052 00053 oc.doRegister("device.hbefa.probability", new Option_Float(0.)); 00054 oc.addDescription("device.hbefa.probability", "Emissions", "The probability for a vehicle to have an emission logging device"); 00055 00056 oc.doRegister("device.hbefa.explicit", new Option_String()); 00057 oc.addSynonyme("device.hbefa.explicit", "device.hbefa.knownveh", true); 00058 oc.addDescription("device.hbefa.explicit", "Emissions", "Assign a device to named vehicles"); 00059 00060 oc.doRegister("device.hbefa.deterministic", new Option_Bool(false)); 00061 oc.addDescription("device.hbefa.deterministic", "Emissions", "The devices are set deterministic using a fraction of 1000"); 00062 } 00063 00064 00065 void 00066 MSDevice_HBEFA::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*> &into) throw() { 00067 OptionsCont& oc = OptionsCont::getOptions(); 00068 if (oc.getFloat("device.hbefa.probability")==0 && !oc.isSet("device.hbefa.explicit")) { 00069 // no route computation is modelled 00070 return; 00071 } 00072 // route computation is enabled 00073 bool haveByNumber = false; 00074 if (oc.getBool("device.hbefa.deterministic")) { 00075 haveByNumber = MSNet::getInstance()->getVehicleControl().isInQuota(oc.getFloat("device.hbefa.probability")); 00076 } else { 00077 haveByNumber = RandHelper::rand()<=oc.getFloat("device.hbefa.probability"); 00078 } 00079 bool haveByName = oc.isSet("device.hbefa.explicit") && OptionsCont::getOptions().isInStringVector("device.hbefa.explicit", v.getID()); 00080 if (haveByNumber||haveByName) { 00081 // build the device 00082 MSDevice_HBEFA* device = new MSDevice_HBEFA(v, "hbefa_" + v.getID()); 00083 into.push_back(device); 00084 } 00085 } 00086 00087 00088 // --------------------------------------------------------------------------- 00089 // MSDevice_HBEFA-methods 00090 // --------------------------------------------------------------------------- 00091 MSDevice_HBEFA::MSDevice_HBEFA(SUMOVehicle& holder, const std::string& id) throw() 00092 : MSDevice(holder, id), 00093 myCO2(0), myCO(0), myHC(0), myPMx(0), myNOx(0), myFuel(0) { 00094 } 00095 00096 00097 MSDevice_HBEFA::~MSDevice_HBEFA() throw() { 00098 } 00099 00100 00101 bool 00102 MSDevice_HBEFA::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal newSpeed) throw() { 00103 SUMOEmissionClass c = veh.getVehicleType().getEmissionClass(); 00104 SUMOReal a = veh.getPreDawdleAcceleration(); 00105 myCO2 += HelpersHBEFA::computeCO2(c, newSpeed, a); 00106 myCO += HelpersHBEFA::computeCO(c, newSpeed, a); 00107 myHC += HelpersHBEFA::computeHC(c, newSpeed, a); 00108 myPMx += HelpersHBEFA::computePMx(c, newSpeed, a); 00109 myNOx += HelpersHBEFA::computeNOx(c, newSpeed, a); 00110 myFuel += HelpersHBEFA::computeFuel(c, newSpeed, a); 00111 return true; 00112 } 00113 00114 00115 void 00116 MSDevice_HBEFA::generateOutput() const throw(IOError) { 00117 OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output"); 00118 (os.openTag("emissions") << 00119 " CO_abs=\"" << OutputDevice::realString(myCO, 6) << 00120 "\" CO2_abs=\"" << OutputDevice::realString(myCO2, 6) << 00121 "\" HC_abs=\"" << OutputDevice::realString(myHC, 6) << 00122 "\" PMx_abs=\""<< OutputDevice::realString(myPMx, 6) << 00123 "\" NOx_abs=\""<< OutputDevice::realString(myNOx, 6) << 00124 "\" fuel_abs=\""<< OutputDevice::realString(myFuel, 6) << 00125 "\"").closeTag(true); 00126 } 00127 00128 00129 00130 /****************************************************************************/ 00131