SUMO - Simulation of Urban MObility
MSDevice_HBEFA.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // A device which collects vehicular emissions (using HBEFA-reformulation)
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
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 "MSDevice_HBEFA.h"
00033 #include <microsim/MSNet.h>
00034 #include <microsim/MSLane.h>
00035 #include <microsim/MSVehicleControl.h>
00036 #include <utils/options/OptionsCont.h>
00037 #include <utils/common/HelpersHBEFA.h>
00038 #include <utils/iodevices/OutputDevice.h>
00039 
00040 #ifdef CHECK_MEMORY_LEAKS
00041 #include <foreign/nvwa/debug_new.h>
00042 #endif // CHECK_MEMORY_LEAKS
00043 
00044 
00045 // ===========================================================================
00046 // method definitions
00047 // ===========================================================================
00048 // ---------------------------------------------------------------------------
00049 // static initialisation methods
00050 // ---------------------------------------------------------------------------
00051 void
00052 MSDevice_HBEFA::insertOptions() {
00053     OptionsCont& oc = OptionsCont::getOptions();
00054     oc.addOptionSubTopic("Emissions");
00055 
00056     oc.doRegister("device.hbefa.probability", new Option_Float(0.));
00057     oc.addDescription("device.hbefa.probability", "Emissions", "The probability for a vehicle to have an emission logging device");
00058 
00059     oc.doRegister("device.hbefa.explicit", new Option_String());
00060     oc.addSynonyme("device.hbefa.explicit", "device.hbefa.knownveh", true);
00061     oc.addDescription("device.hbefa.explicit", "Emissions", "Assign a device to named vehicles");
00062 
00063     oc.doRegister("device.hbefa.deterministic", new Option_Bool(false)); 
00064     oc.addDescription("device.hbefa.deterministic", "Emissions", "The devices are set deterministic using a fraction of 1000");
00065 }
00066 
00067 
00068 void
00069 MSDevice_HBEFA::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*> &into) {
00070     OptionsCont& oc = OptionsCont::getOptions();
00071     if (oc.getFloat("device.hbefa.probability") == 0 && !oc.isSet("device.hbefa.explicit")) {
00072         // no route computation is modelled
00073         return;
00074     }
00075     // route computation is enabled
00076     bool haveByNumber = false;
00077     if (oc.getBool("device.hbefa.deterministic")) {
00078         haveByNumber = MSNet::getInstance()->getVehicleControl().isInQuota(oc.getFloat("device.hbefa.probability"));
00079     } else {
00080         haveByNumber = RandHelper::rand() <= oc.getFloat("device.hbefa.probability");
00081     }
00082     bool haveByName = oc.isSet("device.hbefa.explicit") && OptionsCont::getOptions().isInStringVector("device.hbefa.explicit", v.getID());
00083     if (haveByNumber || haveByName) {
00084         // build the device
00085         MSDevice_HBEFA* device = new MSDevice_HBEFA(v, "hbefa_" + v.getID());
00086         into.push_back(device);
00087     }
00088 }
00089 
00090 
00091 // ---------------------------------------------------------------------------
00092 // MSDevice_HBEFA-methods
00093 // ---------------------------------------------------------------------------
00094 MSDevice_HBEFA::MSDevice_HBEFA(SUMOVehicle& holder, const std::string& id)
00095     : MSDevice(holder, id),
00096       myCO2(0), myCO(0), myHC(0), myPMx(0), myNOx(0), myFuel(0) {
00097 }
00098 
00099 
00100 MSDevice_HBEFA::~MSDevice_HBEFA() {
00101 }
00102 
00103 
00104 bool
00105 MSDevice_HBEFA::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal newSpeed) {
00106     const SUMOEmissionClass c = veh.getVehicleType().getEmissionClass();
00107     const SUMOReal a = veh.getPreDawdleAcceleration();
00108     myCO2 += TS * HelpersHBEFA::computeCO2(c, newSpeed, a);
00109     myCO += TS * HelpersHBEFA::computeCO(c, newSpeed, a);
00110     myHC += TS * HelpersHBEFA::computeHC(c, newSpeed, a);
00111     myPMx += TS * HelpersHBEFA::computePMx(c, newSpeed, a);
00112     myNOx += TS * HelpersHBEFA::computeNOx(c, newSpeed, a);
00113     myFuel += TS * HelpersHBEFA::computeFuel(c, newSpeed, a);
00114     return true;
00115 }
00116 
00117 
00118 void
00119 MSDevice_HBEFA::generateOutput() const {
00120     OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output");
00121     (os.openTag("emissions") <<
00122      " CO_abs=\"" << OutputDevice::realString(myCO, 6) <<
00123      "\" CO2_abs=\"" << OutputDevice::realString(myCO2, 6) <<
00124      "\" HC_abs=\"" << OutputDevice::realString(myHC, 6) <<
00125      "\" PMx_abs=\"" << OutputDevice::realString(myPMx, 6) <<
00126      "\" NOx_abs=\"" << OutputDevice::realString(myNOx, 6) <<
00127      "\" fuel_abs=\"" << OutputDevice::realString(myFuel, 6) <<
00128      "\"").closeTag(true);
00129 }
00130 
00131 
00132 
00133 /****************************************************************************/
00134 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines