SUMO - Simulation of Urban MObility
MSMeanData_Harmonoise.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Redirector for mean data output (net->edgecontrol)
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2017 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/MSLane.h>
33 #include <microsim/MSVehicle.h>
35 #include <utils/common/SUMOTime.h>
36 #include <utils/common/ToString.h>
38 #include "MSMeanData_Harmonoise.h"
40 #include <limits>
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 // ---------------------------------------------------------------------------
47 // MSMeanData_Harmonoise::MSLaneMeanDataValues - methods
48 // ---------------------------------------------------------------------------
49 MSMeanData_Harmonoise::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane, const double length, const bool doAdd,
50  const MSMeanData_Harmonoise* parent)
51  : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
52  currentTimeN(0), meanNTemp(0), myParent(parent) {}
53 
54 
56 }
57 
58 
59 void
61  sampleSeconds = 0;
62  currentTimeN = 0;
63  meanNTemp = 0;
65 }
66 
67 
68 void
72  v.meanNTemp += (double) pow(10., HelpersHarmonoise::sum(meanNTemp) / 10.);
74 }
75 
76 
77 void
79  meanNTemp += (double) pow(10., HelpersHarmonoise::sum(currentTimeN) / 10.);
80  currentTimeN = 0;
81 }
82 
83 
84 void
85 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) {
87  // XXX: recheck, which value to use here for the speed. (Leo) Refs. #2579
88  (double) meanSpeedVehicleOnLane, veh.getAcceleration());
89  currentTimeN += (double) pow(10., (sn / 10.));
90  sampleSeconds += timeOnLane;
91  travelledDistance += travelledDistanceVehicleOnLane;
92 }
93 
94 
95 void
97  const double /*numLanes*/, const double defaultTravelTime, const int /*numVehicles*/) const {
98  dev.writeAttr("noise", (meanNTemp != 0 ? (double)(10. * log10(meanNTemp * TS / STEPS2TIME(period))) : (double) 0.));
100  double traveltime = myParent->myMaxTravelTime;
101  if (travelledDistance > 0.f) {
102  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
103  }
104  dev.writeAttr("traveltime", traveltime);
105  } else if (defaultTravelTime >= 0.) {
106  // @todo default value for noise
107  dev.writeAttr("traveltime", defaultTravelTime);
108  }
109  dev.closeTag();
110 }
111 
112 
113 
114 // ---------------------------------------------------------------------------
115 // MSMeanData_Harmonoise - methods
116 // ---------------------------------------------------------------------------
118  const SUMOTime dumpBegin, const SUMOTime dumpEnd,
119  const bool useLanes, const bool withEmpty,
120  const bool printDefaults, const bool withInternal,
121  const bool trackVehicles,
122  const double maxTravelTime, const double minSamples,
123  const std::string& vTypes)
124  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
125  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes) {
126 }
127 
128 
130 
131 
133 MSMeanData_Harmonoise::createValues(MSLane* const lane, const double length, const bool doAdd) const {
134  return new MSLaneMeanDataValues(lane, length, doAdd, this);
135 }
136 
137 
138 void
141  for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i) {
142  const std::vector<MeanDataValues*>& lm = *i;
143  for (std::vector<MeanDataValues*>::const_iterator j = lm.begin(); j != lm.end(); ++j) {
144  (*j)->update();
145  }
146  }
147 }
148 
149 
150 /****************************************************************************/
151 
const MSMeanData_Harmonoise * myParent
The meandata parent.
Data collector for edges/lanes.
Definition: MSMeanData.h:67
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:435
const double myMaxTravelTime
the maximum travel time to write
Definition: MSMeanData.h:432
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:52
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:183
Representation of a vehicle.
Definition: SUMOVehicle.h:67
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:76
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.
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
T MIN2(T a, T b)
Definition: StdDefs.h:64
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:175
const double myMinSamples
the minimum sample seconds
Definition: MSMeanData.h:429
void notifyMoveInternal(const SUMOVehicle &veh, const double, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane)
Internal notification about the vehicle moves.
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:543
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
long long int SUMOTime
Definition: TraCIDefs.h:52
static double sum(double val)
Computes the resulting noise.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
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.