All Downloads are FREE. Search and download functionalities are using the official Maven repository.

umontreal.iro.lecuyer.randvar.ErlangConvolutionGen Maven / Gradle / Ivy

Go to download

SSJ is a Java library for stochastic simulation, developed under the direction of Pierre L'Ecuyer, in the Département d'Informatique et de Recherche Opérationnelle (DIRO), at the Université de Montréal. It provides facilities for generating uniform and nonuniform random variates, computing different measures related to probability distributions, performing goodness-of-fit tests, applying quasi-Monte Carlo methods, collecting (elementary) statistics, and programming discrete-event simulations with both events and processes.

The newest version!


/*
 * Class:        ErlangConvolutionGen
 * Description:  Erlang random variate generators using the convolution method
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Université de Montréal
 * Organization: DIRO, Université de Montréal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   GPL licence site.
 */

package umontreal.iro.lecuyer.randvar;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;


/**
 * This class implements Erlang random variate generators using
 * the convolution method.  This method uses inversion to
 * generate k exponential variates with parameter λ and returns
 * their sum.
 * 
 */
public class ErlangConvolutionGen extends ErlangGen  {


   /**
    * Creates an Erlang random variate generator with parameters
    *  k and λ = lambda,
    *   using stream s.
    * 
    */
   public ErlangConvolutionGen (RandomStream s, int k, double lambda)  {
      super (s, null);
      setParams (k, lambda);
   }


   /**
    * Creates an Erlang random variate generator with parameters
    *  k and 
    * λ = 1, using stream s.
    * 
    */
   public ErlangConvolutionGen (RandomStream s, int k)  {
      this (s, k, 1.0);
   }

 
   /**
    * Creates a new generator for the distribution dist
    *     and stream s.
    * 
    */
   public ErlangConvolutionGen (RandomStream s, ErlangDist dist)  {
      super (s, dist);
      if (dist != null)
         setParams (dist.getK(), dist.getLambda());
   }
 

   public double nextDouble() {
      return convolution (stream, k, lambda);
   }

   public static double nextDouble (RandomStream s, int k, double lambda) {
      return convolution (s, k, lambda);
   }

   private static double convolution (RandomStream s, int k, double lambda) {
      double x = 0.0;
      for (int i=0;  i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy