JGAP

examples.supergene
Class AbstractSupergeneTest

java.lang.Object
  extended by examples.supergene.AbstractSupergeneTest
Direct Known Subclasses:
SupergeneSample

public abstract class AbstractSupergeneTest
extends java.lang.Object

Abstract class for testing Supergene performance.

Since:
2.0

Field Summary
static int DIMES
          Gene index for the dimes gene
static boolean EXISTING_SOLUTIONS_ONLY
          If set to true (required for strict tests), only tasks with existing solutions will be submitted as a test tasks.
static int MAX_ALLOWED_EVOLUTIONS
          The total number of times we'll let the population evolve.
static int NICKELS
          Gene index for the nickels gene Only used in the alternative presentation
static int PENNIES
          Gene index for the pennies gene.
static int POPULATION_SIZE
          Chromosome size.
static int QUARTERS
          Gene index for the quarters gene.
static boolean REPORT_ENABLED
           
 
Constructor Summary
AbstractSupergeneTest()
           
 
Method Summary
static int amountOfChange(int a_numQuarters, int a_numDimes, int a_numNickels, int a_numPennies)
          Compute the money value from the coin information.
protected  Gene getDimesGene(Configuration a_conf)
           
protected  Gene getNickelsGene(Configuration a_conf)
           
protected  Gene getPenniesGene(Configuration a_conf)
           
protected  Gene getQuartersGene(Configuration a_conf)
           
abstract  int makeChangeForAmount(int a_targetChangeAmount)
          Executes the genetic algorithm to determine the minimum number of coins necessary to make up the given target amount of change.
 IChromosome report(SupergeneChangeFitnessFunction a_fitnessFunction, Genotype a_population)
          Write report on eveluation to the given stream.
protected  int solve(Configuration a_conf, int a_targetChangeAmount, SupergeneChangeFitnessFunction a_fitnessFunction, Gene[] a_sampleGenes)
          Find and print the solution, return the solution error.
 int test()
          Test the method, returns the sum of all differences between the required and obtained excange amount.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIMES

public static final int DIMES
Gene index for the dimes gene

See Also:
Constant Field Values

QUARTERS

public static final int QUARTERS
Gene index for the quarters gene.

See Also:
Constant Field Values

NICKELS

public static final int NICKELS
Gene index for the nickels gene Only used in the alternative presentation

See Also:
Constant Field Values

PENNIES

public static final int PENNIES
Gene index for the pennies gene. Only used in the alternative presentation

See Also:
Constant Field Values

MAX_ALLOWED_EVOLUTIONS

public static int MAX_ALLOWED_EVOLUTIONS
The total number of times we'll let the population evolve.


POPULATION_SIZE

public static int POPULATION_SIZE
Chromosome size.


REPORT_ENABLED

public static boolean REPORT_ENABLED

EXISTING_SOLUTIONS_ONLY

public static boolean EXISTING_SOLUTIONS_ONLY
If set to true (required for strict tests), only tasks with existing solutions will be submitted as a test tasks.

Constructor Detail

AbstractSupergeneTest

public AbstractSupergeneTest()
Method Detail

getDimesGene

protected Gene getDimesGene(Configuration a_conf)
Parameters:
a_conf - the configuration to use
Returns:
created Dimes gene instance

getNickelsGene

protected Gene getNickelsGene(Configuration a_conf)
Parameters:
a_conf - the configuration to use
Returns:
created Nickels gene instance

getPenniesGene

protected Gene getPenniesGene(Configuration a_conf)
Parameters:
a_conf - the configuration to use
Returns:
created Pennies (1) gene instance

getQuartersGene

protected Gene getQuartersGene(Configuration a_conf)
Parameters:
a_conf - the configuration to use
Returns:
created Quarters gene instance

amountOfChange

public static int amountOfChange(int a_numQuarters,
                                 int a_numDimes,
                                 int a_numNickels,
                                 int a_numPennies)
Compute the money value from the coin information.


makeChangeForAmount

public abstract int makeChangeForAmount(int a_targetChangeAmount)
                                 throws java.lang.Exception
Executes the genetic algorithm to determine the minimum number of coins necessary to make up the given target amount of change. The solution will then be written to System.out.

Parameters:
a_targetChangeAmount - the target amount of change for which this method is attempting to produce the minimum number of coins
Returns:
absolute difference between the required and computed change amount
Throws:
java.lang.Exception

report

public IChromosome report(SupergeneChangeFitnessFunction a_fitnessFunction,
                          Genotype a_population)
Write report on eveluation to the given stream.

Parameters:
a_fitnessFunction - p_SupergeneChangeFitnessFunction
a_population - Genotype
Returns:
Chromosome

test

public int test()
Test the method, returns the sum of all differences between the required and obtained excange amount. One exception counts as 1000 on the error score.


solve

protected int solve(Configuration a_conf,
                    int a_targetChangeAmount,
                    SupergeneChangeFitnessFunction a_fitnessFunction,
                    Gene[] a_sampleGenes)
             throws InvalidConfigurationException
Find and print the solution, return the solution error.

Parameters:
a_conf - the configuration to use
Returns:
absolute difference between the required and computed change
Throws:
InvalidConfigurationException

JGAP