![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <WNS/distribution/CDFTable.hpp> 00029 #include <WNS/module/Base.hpp> 00030 #include <WNS/Interval.hpp> 00031 #include <WNS/container/RangeMap.hpp> 00032 00033 using namespace wns::distribution; 00034 00035 STATIC_FACTORY_REGISTER_WITH_CREATOR(CDFTable, Distribution, "CDFTable", wns::PyConfigViewCreator); 00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(CDFTable, Distribution, "CDFTable", wns::distribution::RNGConfigCreator); 00037 00038 typedef wns::Interval<double> CDFRange; 00039 00040 CDFTable::CDFTable(const pyconfig::View& config) : 00041 Distribution(), 00042 dis_(getRNG()), 00043 mean_(0.0) 00044 { 00045 int tableLen = config.len("cdfTable"); 00046 assure(tableLen>0, "empty cdfTable"); 00047 double lastCdfValue=0.0; 00048 for (int ii=0; ii<tableLen; ++ii) 00049 { 00050 std::stringstream index; 00051 index << ii; 00052 std::string subviewName = "cdfTable" + std::string("[") + index.str() + std::string("]"); 00053 double rnValue = config.get<double>(subviewName, 0); 00054 double cdfValue = config.get<double>(subviewName,1); 00055 mean_ += rnValue * (cdfValue - lastCdfValue); 00056 CDFRange cdfInterval = CDFRange::FromExcluding(lastCdfValue).ToIncluding(cdfValue); 00057 rangeMap_.insert(cdfInterval, rnValue); 00058 lastCdfValue = cdfValue; 00059 } 00060 } 00061 00062 CDFTable::CDFTable(wns::rng::RNGen* rng, const pyconfig::View& config) : 00063 Distribution(rng), 00064 dis_(getRNG()), 00065 mean_(0.0) 00066 { 00067 int tableLen = config.len("cdfTable"); 00068 assure(tableLen>0, "empty cdfTable"); 00069 double lastCdfValue=0.0; 00070 for (int ii=0; ii<tableLen; ++ii) 00071 { 00072 std::stringstream index; 00073 index << ii; 00074 std::string subviewName = "cdfTable" + std::string("[") + index.str() + std::string("]"); 00075 double rnValue = config.get<double>(subviewName, 0); 00076 double cdfValue = config.get<double>(subviewName,1); 00077 mean_ += rnValue * (cdfValue - lastCdfValue); 00078 CDFRange cdfInterval = CDFRange::FromExcluding(lastCdfValue).ToIncluding(cdfValue); 00079 rangeMap_.insert(cdfInterval, rnValue); 00080 lastCdfValue = cdfValue; 00081 } 00082 } 00083 00084 CDFTable::~CDFTable() 00085 { 00086 } 00087 00088 double 00089 CDFTable::operator()() 00090 { 00091 return rangeMap_.get(dis_()); 00092 } 00093 00094 double 00095 CDFTable::getMean() const 00096 { 00097 return mean_; 00098 } 00099 00100 std::string 00101 CDFTable::paramString() const 00102 { 00103 std::ostringstream tmp; 00104 tmp << "CDFTable()"; 00105 return tmp.str(); 00106 } 00107 00108 /* 00109 Local Variables: 00110 mode: c++ 00111 fill-column: 80 00112 c-basic-offset: 8 00113 c-comment-only-line-offset: 0 00114 c-tab-always-indent: t 00115 indent-tabs-mode: t 00116 tab-width: 8 00117 End: 00118 */ 00119
1.5.5