SUMO - Simulation of Urban MObility

MSMeanData_Harmonoise.cpp

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