Line data Source code
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 : /****************************************************************************/
14 : /// @file MSMeanData_Harmonoise.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @date Mon, 10.05.2004
18 : ///
19 : // Redirector for mean data output (net->edgecontrol)
20 : /****************************************************************************/
21 : #include <config.h>
22 :
23 : #include <microsim/MSLane.h>
24 : #include <microsim/MSVehicle.h>
25 : #include <microsim/output/MSDetectorControl.h>
26 : #include <utils/common/SUMOTime.h>
27 : #include <utils/common/ToString.h>
28 : #include <utils/iodevices/OutputDevice.h>
29 : #include "MSMeanData_Harmonoise.h"
30 : #include <utils/emissions/HelpersHarmonoise.h>
31 : #include <limits>
32 :
33 :
34 : // ===========================================================================
35 : // method definitions
36 : // ===========================================================================
37 : // ---------------------------------------------------------------------------
38 : // MSMeanData_Harmonoise::MSLaneMeanDataValues - methods
39 : // ---------------------------------------------------------------------------
40 381100 : MSMeanData_Harmonoise::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane, const double length, const bool doAdd,
41 381100 : const MSMeanData_Harmonoise* parent)
42 : : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
43 381100 : currentTimeN(0), meanNTemp(0), myParent(parent) {}
44 :
45 :
46 762200 : MSMeanData_Harmonoise::MSLaneMeanDataValues::~MSLaneMeanDataValues() {
47 762200 : }
48 :
49 :
50 : void
51 1154608 : MSMeanData_Harmonoise::MSLaneMeanDataValues::reset(bool) {
52 1154608 : sampleSeconds = 0;
53 1154608 : currentTimeN = 0;
54 1154608 : meanNTemp = 0;
55 1154608 : travelledDistance = 0;
56 1154608 : resetTime = SIMSTEP;
57 1154608 : }
58 :
59 :
60 : void
61 363112 : MSMeanData_Harmonoise::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const {
62 : MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val;
63 363112 : v.sampleSeconds += sampleSeconds;
64 363112 : v.meanNTemp += meanNTemp;
65 363112 : v.travelledDistance += travelledDistance;
66 363112 : }
67 :
68 :
69 : void
70 7627152 : MSMeanData_Harmonoise::MSLaneMeanDataValues::update() {
71 7627152 : meanNTemp += currentTimeN;
72 7627152 : currentTimeN = 0;
73 7627152 : }
74 :
75 :
76 : void
77 766642 : MSMeanData_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 766642 : const double sn = HelpersHarmonoise::computeNoise(veh.getVehicleType().getEmissionClass(),
79 : // XXX: recheck, which value to use here for the speed. (Leo) Refs. #2579
80 766642 : (double) meanSpeedVehicleOnLane, veh.getAcceleration());
81 766642 : currentTimeN += (double) pow(10., (sn / 10.));
82 766642 : sampleSeconds += timeOnLane;
83 766642 : travelledDistance += travelledDistanceVehicleOnLane;
84 766642 : }
85 :
86 :
87 : void
88 27632 : MSMeanData_Harmonoise::MSLaneMeanDataValues::write(OutputDevice& dev, const SumoXMLAttrMask& attributeMask, const SUMOTime period,
89 : const int /*numLanes*/, const double /*speedLimit*/, const double defaultTravelTime, const int /*numVehicles*/) const {
90 27632 : const double noise = meanNTemp != 0 ? (double)(10. * log10(meanNTemp * TS / STEPS2TIME(period))) : (double) 0.;
91 27632 : dev.writeOptionalAttr(SUMO_ATTR_NOISE, noise, attributeMask);
92 27632 : if (sampleSeconds > myParent->myMinSamples) {
93 25490 : double traveltime = myParent->myMaxTravelTime;
94 25490 : if (travelledDistance > 0.f) {
95 50740 : traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
96 : }
97 25490 : dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, traveltime, attributeMask);
98 2142 : } else if (defaultTravelTime >= 0.) {
99 : // @todo default value for noise
100 1056 : dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, defaultTravelTime, attributeMask);
101 : }
102 27632 : dev.closeTag();
103 27632 : }
104 :
105 :
106 :
107 : // ---------------------------------------------------------------------------
108 : // MSMeanData_Harmonoise - methods
109 : // ---------------------------------------------------------------------------
110 410 : MSMeanData_Harmonoise::MSMeanData_Harmonoise(const std::string& id,
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 410 : AggregateType aggregate) :
119 : MSMeanData(id, dumpBegin, dumpEnd, useLanes, excludeEmpty,
120 410 : withInternal, trackVehicles, 0, maxTravelTime, minSamples, vTypes, writeAttributes, edges, aggregate) {
121 410 : }
122 :
123 :
124 820 : MSMeanData_Harmonoise::~MSMeanData_Harmonoise() {}
125 :
126 :
127 : MSMeanData::MeanDataValues*
128 381100 : MSMeanData_Harmonoise::createValues(MSLane* const lane, const double length, const bool doAdd) const {
129 381100 : return new MSLaneMeanDataValues(lane, length, doAdd, this);
130 : }
131 :
132 :
133 : void
134 206402 : MSMeanData_Harmonoise::detectorUpdate(const SUMOTime step) {
135 206402 : MSMeanData::detectorUpdate(step);
136 7747130 : for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i) {
137 : const std::vector<MeanDataValues*>& lm = *i;
138 15167880 : for (std::vector<MeanDataValues*>::const_iterator j = lm.begin(); j != lm.end(); ++j) {
139 7627152 : (*j)->update();
140 : }
141 : }
142 206402 : }
143 :
144 :
145 : /****************************************************************************/
|