SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
11 // Copyright (C) 2001-2013 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 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 // ---------------------------------------------------------------------------
51 // MSMeanData_Harmonoise::MSLaneMeanDataValues - methods
52 // ---------------------------------------------------------------------------
54  const std::set<std::string>* const vTypes, const MSMeanData_Harmonoise* parent)
55  : MSMeanData::MeanDataValues(lane, length, doAdd, vTypes),
56  currentTimeN(0), meanNTemp(0), myParent(parent) {}
57 
58 
60 }
61 
62 
63 void
65  sampleSeconds = 0;
66  currentTimeN = 0;
67  meanNTemp = 0;
68  travelledDistance = 0;
69 }
70 
71 
72 void
75  v.sampleSeconds += sampleSeconds;
76  v.meanNTemp += (SUMOReal) pow(10., HelpersHarmonoise::sum(meanNTemp) / 10.);
77  v.travelledDistance += travelledDistance;
78 }
79 
80 
81 void
83  meanNTemp += (SUMOReal) pow(10., HelpersHarmonoise::sum(currentTimeN) / 10.);
84  currentTimeN = 0;
85 }
86 
87 
88 void
91  (double) speed, veh.getAcceleration());
92  currentTimeN += (SUMOReal) pow(10., (sn / 10.));
93  sampleSeconds += timeOnLane;
94  travelledDistance += speed * timeOnLane;
95 }
96 
97 
98 bool
100  return vehicleApplies(veh);
101 }
102 
103 
104 void
106  const SUMOReal /*numLanes*/, const SUMOReal defaultTravelTime, const int /*numVehicles*/) const {
107  dev << "\" noise=\"" << (meanNTemp != 0 ? (SUMOReal)(10. * log10(meanNTemp * TS / STEPS2TIME(period))) : (SUMOReal) 0.);
108  if (sampleSeconds > myParent->myMinSamples) {
109  SUMOReal traveltime = myParent->myMaxTravelTime;
110  if (travelledDistance > 0.f) {
111  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
112  }
113  dev << "\" traveltime=\"" << traveltime;
114  } else if (defaultTravelTime >= 0.) {
115  // @todo default value for noise
116  dev << "\" traveltime=\"" << defaultTravelTime;
117  }
118  dev << "\"";
119  dev.closeTag();
120 }
121 
122 
123 
124 // ---------------------------------------------------------------------------
125 // MSMeanData_Harmonoise - methods
126 // ---------------------------------------------------------------------------
128  const SUMOTime dumpBegin, const SUMOTime dumpEnd,
129  const bool useLanes, const bool withEmpty,
130  const bool printDefaults, const bool withInternal,
131  const bool trackVehicles,
132  const SUMOReal maxTravelTime, const SUMOReal minSamples,
133  const std::set<std::string> vTypes)
134  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
135  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes) {
136 }
137 
138 
140 
141 
143 MSMeanData_Harmonoise::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
144  return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this);
145 }
146 
147 
148 void
151  for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i) {
152  const std::vector<MeanDataValues*>& lm = *i;
153  for (std::vector<MeanDataValues*>::const_iterator j = lm.begin(); j != lm.end(); ++j) {
154  (*j)->update();
155  }
156  }
157 }
158 
159 
160 /****************************************************************************/
161 
Data collector for edges/lanes.
Definition: MSMeanData.h:66
void write(OutputDevice &dev, const SUMOTime period, const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
std::vector< std::vector< MeanDataValues * > > myMeasures
Value collectors; sorted by edge, then by lane.
Definition: MSMeanData.h:423
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 SUMOReal minSamples, const SUMOReal maxTravelTime, const std::set< std::string > vTypes)
Constructor.
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
void notifyMoveInternal(SUMOVehicle &veh, SUMOReal timeOnLane, SUMOReal speed)
Internal notification about the vehicle moves.
SUMOReal travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:180
SUMOReal meanNTemp
Sum of produced noise over time (pow(10, (&lt;NOISE&gt;/10.)))
Notification
Definition of a vehicle state.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Computes current emission values and adds them to their sums.
const std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
Definition: MSMeanData.h:420
virtual ~MSMeanData_Harmonoise()
Destructor.
#define TS
Definition: SUMOTime.h:52
Noise data collector for edges/lanes.
MSLaneMeanDataValues(MSLane *const lane, const SUMOReal length, const bool doAdd, const std::set< std::string > *const vTypes=0, const MSMeanData_Harmonoise *parent=0)
Constructor.
void update()
Computes the noise in the last time step.
static SUMOReal 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 vehicle.
Definition: SUMOVehicle.h:63
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:75
Data structure for mean (aggregated) edge/lane values.
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
T MIN2(T a, T b)
Definition: StdDefs.h:57
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values to this meanData.
MSMeanData::MeanDataValues * createValues(MSLane *const lane, const SUMOReal length, const bool doAdd) const
Create an instance of MeanDataValues.
virtual SUMOReal getAcceleration() const =0
Returns the vehicle&#39;s acceleration.
static SUMOReal sum(SUMOReal val)
Computes the resulting noise.
virtual void detectorUpdate(const SUMOTime step)
Updates the detector.
Definition: MSMeanData.cpp:476
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:221
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
Representation of a lane in the micro simulation.
Definition: MSLane.h:73
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.