Clover coverage report - JGAP 3.1
Coverage timestamp: Mo Dez 11 2006 21:16:18 CET
file stats: LOC: 69   Methods: 3
NCLOC: 21   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultMutationRateCalculator.java 100% 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 org.jgap.*;
 13   
 14    /**
 15    * Default implementation of a mutation rate calculcator.
 16    *
 17    * @author Klaus Meffert
 18    * @since 1.1
 19    */
 20    public class DefaultMutationRateCalculator
 21    extends BaseRateCalculator {
 22    /** String containing the CVS revision. Read out via reflection!*/
 23    private final static String CVS_REVISION = "$Revision: 1.16 $";
 24   
 25    /**
 26    * @param a_config the configuration to use
 27    * @throws InvalidConfigurationException
 28    *
 29    * @author Klaus Meffert
 30    * @since 3.0
 31    */
 32  1140 public DefaultMutationRateCalculator(Configuration a_config)
 33    throws InvalidConfigurationException {
 34  1140 super(a_config);
 35    }
 36   
 37    /**
 38    * Calculates the mutation rate.
 39    *
 40    * @return calculated divisor of mutation rate probability (dividend is 1)
 41    *
 42    * @author Klaus Meffert
 43    * @since 1.1 (same functionality as earlier, but not encapsulated)
 44    */
 45  273 public int calculateCurrentRate() {
 46  273 int size = getConfiguration().getChromosomeSize();
 47  273 if (size < 1) {
 48  29 size = 1;
 49    }
 50  273 return size;
 51    }
 52   
 53    /**
 54    * Determines whether mutation is to be carried out. In this case
 55    * the rate is the size of the chromosome. There is therefore a
 56    * probability of 1/totalgenes that a particular gene mutates.
 57    *
 58    * @param a_chrom ignored
 59    * @param a_geneIndex ignored
 60    * @return true if gene should be mutated
 61    *
 62    * @author Chris Knowles
 63    * @since 2.0
 64    */
 65  266 public boolean toBePermutated(IChromosome a_chrom, int a_geneIndex) {
 66  266 RandomGenerator generator = getConfiguration().getRandomGenerator();
 67  266 return (generator.nextInt(calculateCurrentRate()) == 0);
 68    }
 69    }