SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSMeanData_HBEFA.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Emission data collector for edges/lanes
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
11 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
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 <microsim/MSNet.h>
33 #include <microsim/MSLane.h>
34 #include <microsim/MSVehicle.h>
35 #include <utils/common/SUMOTime.h>
36 #include <utils/common/ToString.h>
38 #include "MSMeanData_HBEFA.h"
40 #include <limits>
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 // ---------------------------------------------------------------------------
51 // MSMeanData_HBEFA::MSLaneMeanDataValues - methods
52 // ---------------------------------------------------------------------------
54  const std::set<std::string>* const vTypes,
55  const MSMeanData_HBEFA* parent)
56  : MSMeanData::MeanDataValues(lane, length, doAdd, vTypes), myParent(parent), CO2(0), CO(0), HC(0), NOx(0), PMx(0), fuel(0) {}
57 
58 
60 }
61 
62 
63 void
65  sampleSeconds = 0.;
66  travelledDistance = 0.;
67  CO2 = 0;
68  CO = 0;
69  HC = 0;
70  NOx = 0;
71  PMx = 0;
72  fuel = 0;
73 }
74 
75 
76 void
79  v.sampleSeconds += sampleSeconds;
80  v.travelledDistance += travelledDistance;
81  v.CO2 += CO2;
82  v.CO += CO;
83  v.HC += HC;
84  v.NOx += NOx;
85  v.PMx += PMx;
86  v.fuel += fuel;
87 }
88 
89 
90 void
92  sampleSeconds += timeOnLane;
93  travelledDistance += speed * timeOnLane;
94  const double a = veh.getPreDawdleAcceleration();
95  CO += (timeOnLane * HelpersHBEFA::computeCO(veh.getVehicleType().getEmissionClass(), (double) speed, a));
96  CO2 += (timeOnLane * HelpersHBEFA::computeCO2(veh.getVehicleType().getEmissionClass(), (double) speed, a));
97  HC += (timeOnLane * HelpersHBEFA::computeHC(veh.getVehicleType().getEmissionClass(), (double) speed, a));
98  NOx += (timeOnLane * HelpersHBEFA::computeNOx(veh.getVehicleType().getEmissionClass(), (double) speed, a));
99  PMx += (timeOnLane * HelpersHBEFA::computePMx(veh.getVehicleType().getEmissionClass(), (double) speed, a));
100  fuel += (timeOnLane * HelpersHBEFA::computeFuel(veh.getVehicleType().getEmissionClass(), (double) speed, a));
101 }
102 
103 
104 void
106  const SUMOReal /*numLanes*/, const SUMOReal defaultTravelTime, const int /*numVehicles*/) const {
107  const SUMOReal normFactor = SUMOReal(3600. / STEPS2TIME(period) / myLaneLength);
108  dev << "\" CO_abs=\"" << OutputDevice::realString(CO, 6) <<
109  "\" CO2_abs=\"" << OutputDevice::realString(CO2, 6) <<
110  "\" HC_abs=\"" << OutputDevice::realString(HC, 6) <<
111  "\" PMx_abs=\"" << OutputDevice::realString(PMx, 6) <<
112  "\" NOx_abs=\"" << OutputDevice::realString(NOx, 6) <<
113  "\" fuel_abs=\"" << OutputDevice::realString(fuel, 6) <<
114  "\"\n CO_normed=\"" << OutputDevice::realString(normFactor * CO, 6) <<
115  "\" CO2_normed=\"" << OutputDevice::realString(normFactor * CO2, 6) <<
116  "\" HC_normed=\"" << OutputDevice::realString(normFactor * HC, 6) <<
117  "\" PMx_normed=\"" << OutputDevice::realString(normFactor * PMx, 6) <<
118  "\" NOx_normed=\"" << OutputDevice::realString(normFactor * NOx, 6) <<
119  "\" fuel_normed=\"" << OutputDevice::realString(normFactor * fuel, 6);
120  if (sampleSeconds > myParent->myMinSamples) {
121  SUMOReal vehFactor = myParent->myMaxTravelTime / sampleSeconds;
122  SUMOReal traveltime = myParent->myMaxTravelTime;
123  if (travelledDistance > 0.f) {
124  vehFactor = MIN2(vehFactor, myLaneLength / travelledDistance);
125  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
126  }
127  dev << "\"\n traveltime=\"" << OutputDevice::realString(traveltime) <<
128  "\" CO_perVeh=\"" << OutputDevice::realString(CO * vehFactor, 6) <<
129  "\" CO2_perVeh=\"" << OutputDevice::realString(CO2 * vehFactor, 6) <<
130  "\" HC_perVeh=\"" << OutputDevice::realString(HC * vehFactor, 6) <<
131  "\" PMx_perVeh=\"" << OutputDevice::realString(PMx * vehFactor, 6) <<
132  "\" NOx_perVeh=\"" << OutputDevice::realString(NOx * vehFactor, 6) <<
133  "\" fuel_perVeh=\"" << OutputDevice::realString(fuel * vehFactor, 6);
134  } else if (defaultTravelTime >= 0.) {
136  const SUMOReal speed = MIN2(myLaneLength / defaultTravelTime, t->getMaxSpeed());
137  dev << "\"\n traveltime=\"" << OutputDevice::realString(defaultTravelTime) <<
138  "\" CO_perVeh=\"" << OutputDevice::realString(HelpersHBEFA::computeDefaultCO(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), defaultTravelTime), 6) <<
139  "\" CO2_perVeh=\"" << OutputDevice::realString(HelpersHBEFA::computeDefaultCO2(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), defaultTravelTime), 6) <<
140  "\" HC_perVeh=\"" << OutputDevice::realString(HelpersHBEFA::computeDefaultHC(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), defaultTravelTime), 6) <<
141  "\" PMx_perVeh=\"" << OutputDevice::realString(HelpersHBEFA::computeDefaultPMx(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), defaultTravelTime), 6) <<
142  "\" NOx_perVeh=\"" << OutputDevice::realString(HelpersHBEFA::computeDefaultNOx(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), defaultTravelTime), 6) <<
143  "\" fuel_perVeh=\"" << OutputDevice::realString(HelpersHBEFA::computeDefaultFuel(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), defaultTravelTime), 6);
144  }
145  dev << "\"";
146  dev.closeTag(true);
147 }
148 
149 
150 
151 // ---------------------------------------------------------------------------
152 // MSMeanData_HBEFA - methods
153 // ---------------------------------------------------------------------------
155  const SUMOTime dumpBegin,
156  const SUMOTime dumpEnd,
157  const bool useLanes, const bool withEmpty,
158  const bool printDefaults,
159  const bool withInternal,
160  const bool trackVehicles,
161  const SUMOReal maxTravelTime,
162  const SUMOReal minSamples,
163  const std::set<std::string> vTypes)
164  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
165  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes) {
166 }
167 
168 
170 
171 
173 MSMeanData_HBEFA::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
174  return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this);
175 }
176 
177 
178 /****************************************************************************/