COIN-OR::LEMON - Graph Library

Ticket #102: 5e1b90e430c2.patch

File 5e1b90e430c2.patch, 1.9 KB (added by Alpar Juttner, 13 years ago)
  • lemon/random.h

    # HG changeset patch
    # User Alpar Juttner <alpar@cs.elte.hu>
    # Date 1213893186 -3600
    # Node ID 5e1b90e430c2d9a6fb0587d2ac004f1f2bcd8b6f
    # Parent  d2bac07f174234a37a21860c8c8a9ed4d14b3415
    Lognormal distribution added
    
    diff --git a/lemon/random.h b/lemon/random.h
    a b  
    841841      return gauss()*std_dev+mean;
    842842    }
    843843
     844    /// Lognormal distribution
     845
     846    /// Lognormal distribution. The parameters are the mean and the standard
     847    /// deviation of <tt>exp(X)</tt>.
     848    ///
     849    double lognormal(double n_mean,double n_std_dev)
     850    {
     851      return std::exp(gauss(n_mean,n_std_dev));
     852    }
     853    /// Lognormal distribution
     854
     855    /// Lognormal distribution. The parameter is an <tt>std::pair</tt> of
     856    /// the mean and the standard deviation of <tt>exp(X)</tt>.
     857    ///
     858    double lognormal(const std::pair<double,double> &params)
     859    {
     860      return std::exp(gauss(params.first,params.second));
     861    }
     862    /// Compute the lognormal parameters from mean and standard deviation
     863
     864    /// This function computes the lognormal parameters from mean and
     865    /// standard deviation. The return value can direcly be passed to
     866    /// lognormal().
     867    std::pair<double,double> lognormalParamsFromMeanStdDev(double mean,
     868                                                           double std_dev)
     869    {
     870      double fr=std_dev/mean;
     871      fr*=fr;
     872      double lg=std::log(1+fr);
     873      return std::pair<double,double>(std::log(mean)-lg/2.0,std::sqrt(lg));
     874    }
     875    /// Lognormal distribution with given mean and standard deviation
     876
     877    /// Lognormal distribution with given mean and standard deviation.
     878    ///
     879    double lognormalMeanStdDev(double mean,double std_dev)
     880    {
     881      return lognormal(lognormalParamsFromMeanStdDev(mean,std_dev));
     882    }
     883   
    844884    /// Exponential distribution with given mean
    845885
    846886    /// This function generates an exponential distribution random number