User Manual, Developers Guide and API Documentation

Geometric.cpp

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

Generated on Thu May 24 03:31:35 2012 for openWNS by  doxygen 1.5.5