JGAP

examples.supergene
Class AbstractChangeFitnessFunction

java.lang.Object
  extended by org.jgap.FitnessFunction
      extended by examples.supergene.AbstractChangeFitnessFunction
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ICloneable
Direct Known Subclasses:
SupergeneChangeFitnessFunction

public abstract class AbstractChangeFitnessFunction
extends FitnessFunction

Sample fitness function for the MakeChange example, including supergenes.

Since:
2.0
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jgap.FitnessFunction
DELTA, NO_FITNESS_VALUE
 
Constructor Summary
AbstractChangeFitnessFunction(int a_targetAmount)
           
 
Method Summary
 int amountOfChange(IChromosome a_potentialSolution)
          Calculates the total amount of change (in cents) represented by the given potential solution and returns that amount.
 double evaluate(IChromosome a_subject)
          Determine the fitness of the given Chromosome instance.
 int getNumberOfCoinsAtGene(IChromosome a_potentialSolution, int a_code)
          Retrieves the number of coins represented by the given potential solution at the given gene position.
abstract  Gene getResponsibleGene(IChromosome a_chromosome, int a_code)
          Get the gene, responsible for the number of coins, corresponding this code.
 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.FitnessFunction
clone, getFitnessValue, getLastComputedFitnessValue
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractChangeFitnessFunction

public AbstractChangeFitnessFunction(int a_targetAmount)
Method Detail

evaluate

public double evaluate(IChromosome a_subject)
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 integer reflecting the fitness rating of the given Chromosome
Since:
2.0

amountOfChange

public int amountOfChange(IChromosome a_potentialSolution)
Calculates the total amount of change (in cents) represented by the given potential solution and returns that amount.

Parameters:
a_potentialSolution - the potential solution to evaluate
Returns:
the total amount of change (in cents) represented by the given solution

getNumberOfCoinsAtGene

public int getNumberOfCoinsAtGene(IChromosome a_potentialSolution,
                                  int a_code)
Retrieves the number of coins represented by the given potential solution at the given gene position.

Parameters:
a_potentialSolution - the potential solution to evaluate
a_code - index of gene
Returns:
the number of coins represented by the potential solution at the given gene position

getTotalNumberOfCoins

public 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:
the total number of coins represented by the given Chromosome

getResponsibleGene

public abstract Gene getResponsibleGene(IChromosome a_chromosome,
                                        int a_code)
Get the gene, responsible for the number of coins, corresponding this code.

Parameters:
a_chromosome - Chromosome to evaluate
a_code - index of Gene
Returns:
responsible gene

JGAP