SUMO - Simulation of Urban MObility
MSMeanData_Harmonoise.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // Redirector for mean data output (net->edgecontrol)
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <microsim/MSLane.h>
00033 #include <microsim/MSVehicle.h>
00034 #include <microsim/output/MSDetectorControl.h>
00035 #include <utils/common/SUMOTime.h>
00036 #include <utils/common/ToString.h>
00037 #include <utils/iodevices/OutputDevice.h>
00038 #include "MSMeanData_Harmonoise.h"
00039 #include <utils/common/HelpersHarmonoise.h>
00040 #include <limits>
00041 
00042 #ifdef CHECK_MEMORY_LEAKS
00043 #include <foreign/nvwa/debug_new.h>
00044 #endif // CHECK_MEMORY_LEAKS
00045 
00046 
00047 // ===========================================================================
00048 // method definitions
00049 // ===========================================================================
00050 // ---------------------------------------------------------------------------
00051 // MSMeanData_Harmonoise::MSLaneMeanDataValues - methods
00052 // ---------------------------------------------------------------------------
00053 MSMeanData_Harmonoise::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane, const SUMOReal length, const bool doAdd,
00054         const std::set<std::string>* const vTypes, const MSMeanData_Harmonoise* parent)
00055     : MSMeanData::MeanDataValues(lane, length, doAdd, vTypes),
00056       currentTimeN(0), meanNTemp(0), myParent(parent) {}
00057 
00058 
00059 MSMeanData_Harmonoise::MSLaneMeanDataValues::~MSLaneMeanDataValues() {
00060 }
00061 
00062 
00063 void
00064 MSMeanData_Harmonoise::MSLaneMeanDataValues::reset(bool) {
00065     sampleSeconds = 0;
00066     currentTimeN = 0;
00067     meanNTemp = 0;
00068     travelledDistance = 0;
00069 }
00070 
00071 
00072 void
00073 MSMeanData_Harmonoise::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const {
00074     MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val;
00075     v.sampleSeconds += sampleSeconds;
00076     v.meanNTemp += (SUMOReal) pow(10., HelpersHarmonoise::sum(meanNTemp) / 10.);
00077     v.travelledDistance += travelledDistance;
00078 }
00079 
00080 
00081 void
00082 MSMeanData_Harmonoise::MSLaneMeanDataValues::update() {
00083     meanNTemp += (SUMOReal) pow(10., HelpersHarmonoise::sum(currentTimeN) / 10.);
00084     currentTimeN = 0;
00085 }
00086 
00087 
00088 void
00089 MSMeanData_Harmonoise::MSLaneMeanDataValues::notifyMoveInternal(SUMOVehicle& veh, SUMOReal timeOnLane, SUMOReal speed) {
00090     const SUMOReal sn = HelpersHarmonoise::computeNoise(veh.getVehicleType().getEmissionClass(),
00091                         (double) speed, veh.getPreDawdleAcceleration());
00092     currentTimeN += (SUMOReal) pow(10., (sn / 10.));
00093     sampleSeconds += timeOnLane;
00094     travelledDistance += speed * timeOnLane;
00095 }
00096 
00097 
00098 bool
00099 MSMeanData_Harmonoise::MSLaneMeanDataValues::notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification /*reason*/) {
00100     return vehicleApplies(veh);
00101 }
00102 
00103 
00104 void
00105 MSMeanData_Harmonoise::MSLaneMeanDataValues::write(OutputDevice& dev, const SUMOTime period,
00106         const SUMOReal /*numLanes*/, const SUMOReal defaultTravelTime, const int /*numVehicles*/) const {
00107     dev << "\" noise=\"" << (meanNTemp != 0 ? (SUMOReal)(10. * log10(meanNTemp * TS / STEPS2TIME(period))) : (SUMOReal) 0.);
00108     if (sampleSeconds > myParent->myMinSamples) {
00109         SUMOReal traveltime = myParent->myMaxTravelTime;
00110         if (travelledDistance > 0.f) {
00111             traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
00112         }
00113         dev << "\" traveltime=\"" << traveltime;
00114     } else if (defaultTravelTime >= 0.) {
00115         // @todo default value for noise
00116         dev << "\" traveltime=\"" << defaultTravelTime;
00117     }
00118     dev << "\"";
00119     dev.closeTag(true);
00120 }
00121 
00122 
00123 
00124 // ---------------------------------------------------------------------------
00125 // MSMeanData_Harmonoise - methods
00126 // ---------------------------------------------------------------------------
00127 MSMeanData_Harmonoise::MSMeanData_Harmonoise(const std::string& id,
00128         const SUMOTime dumpBegin, const SUMOTime dumpEnd,
00129         const bool useLanes, const bool withEmpty,
00130         const bool printDefaults, const bool withInternal,
00131         const bool trackVehicles,
00132         const SUMOReal maxTravelTime, const SUMOReal minSamples,
00133         const std::set<std::string> vTypes)
00134     : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
00135                  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes) {
00136 }
00137 
00138 
00139 MSMeanData_Harmonoise::~MSMeanData_Harmonoise() {}
00140 
00141 
00142 MSMeanData::MeanDataValues*
00143 MSMeanData_Harmonoise::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
00144     return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this);
00145 }
00146 
00147 
00148 void
00149 MSMeanData_Harmonoise::detectorUpdate(const SUMOTime step) {
00150     MSMeanData::detectorUpdate(step);
00151     for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i) {
00152         const std::vector<MeanDataValues*> &lm = *i;
00153         for (std::vector<MeanDataValues*>::const_iterator j = lm.begin(); j != lm.end(); ++j) {
00154             (*j)->update();
00155         }
00156     }
00157 }
00158 
00159 
00160 /****************************************************************************/
00161 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines