JGAP

examples
Class MinimizingFitnessFunctionCached

java.lang.Object
  extended by org.jgap.FitnessFunction
      extended by org.jgap.CachedFitnessFunction
          extended by examples.MinimizingFitnessFunctionCached
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ICloneable

public class MinimizingFitnessFunctionCached
extends CachedFitnessFunction

For any Javadoc see MinimizingMakeChangeFitnessFunction.

Additionally, this fitness function is cached.

Since:
3.2
See Also:
Serialized Form

Field Summary
static int MAX_BOUND
           
 
Fields inherited from class org.jgap.FitnessFunction
DELTA, NO_FITNESS_VALUE
 
Constructor Summary
MinimizingFitnessFunctionCached(int a_targetAmount)
           
 
Method Summary
static int amountOfChange(IChromosome a_potentialSolution)
           
protected  double changeDifferenceBonus(double a_maxFitness, int a_changeDifference)
           
protected  double computeCoinNumberPenalty(double a_maxFitness, int a_coins)
           
 double evaluate(IChromosome a_subject)
          Determine the fitness of the given Chromosome instance.
static int getNumberOfCoinsAtGene(IChromosome a_potentialSolution, int a_position)
           
static int getTotalNumberOfCoins(IChromosome a_potentialsolution)
          Returns the total number of coins represented by all of the genes in the given potential solution.
 
Methods inherited from class org.jgap.CachedFitnessFunction
getBusinessKey, getFitnessValue
 
Methods inherited from class org.jgap.FitnessFunction
clone, getLastComputedFitnessValue
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_BOUND

public static final int MAX_BOUND
See Also:
Constant Field Values
Constructor Detail

MinimizingFitnessFunctionCached

public MinimizingFitnessFunctionCached(int a_targetAmount)
Method Detail

evaluate

public double evaluate(IChromosome a_subject)
Description copied from class: FitnessFunction
Determine the fitness of the given Chromosome instance. The higher the return value, the more fit the instance. This method should always return the same fitness value for two equivalent Chromosome instances.

Specified by:
evaluate in class FitnessFunction
Parameters:
a_subject - the Chromosome instance to evaluate
Returns:
positive double reflecting the fitness rating of the given Chromosome. Note that if a non-positive double is returned, a RuntimeException should be generated

changeDifferenceBonus

protected double changeDifferenceBonus(double a_maxFitness,
                                       int a_changeDifference)

computeCoinNumberPenalty

protected double computeCoinNumberPenalty(double a_maxFitness,
                                          int a_coins)

amountOfChange

public static int amountOfChange(IChromosome a_potentialSolution)

getNumberOfCoinsAtGene

public static int getNumberOfCoinsAtGene(IChromosome a_potentialSolution,
                                         int a_position)

getTotalNumberOfCoins

public static int getTotalNumberOfCoins(IChromosome a_potentialsolution)
Returns the total number of coins represented by all of the genes in the given potential solution.

Parameters:
a_potentialsolution - the potential solution to evaluate
Returns:
total number of coins represented by the given Chromosome
Since:
1.0

JGAP