JGAP

examples.constraint
Class SampleFitnessFunction

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

public class SampleFitnessFunction
extends FitnessFunction

Sample fitness function for the MakeChange example.

Since:
3.6.2
See Also:
Serialized Form

Field Summary
static int MAX_BOUND
           
 
Fields inherited from class org.jgap.FitnessFunction
DELTA, NO_FITNESS_VALUE
 
Constructor Summary
SampleFitnessFunction(int a_targetAmount)
           
 
Method Summary
static double amountOfChange(IChromosome a_potentialSolution)
          Calculates the total amount of change (in cents) represented by the given potential solution and returns that amount.
protected  double changeDifferenceBonus(double a_maxFitness, int a_changeDifference)
          Bonus calculation of fitness value.
protected  double computeCoinNumberPenalty(double a_maxFitness, int a_coins)
          Calculates the penalty to apply to the fitness value based on the ammount of coins in the solution
 double evaluate(IChromosome a_subject)
          Determine the fitness of the given Chromosome instance.
static int getNumberOfCoinsAtGene(IChromosome a_potentialSolution, int a_position)
          Retrieves the number of coins represented by the given potential solution at the given gene 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.FitnessFunction
clone, getFitnessValue, 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

SampleFitnessFunction

public SampleFitnessFunction(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 double reflecting the fitness rating of the given Chromosome
Since:
2.0 (until 1.1: return type int)

changeDifferenceBonus

protected double changeDifferenceBonus(double a_maxFitness,
                                       int a_changeDifference)
Bonus calculation of fitness value.

Parameters:
a_maxFitness - maximum fitness value appliable
a_changeDifference - change difference in coins for the coins problem
Returns:
bonus for given change difference
Since:
2.3

computeCoinNumberPenalty

protected double computeCoinNumberPenalty(double a_maxFitness,
                                          int a_coins)
Calculates the penalty to apply to the fitness value based on the ammount of coins in the solution

Parameters:
a_maxFitness - maximum fitness value allowed
a_coins - number of coins in the solution
Returns:
penalty for the fitness value base on the number of coins
Since:
2.2

amountOfChange

public static double 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
Since:
3.6.2

getNumberOfCoinsAtGene

public static int getNumberOfCoinsAtGene(IChromosome a_potentialSolution,
                                         int a_position)
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_position - the gene position to evaluate
Returns:
the number of coins represented by the potential solution at the given gene position
Since:
3.6.2

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:
3.6.2

JGAP