uchicago.src.repastdemos.genetic
Class MinimizingMakeChangeFitnessFunction

java.lang.Object
  extended by org.jgap.FitnessFunction
      extended by uchicago.src.repastdemos.genetic.MinimizingMakeChangeFitnessFunction
All Implemented Interfaces:
java.io.Serializable

public class MinimizingMakeChangeFitnessFunction
extends org.jgap.FitnessFunction

Sample fitness function for the MakeChange example.

See Also:
Serialized Form

Field Summary
static int DIMES_POS
           
static int NICKELS_POS
           
static int PENNIES_POS
           
static int QUARTERS_POS
           
 
Constructor Summary
MinimizingMakeChangeFitnessFunction(int a_targetAmount)
           
 
Method Summary
static int amountOfChange(org.jgap.Chromosome a_potentialSolution)
          Calculates the total amount of change (in cents) represented by the given potential solution and returns that amount.
 int evaluate(org.jgap.Chromosome a_subject)
          Determine the fitness of the given Chromosome instance.
static CoinStruct getCoinsAtGene(org.jgap.Chromosome potentialSolution)
           
static int getNumberOfCoinsAtGene(org.jgap.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(org.jgap.Chromosome 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
getFitnessValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QUARTERS_POS

public static final int QUARTERS_POS
See Also:
Constant Field Values

DIMES_POS

public static final int DIMES_POS
See Also:
Constant Field Values

NICKELS_POS

public static final int NICKELS_POS
See Also:
Constant Field Values

PENNIES_POS

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

MinimizingMakeChangeFitnessFunction

public MinimizingMakeChangeFitnessFunction(int a_targetAmount)
Method Detail

evaluate

public int evaluate(org.jgap.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 org.jgap.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(org.jgap.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(org.jgap.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.

getCoinsAtGene

public static CoinStruct getCoinsAtGene(org.jgap.Chromosome potentialSolution)

getTotalNumberOfCoins

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