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 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     }
00115     dev << "\"/>\n";
00116 }
00117 
00118 
00119 
00120 // ---------------------------------------------------------------------------
00121 // MSMeanData_Harmonoise - methods
00122 // ---------------------------------------------------------------------------
00123 MSMeanData_Harmonoise::MSMeanData_Harmonoise(const std::string& id,
00124         const SUMOTime dumpBegin, const SUMOTime dumpEnd,
00125         const bool useLanes, const bool withEmpty, const bool withInternal,
00126         const bool trackVehicles,
00127         const SUMOReal maxTravelTime, const SUMOReal minSamples,
00128         const std::set<std::string> vTypes)
00129     : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, withInternal, trackVehicles, maxTravelTime, minSamples, vTypes) {
00130 }
00131 
00132 
00133 MSMeanData_Harmonoise::~MSMeanData_Harmonoise() {}
00134 
00135 
00136 MSMeanData::MeanDataValues*
00137 MSMeanData_Harmonoise::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
00138     return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this);
00139 }
00140 
00141 
00142 void
00143 MSMeanData_Harmonoise::detectorUpdate(const SUMOTime step) {
00144     MSMeanData::detectorUpdate(step);
00145     for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i) {
00146         const std::vector<MeanDataValues*> &lm = *i;
00147         for (std::vector<MeanDataValues*>::const_iterator j = lm.begin(); j != lm.end(); ++j) {
00148             (*j)->update();
00149         }
00150     }
00151 }
00152 
00153 
00154 /****************************************************************************/
00155 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines