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