Clover coverage report - JGAP 3.1
Coverage timestamp: Mo Dez 11 2006 21:16:18 CET
file stats: LOC: 125   Methods: 11
NCLOC: 53   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CauchyRandomGenerator.java - 100% 100% 100%
coverage
 1    /*
 2    * This file is part of JGAP.
 3    *
 4    * JGAP offers a dual license model containing the LGPL as well as the MPL.
 5    *
 6    * For licencing information please see the file license.txt included with JGAP
 7    * or have a look at the top of class org.jgap.Chromosome which representatively
 8    * includes the JGAP license policy applicable for any file delivered with JGAP.
 9    */
 10    package org.jgap.impl;
 11   
 12    import java.util.*;
 13    import java.io.*;
 14   
 15    import org.jgap.*;
 16   
 17    /**
 18    * Cauchy probability density function (cumulative distribution function).
 19    *
 20    * @author Klaus Meffert
 21    * @since 1.1
 22    */
 23    public class CauchyRandomGenerator
 24    implements RandomGenerator {
 25    /** String containing the CVS revision. Read out via reflection!*/
 26    private final static String CVS_REVISION = "$Revision: 1.13 $";
 27   
 28    private double m_scale;
 29   
 30    private double m_location;
 31   
 32    private Random m_rn;
 33   
 34    /**
 35    * Defaults to location = 0.0 and scale = 1.0.
 36    *
 37    * @author Klaus Meffert
 38    * @since 1.1
 39    */
 40  2 public CauchyRandomGenerator() {
 41  2 this(0.0d, 1.0d);
 42    }
 43   
 44    /**
 45    * @param a_location cauchy parameter
 46    * @param a_scale cauchy parameter
 47    *
 48    * @author Klaus Meffert
 49    * @since 1.1
 50    */
 51  5 public CauchyRandomGenerator(final double a_location, final double a_scale) {
 52  5 m_location = a_location;
 53  5 m_scale = a_scale;
 54  5 m_rn = new Random();
 55    }
 56   
 57  2 public int nextInt() {
 58  2 return Math.min(Integer.MAX_VALUE - 1,
 59    (int) Math.round(nextCauchy() * Integer.MAX_VALUE));
 60    }
 61   
 62  2 public int nextInt(final int a_ceiling) {
 63  2 return Math.min(a_ceiling - 1,
 64    (int) Math.round(nextCauchy() * a_ceiling));
 65    }
 66   
 67  1 public long nextLong() {
 68  1 return Math.min(Long.MAX_VALUE - 1,
 69    Math.round(nextCauchy() * Long.MAX_VALUE));
 70    }
 71   
 72  1 public double nextDouble() {
 73  1 return nextCauchy();
 74    }
 75   
 76  1 public float nextFloat() {
 77  1 return Math.min(Float.MAX_VALUE - 1,
 78    (float) (nextCauchy() * Float.MAX_VALUE));
 79    }
 80   
 81  1 public boolean nextBoolean() {
 82  1 return nextCauchy() >= 0.5d;
 83    }
 84   
 85    /**
 86    * Calculate Cumulative Cauchy distribution function.
 87    * @return the probability that a stochastic variable x is less than X
 88    *
 89    * @author Klaus Meffert
 90    * @since 1.1
 91    */
 92  9 public double nextCauchy() {
 93  9 return 0.5
 94    + Math.atan( (m_rn.nextDouble() - m_location) / m_scale) / Math.PI;
 95    }
 96   
 97    /**
 98    * @return the cauchy standard deviation
 99    *
 100    * @author Klaus Meffert
 101    * @since 1.1
 102    */
 103  1 public double getCauchyStandardDeviation() {
 104  1 return m_scale;
 105    }
 106   
 107    /**
 108    * When deserializing, initialize the seed because otherwise we could get
 109    * duplicate evolution results when doing distributed computing!
 110    *
 111    * @param a_inputStream the ObjectInputStream provided for deserialzation
 112    *
 113    * @throws IOException
 114    * @throws ClassNotFoundException
 115    *
 116    * @author Klaus Meffert
 117    * @since 3.01
 118    */
 119  1 private void readObject(ObjectInputStream a_inputStream)
 120    throws IOException, ClassNotFoundException {
 121    //always perform the default de-serialization first
 122  1 a_inputStream.defaultReadObject();
 123  1 m_rn.setSeed(System.currentTimeMillis());
 124    }
 125    }