![]() |
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/Poisson.hpp> 00029 00030 #include <WNS/module/Base.hpp> 00031 00032 using namespace wns::distribution; 00033 00034 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00035 Poisson, 00036 Distribution, 00037 "Poisson", 00038 wns::PyConfigViewCreator); 00039 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00040 Poisson, 00041 Distribution, 00042 "Poisson", 00043 wns::distribution::RNGConfigCreator); 00044 00045 Poisson::Poisson(double mean, wns::rng::RNGen* rng) : 00046 Distribution(rng), 00047 mean_(mean), 00048 dis_(getRNG()) 00049 { 00050 } 00051 00052 Poisson::Poisson(const pyconfig::View& config) : 00053 Distribution(), 00054 mean_(config.get<double>("mean")), 00055 dis_(getRNG()) 00056 { 00057 } 00058 00059 Poisson::Poisson(wns::rng::RNGen* rng, const pyconfig::View& config) : 00060 Distribution(rng), 00061 mean_(config.get<double>("mean")), 00062 dis_(getRNG()) 00063 { 00064 } 00065 00066 00067 Poisson::~Poisson() 00068 { 00069 } 00070 00071 00072 double 00073 Poisson::operator()() 00074 { 00075 double product; 00076 double bound = exp(-1.0 * mean_); 00077 int16_t i = 0; 00078 00079 for (product = 1.0; product >= bound; product *= dis_()) 00080 { 00081 i++; 00082 } 00083 return i - 1; 00084 } 00085 00086 00087 double 00088 Poisson::getMean() const 00089 { 00090 return mean_; 00091 } 00092 00093 00094 std::string 00095 Poisson::paramString() const 00096 { 00097 std::ostringstream tmp; 00098 tmp << "Poisson(mean=" << this->getMean() <<")"; 00099 return tmp.str(); 00100 } 00101 00102 /* 00103 Local Variables: 00104 mode: c++ 00105 fill-column: 80 00106 c-basic-offset: 8 00107 c-comment-only-line-offset: 0 00108 c-tab-always-indent: t 00109 indent-tabs-mode: t 00110 tab-width: 8 00111 End: 00112 */ 00113
1.5.5