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 2001-2010 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 bool doAdd,
00052         const std::set<std::string>* const vTypes, const MSMeanData_Harmonoise *parent) throw()
00053         : MSMeanData::MeanDataValues(lane, 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() 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 bool
00087 MSMeanData_Harmonoise::MSLaneMeanDataValues::isStillActive(MSVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) throw() {
00088     if (!vehicleApplies(veh)) {
00089         return false;
00090     }
00091     bool ret = true;
00092     SUMOReal timeOnLane = TS;
00093     if (oldPos<0&&newSpeed!=0) {
00094         timeOnLane = (oldPos+SPEED2DIST(newSpeed)) / newSpeed;
00095     }
00096     if (oldPos+SPEED2DIST(newSpeed)>getLane()->getLength()&&newSpeed!=0) {
00097         timeOnLane -= (oldPos+SPEED2DIST(newSpeed) - getLane()->getLength()) / newSpeed;
00098         ret = false;
00099     }
00100     if (timeOnLane<0) {
00101         MsgHandler::getErrorInstance()->inform("Negative vehicle step fraction on lane '" + getLane()->getID() + "'.");
00102         return false;
00103     }
00104     if (timeOnLane==0) {
00105         return false;
00106     }
00107     SUMOReal a = veh.getPreDawdleAcceleration();
00108     SUMOReal sn = HelpersHarmonoise::computeNoise(veh.getVehicleType().getEmissionClass(), (double) newSpeed, (double) a);
00109     currentTimeN += (SUMOReal) pow(10., (sn/10.));
00110     sampleSeconds += timeOnLane;
00111     travelledDistance += newSpeed * timeOnLane;
00112     return ret;
00113 }
00114 
00115 
00116 bool
00117 MSMeanData_Harmonoise::MSLaneMeanDataValues::notifyEnter(MSVehicle& veh, bool isEmit, bool isLaneChange) throw() {
00118     return vehicleApplies(veh);
00119 }
00120 
00121 
00122 void
00123 MSMeanData_Harmonoise::MSLaneMeanDataValues::write(OutputDevice &dev, const SUMOTime period,
00124         const SUMOReal numLanes, const SUMOReal length, const int numVehicles) const throw(IOError) {
00125     dev << "\" noise=\"" << (meanNTemp!=0 ? (SUMOReal)(10. * log10(meanNTemp*TS/STEPS2TIME(period))) : (SUMOReal) 0.);
00126     if (sampleSeconds > myParent->myMinSamples) {
00127         SUMOReal traveltime = myParent->myMaxTravelTime;
00128         if (travelledDistance > 0.f) {
00129             traveltime = MIN2(traveltime, length * sampleSeconds / travelledDistance);
00130         }
00131         dev << "\" traveltime=\"" << traveltime;
00132     }
00133     dev << "\"/>\n";
00134 }
00135 
00136 
00137 
00138 // ---------------------------------------------------------------------------
00139 // MSMeanData_Harmonoise - methods
00140 // ---------------------------------------------------------------------------
00141 MSMeanData_Harmonoise::MSMeanData_Harmonoise(const std::string &id,
00142         const SUMOTime dumpBegin, const SUMOTime dumpEnd,
00143         const bool useLanes, const bool withEmpty,
00144         const bool trackVehicles,
00145         const SUMOReal maxTravelTime, const SUMOReal minSamples,
00146         const std::set<std::string> vTypes) throw()
00147         : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, trackVehicles, maxTravelTime, minSamples, vTypes) {
00148     MSNet::getInstance()->getDetectorControl().add(this);
00149 }
00150 
00151 
00152 MSMeanData_Harmonoise::~MSMeanData_Harmonoise() throw() {}
00153 
00154 
00155 MSMeanData::MeanDataValues*
00156 MSMeanData_Harmonoise::createValues(MSLane * const lane, const bool doAdd) const throw(IOError) {
00157     return new MSLaneMeanDataValues(lane, doAdd, &myVehicleTypes, this);
00158 }
00159 
00160 
00161 /****************************************************************************/
00162 

Generated on Wed May 5 00:06:32 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6