examples
Class MinimizingMakeChangeFitnessFunction

java.lang.Object
  extended by org.jgap.FitnessFunction
      extended by examples.MinimizingMakeChangeFitnessFunction
All Implemented Interfaces:
java.io.Serializable

public class MinimizingMakeChangeFitnessFunction
extends FitnessFunction

Sample fitness function for the MakeChange example.

See Also:
Serialized Form

Constructor Summary
MinimizingMakeChangeFitnessFunction(int a_targetAmount)
          ctor
 
Method Summary
static int amountOfChange(Chromosome a_potentialSolution)
          Calculates the total amount of change (in cents) represented by the given potential solution and returns that amount.
 int evaluate(Chromosome a_subject)
          Determine the fitness of the given Chromosome instance.
static int getNumberOfCoinsAtGene(Chromosome a_potentialSolution, int a_position)
          Retrieves the number of coins represented by the given potential solution at the given gene position.
static int getTotalNumberOfCoins(Chromosome a_potentialsolution)
          Returns the total number of coins represented by all of the genes in the given potential solution.
 void init(java.util.Properties newProps)
           
 
Methods inherited from class org.jgap.FitnessFunction
getFitnessValue, getMaxFitnessValue, setMaxFitnessValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MinimizingMakeChangeFitnessFunction

public MinimizingMakeChangeFitnessFunction(int a_targetAmount)
ctor

Parameters:
a_targetAmount -
Method Detail

evaluate

public int evaluate(Chromosome 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:
A positive integer reflecting the fitness rating of the given Chromosome.

amountOfChange

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

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

getNumberOfCoinsAtGene

public static int getNumberOfCoinsAtGene(Chromosome 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.

getTotalNumberOfCoins

public static int getTotalNumberOfCoins(Chromosome 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.

init

public void init(java.util.Properties newProps)
Specified by:
init in class FitnessFunction
Parameters:
newProps - configuration parameters
See Also:
FitnessFunction.init(java.util.Properties)