Clover coverage report - JGAP 3.1
Coverage timestamp: Mo Dez 11 2006 21:16:18 CET
file stats: LOC: 100   Methods: 2
NCLOC: 21   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FitnessFunction.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;
 11   
 12    /**
 13    * Fitness functions are used to determine how optimal a particular solution
 14    * is relative to other solutions. This abstract class should be extended and
 15    * the evaluate() method implemented. The fitness function is given a Chromosome
 16    * to evaluate and should return a positive double that reflects its fitness
 17    * value. The higher the value, the more fit the Chromosome. The actual range
 18    * of fitness values isn't important (other than the fact that they must be
 19    * positive doubles): it's the relative difference as a percentage that
 20    * tends to determine the success or failure of a Chromosome. So in other words,
 21    * two Chromosomes with respective fitness values of 1 and 100 have the same
 22    * relative fitness to each other as two Chromosomes with respective fitness
 23    * values of 10 and 1000 (in each case, the first is 1% as fit as the second).
 24    * <p>
 25    * Note: Two Chromosomes with equivalent sets of genes should always be
 26    * assigned the same fitness value by any implementation of this interface.
 27    *
 28    * @author Neil Rotstan
 29    * @author Klaus Meffert
 30    * @since 1.0
 31    */
 32    public abstract class FitnessFunction
 33    implements java.io.Serializable {
 34    /** String containing the CVS revision. Read out via reflection!*/
 35    private final static String CVS_REVISION = "$Revision: 1.18 $";
 36   
 37    public final static double NO_FITNESS_VALUE = -1.0000000d;
 38   
 39    /**
 40    * The fitness value computed during the previous run
 41    */
 42    private double m_lastComputedFitnessValue = NO_FITNESS_VALUE;
 43   
 44    /**
 45    * Retrieves the fitness value of the given Chromosome. The fitness
 46    * value will be a positive double.
 47    *
 48    * @param a_subject the Chromosome for which to compute and return the
 49    * fitness value
 50    * @return the fitness value of the given Chromosome
 51    *
 52    * @author Neil Rotstan
 53    * @author Klaus Meffert
 54    * @since 2.0 (until 1.1: return type int)
 55    */
 56  6719 public final double getFitnessValue(final IChromosome a_subject) {
 57    // Delegate to the evaluate() method to actually compute the
 58    // fitness value. If the returned value is less than one,
 59    // then we throw a runtime exception.
 60    // ---------------------------------------------------------
 61  6719 double fitnessValue = evaluate(a_subject);
 62  6719 if (fitnessValue < 0.00000000d) {
 63  1 throw new RuntimeException(
 64    "Fitness values must be positive! Received value: "
 65    + fitnessValue);
 66    }
 67  6718 m_lastComputedFitnessValue = fitnessValue;
 68  6718 return fitnessValue;
 69    }
 70   
 71    /**
 72    * @return the last fitness value computed via method getFitnessValue(
 73    * Chromosome), or NO_FITNES_VALUE if the former method has not been called
 74    * yet
 75    *
 76    * @author Klaus Meffert
 77    * @since 2.4
 78    */
 79  2 public double getLastComputedFitnessValue() {
 80  2 return m_lastComputedFitnessValue;
 81    }
 82   
 83    /**
 84    * Determine the fitness of the given Chromosome instance. The higher the
 85    * return value, the more fit the instance. This method should always
 86    * return the same fitness value for two equivalent Chromosome instances.
 87    *
 88    * @param a_subject the Chromosome instance to evaluate
 89    *
 90    * @return positive double reflecting the fitness rating of the given
 91    * Chromosome. Note that if a non-positive double is returned, a
 92    * RuntimeException should be generated
 93    *
 94    * @author Neil Rotstan
 95    * @author Klaus Meffert
 96    * @since 2.0 (until 1.1: return type int)
 97    */
 98    protected abstract double evaluate(IChromosome a_subject);
 99   
 100    }