SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSDevice_HBEFA.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A device which collects vehicular emissions (using HBEFA-reformulation)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include "MSDevice_HBEFA.h"
33 #include <microsim/MSNet.h>
34 #include <microsim/MSLane.h>
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 // ---------------------------------------------------------------------------
49 // static initialisation methods
50 // ---------------------------------------------------------------------------
51 void
54  oc.addOptionSubTopic("Emissions");
55 
56  oc.doRegister("device.hbefa.probability", new Option_Float(0.));
57  oc.addDescription("device.hbefa.probability", "Emissions", "The probability for a vehicle to have an emission logging device");
58 
59  oc.doRegister("device.hbefa.explicit", new Option_String());
60  oc.addSynonyme("device.hbefa.explicit", "device.hbefa.knownveh", true);
61  oc.addDescription("device.hbefa.explicit", "Emissions", "Assign a device to named vehicles");
62 
63  oc.doRegister("device.hbefa.deterministic", new Option_Bool(false));
64  oc.addDescription("device.hbefa.deterministic", "Emissions", "The devices are set deterministic using a fraction of 1000");
65 }
66 
67 
68 void
69 MSDevice_HBEFA::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*> &into) {
71  if (oc.getFloat("device.hbefa.probability") == 0 && !oc.isSet("device.hbefa.explicit")) {
72  // no route computation is modelled
73  return;
74  }
75  // route computation is enabled
76  bool haveByNumber = false;
77  if (oc.getBool("device.hbefa.deterministic")) {
78  haveByNumber = MSNet::getInstance()->getVehicleControl().isInQuota(oc.getFloat("device.hbefa.probability"));
79  } else {
80  haveByNumber = RandHelper::rand() <= oc.getFloat("device.hbefa.probability");
81  }
82  bool haveByName = oc.isSet("device.hbefa.explicit") && OptionsCont::getOptions().isInStringVector("device.hbefa.explicit", v.getID());
83  if (haveByNumber || haveByName) {
84  // build the device
85  MSDevice_HBEFA* device = new MSDevice_HBEFA(v, "hbefa_" + v.getID());
86  into.push_back(device);
87  }
88 }
89 
90 
91 // ---------------------------------------------------------------------------
92 // MSDevice_HBEFA-methods
93 // ---------------------------------------------------------------------------
94 MSDevice_HBEFA::MSDevice_HBEFA(SUMOVehicle& holder, const std::string& id)
95  : MSDevice(holder, id),
96  myCO2(0), myCO(0), myHC(0), myPMx(0), myNOx(0), myFuel(0) {
97 }
98 
99 
101 }
102 
103 
104 bool
105 MSDevice_HBEFA::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal newSpeed) {
107  const SUMOReal a = veh.getPreDawdleAcceleration();
108  myCO2 += TS * HelpersHBEFA::computeCO2(c, newSpeed, a);
109  myCO += TS * HelpersHBEFA::computeCO(c, newSpeed, a);
110  myHC += TS * HelpersHBEFA::computeHC(c, newSpeed, a);
111  myPMx += TS * HelpersHBEFA::computePMx(c, newSpeed, a);
112  myNOx += TS * HelpersHBEFA::computeNOx(c, newSpeed, a);
113  myFuel += TS * HelpersHBEFA::computeFuel(c, newSpeed, a);
114  return true;
115 }
116 
117 
118 void
120  OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output");
121  (os.openTag("emissions") <<
122  " CO_abs=\"" << OutputDevice::realString(myCO, 6) <<
123  "\" CO2_abs=\"" << OutputDevice::realString(myCO2, 6) <<
124  "\" HC_abs=\"" << OutputDevice::realString(myHC, 6) <<
125  "\" PMx_abs=\"" << OutputDevice::realString(myPMx, 6) <<
126  "\" NOx_abs=\"" << OutputDevice::realString(myNOx, 6) <<
127  "\" fuel_abs=\"" << OutputDevice::realString(myFuel, 6) <<
128  "\"").closeTag(true);
129 }
130 
131 
132 
133 /****************************************************************************/
134