Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSMeanData_Harmonoise.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19// Redirector for mean data output (net->edgecontrol)
20/****************************************************************************/
21#include <config.h>
22
23#include <microsim/MSLane.h>
24#include <microsim/MSVehicle.h>
31#include <limits>
32
33
34// ===========================================================================
35// method definitions
36// ===========================================================================
37// ---------------------------------------------------------------------------
38// MSMeanData_Harmonoise::MSLaneMeanDataValues - methods
39// ---------------------------------------------------------------------------
40MSMeanData_Harmonoise::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane, const double length, const bool doAdd,
41 const MSMeanData_Harmonoise* parent)
42 : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
43 currentTimeN(0), meanNTemp(0), myParent(parent) {}
44
45
48
49
50void
52 sampleSeconds = 0;
53 currentTimeN = 0;
54 meanNTemp = 0;
55 travelledDistance = 0;
56}
57
58
59void
62 v.sampleSeconds += sampleSeconds;
63 v.meanNTemp += meanNTemp;
64 v.travelledDistance += travelledDistance;
65}
66
67
68void
70 meanNTemp += currentTimeN;
71 currentTimeN = 0;
72}
73
74
75void
76MSMeanData_Harmonoise::MSLaneMeanDataValues::notifyMoveInternal(const SUMOTrafficObject& veh, const double /* frontOnLane */, const double timeOnLane, const double /*meanSpeedFrontOnLane*/, const double meanSpeedVehicleOnLane, const double /*travelledDistanceFrontOnLane*/, const double travelledDistanceVehicleOnLane, const double /* meanLengthOnLane */) {
78 // XXX: recheck, which value to use here for the speed. (Leo) Refs. #2579
79 (double) meanSpeedVehicleOnLane, veh.getAcceleration());
80 currentTimeN += (double) pow(10., (sn / 10.));
81 sampleSeconds += timeOnLane;
82 travelledDistance += travelledDistanceVehicleOnLane;
83}
84
85
86void
87MSMeanData_Harmonoise::MSLaneMeanDataValues::write(OutputDevice& dev, long long int attributeMask, const SUMOTime period,
88 const double /*numLanes*/, const double /*speedLimit*/, const double defaultTravelTime, const int /*numVehicles*/) const {
89 const double noise = meanNTemp != 0 ? (double)(10. * log10(meanNTemp * TS / STEPS2TIME(period))) : (double) 0.;
90 dev.writeOptionalAttr(SUMO_ATTR_NOISE, noise, attributeMask);
91 if (sampleSeconds > myParent->myMinSamples) {
92 double traveltime = myParent->myMaxTravelTime;
93 if (travelledDistance > 0.f) {
94 traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
95 }
96 dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, traveltime, attributeMask);
97 } else if (defaultTravelTime >= 0.) {
98 // @todo default value for noise
99 dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, defaultTravelTime, attributeMask);
100 }
101 dev.closeTag();
102}
103
104
105
106// ---------------------------------------------------------------------------
107// MSMeanData_Harmonoise - methods
108// ---------------------------------------------------------------------------
110 const SUMOTime dumpBegin, const SUMOTime dumpEnd,
111 const bool useLanes, const bool withEmpty,
112 const bool printDefaults, const bool withInternal,
113 const bool trackVehicles,
114 const double maxTravelTime, const double minSamples,
115 const std::string& vTypes,
116 const std::string& writeAttributes,
117 const std::vector<MSEdge*>& edges,
118 bool aggregate) :
119 MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
120 withInternal, trackVehicles, 0, maxTravelTime, minSamples, vTypes, writeAttributes, edges, aggregate) {
121}
122
123
125
126
128MSMeanData_Harmonoise::createValues(MSLane* const lane, const double length, const bool doAdd) const {
129 return new MSLaneMeanDataValues(lane, length, doAdd, this);
130}
131
132
133void
136 for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i) {
137 const std::vector<MeanDataValues*>& lm = *i;
138 for (std::vector<MeanDataValues*>::const_iterator j = lm.begin(); j != lm.end(); ++j) {
139 (*j)->update();
140 }
141 }
142}
143
144
145/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#define TS
Definition SUMOTime.h:42
@ SUMO_ATTR_NOISE
MSMeanData_Harmonoise.
@ SUMO_ATTR_TRAVELTIME
T MIN2(T a, T b)
Definition StdDefs.h:76
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.
Representation of a lane in the micro simulation.
Definition MSLane.h:84
Data structure for mean (aggregated) edge/lane values.
Definition MSMeanData.h:66
double travelledDistance
The sum of the distances the vehicles travelled.
Definition MSMeanData.h:182
Data structure for mean (aggregated) edge/lane values.
void notifyMoveInternal(const SUMOTrafficObject &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.
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
void write(OutputDevice &dev, long long int attributeMask, const SUMOTime period, const double numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
MSLaneMeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData_Harmonoise *parent)
Constructor.
double meanNTemp
Sum of produced noise over time (pow(10, (<NOISE>/10.)))
void update()
Computes the noise in the last time step.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values to this meanData.
Noise data collector for edges/lanes.
MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const
Create an instance of MeanDataValues.
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
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, const std::string &writeAttributes, const std::vector< MSEdge * > &edges, bool aggregate)
Constructor.
virtual ~MSMeanData_Harmonoise()
Destructor.
Data collector for edges/lanes.
Definition MSMeanData.h:57
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition MSMeanData.h:472
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
Static storage of an output device and its base (abstract) implementation.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
OutputDevice & writeOptionalAttr(const SumoXMLAttr attr, const T &val, long long int attributeMask)
writes a named attribute unless filtered
Representation of a vehicle, person, or container.
virtual double getAcceleration() const =0
Returns the object's acceleration.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
static double sn[6]
Definition odrSpiral.cpp:49