SUMO - Simulation of Urban MObility
MSMeanData_Harmonoise.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // Redirector for mean data output (net->edgecontrol)
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <microsim/MSLane.h>
32 #include <microsim/MSVehicle.h>
34 #include <utils/common/SUMOTime.h>
35 #include <utils/common/ToString.h>
37 #include "MSMeanData_Harmonoise.h"
39 #include <limits>
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 // ---------------------------------------------------------------------------
46 // MSMeanData_Harmonoise::MSLaneMeanDataValues - methods
47 // ---------------------------------------------------------------------------
48 MSMeanData_Harmonoise::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane, const double length, const bool doAdd,
49  const MSMeanData_Harmonoise* parent)
50  : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
51  currentTimeN(0), meanNTemp(0), myParent(parent) {}
52 
53 
55 }
56 
57 
58 void
60  sampleSeconds = 0;
61  currentTimeN = 0;
62  meanNTemp = 0;
64 }
65 
66 
67 void
71  v.meanNTemp += (double) pow(10., HelpersHarmonoise::sum(meanNTemp) / 10.);
73 }
74 
75 
76 void
78  meanNTemp += (double) pow(10., HelpersHarmonoise::sum(currentTimeN) / 10.);
79  currentTimeN = 0;
80 }
81 
82 
83 void
84 MSMeanData_Harmonoise::MSLaneMeanDataValues::notifyMoveInternal(const SUMOVehicle& veh, const double /* frontOnLane */, const double timeOnLane, const double /*meanSpeedFrontOnLane*/, const double meanSpeedVehicleOnLane, const double /*travelledDistanceFrontOnLane*/, const double travelledDistanceVehicleOnLane, const double /* meanLengthOnLane */) {
86  // XXX: recheck, which value to use here for the speed. (Leo) Refs. #2579
87  (double) meanSpeedVehicleOnLane, veh.getAcceleration());
88  currentTimeN += (double) pow(10., (sn / 10.));
89  sampleSeconds += timeOnLane;
90  travelledDistance += travelledDistanceVehicleOnLane;
91 }
92 
93 
94 void
96  const double /*numLanes*/, const double defaultTravelTime, const int /*numVehicles*/) const {
97  dev.writeAttr("noise", (meanNTemp != 0 ? (double)(10. * log10(meanNTemp * TS / STEPS2TIME(period))) : (double) 0.));
99  double traveltime = myParent->myMaxTravelTime;
100  if (travelledDistance > 0.f) {
101  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
102  }
103  dev.writeAttr("traveltime", traveltime);
104  } else if (defaultTravelTime >= 0.) {
105  // @todo default value for noise
106  dev.writeAttr("traveltime", defaultTravelTime);
107  }
108  dev.closeTag();
109 }
110 
111 
112 
113 // ---------------------------------------------------------------------------
114 // MSMeanData_Harmonoise - methods
115 // ---------------------------------------------------------------------------
117  const SUMOTime dumpBegin, const SUMOTime dumpEnd,
118  const bool useLanes, const bool withEmpty,
119  const bool printDefaults, const bool withInternal,
120  const bool trackVehicles,
121  const double maxTravelTime, const double minSamples,
122  const std::string& vTypes)
123  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
124  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes) {
125 }
126 
127 
129 
130 
132 MSMeanData_Harmonoise::createValues(MSLane* const lane, const double length, const bool doAdd) const {
133  return new MSLaneMeanDataValues(lane, length, doAdd, this);
134 }
135 
136 
137 void
140  for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i) {
141  const std::vector<MeanDataValues*>& lm = *i;
142  for (std::vector<MeanDataValues*>::const_iterator j = lm.begin(); j != lm.end(); ++j) {
143  (*j)->update();
144  }
145  }
146 }
147 
148 
149 /****************************************************************************/
150 
const MSMeanData_Harmonoise * myParent
The meandata parent.
Data collector for edges/lanes.
Definition: MSMeanData.h:66
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:434
const double myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:431
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
void write(OutputDevice &dev, const SUMOTime period, const double numLanes, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
static double computeNoise(SUMOEmissionClass c, double v, double a)
Returns the noise produced by the a vehicle of the given type at the given speed. ...
virtual ~MSMeanData_Harmonoise()
Destructor.
MSMeanData_Harmonoise(const std::string &id, const SUMOTime dumpBegin, const SUMOTime dumpEnd, const bool useLanes, const bool withEmpty, const bool printDefaults, const bool withInternal, const bool trackVehicles, const double minSamples, const double maxTravelTime, const std::string &vTypes)
Constructor.
#define TS
Definition: SUMOTime.h:51
Noise data collector for edges/lanes.
MSLaneMeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData_Harmonoise *parent)
Constructor.
void update()
Computes the noise in the last time step.
double travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:182
Representation of a vehicle.
Definition: SUMOVehicle.h:66
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:75
MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const
Create an instance of MeanDataValues.
Data structure for mean (aggregated) edge/lane values.
static double sn[6]
Definition: odrSpiral.cpp:44
void notifyMoveInternal(const SUMOVehicle &veh, const double, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double)
Internal notification about the vehicle moves.
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
T MIN2(T a, T b)
Definition: StdDefs.h:67
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
const double myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:174
const double myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:428
double meanNTemp
Sum of produced noise over time (pow(10, (<NOISE>/10.)))
void addTo(MSMeanData::MeanDataValues &val) const
Add the values to this meanData.
double currentTimeN
Sum of produced noise at this time step(pow(10, (<NOISE>/10.)))
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
Definition: MSMeanData.cpp:645
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
long long int SUMOTime
Definition: TraCIDefs.h:51
static double sum(double val)
Computes the resulting noise.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
virtual double getAcceleration() const =0
Returns the vehicle&#39;s acceleration.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.