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-2026 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 resetTime = SIMSTEP;
57}
58
59
60void
63 v.sampleSeconds += sampleSeconds;
64 v.meanNTemp += meanNTemp;
65 v.travelledDistance += travelledDistance;
66}
67
68
69void
71 meanNTemp += currentTimeN;
72 currentTimeN = 0;
73}
74
75
76void
77MSMeanData_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 */) {
79 // XXX: recheck, which value to use here for the speed. (Leo) Refs. #2579
80 (double) meanSpeedVehicleOnLane, veh.getAcceleration());
81 currentTimeN += (double) pow(10., (sn / 10.));
82 sampleSeconds += timeOnLane;
83 travelledDistance += travelledDistanceVehicleOnLane;
84}
85
86
87void
89 const int /*numLanes*/, const double /*speedLimit*/, const double defaultTravelTime, const int /*numVehicles*/) const {
90 const double noise = meanNTemp != 0 ? (double)(10. * log10(meanNTemp * TS / STEPS2TIME(period))) : (double) 0.;
91 dev.writeOptionalAttr(SUMO_ATTR_NOISE, noise, attributeMask);
92 if (sampleSeconds > myParent->myMinSamples) {
93 double traveltime = myParent->myMaxTravelTime;
94 if (travelledDistance > 0.f) {
95 traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
96 }
97 dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, traveltime, attributeMask);
98 } else if (defaultTravelTime >= 0.) {
99 // @todo default value for noise
100 dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, defaultTravelTime, attributeMask);
101 }
102 dev.closeTag();
103}
104
105
106
107// ---------------------------------------------------------------------------
108// MSMeanData_Harmonoise - methods
109// ---------------------------------------------------------------------------
111 const SUMOTime dumpBegin, const SUMOTime dumpEnd,
112 const bool useLanes, const std::string& excludeEmpty, 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 AggregateType aggregate) :
119 MSMeanData(id, dumpBegin, dumpEnd, useLanes, excludeEmpty,
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:58
#define SIMSTEP
Definition SUMOTime.h:64
#define TS
Definition SUMOTime.h:45
std::bitset< 96 > SumoXMLAttrMask
AggregateType
Numbers representing special SUMO-XML-attribute values Information on edgeData/laneData output should...
@ SUMO_ATTR_NOISE
MSMeanData_Harmonoise.
@ SUMO_ATTR_TRAVELTIME
T MIN2(T a, T b)
Definition StdDefs.h:80
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:190
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.
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.
void write(OutputDevice &dev, const SumoXMLAttrMask &attributeMask, const SUMOTime period, const int numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
Noise data collector for edges/lanes.
MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const
Create an instance of MeanDataValues.
MSMeanData_Harmonoise(const std::string &id, const SUMOTime dumpBegin, const SUMOTime dumpEnd, const bool useLanes, const std::string &excludeEmpty, 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, AggregateType aggregate)
Constructor.
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
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:495
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, const SumoXMLAttrMask &attributeMask, const bool isNull=false)
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