|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.vizzini.ai.geneticalgorithm.AbstractGeneticAlgorithm
org.vizzini.ai.geneticprogramming.AbstractGeneticAlgorithmGP
org.vizzini.example.tictactoe.TicTacToeGeneticAlgorithmGP
public class TicTacToeGeneticAlgorithmGP
Provides a genetic programming algorithm to create agents for a tic-tac-toe game.
Field Summary |
---|
Fields inherited from class org.vizzini.ai.geneticalgorithm.AbstractGeneticAlgorithm |
---|
_crossoverFraction, _crossoverType, _elapsedTime, _generation |
Constructor Summary | |
---|---|
TicTacToeGeneticAlgorithmGP(boolean isBoardPrinted)
Construct this object. |
Method Summary | |
---|---|
protected void |
configureAgent(IComputerAgent agent,
IChromosomeGP chromosome)
Configure the given agent for play. |
protected IComputerAgent |
createAgent0()
Create agent 0. |
protected IComputerAgent |
createAgent1()
Create agent 1. |
protected IGame |
createGame()
Create the game. |
protected void |
evaluateFitness()
Evaluate the fitnesses of the chromosomes in the population. |
protected int |
evaluateFitness(int index,
IChromosomeGP chromosome,
boolean isPrinting)
Evaluate the fitness of the given chromosome for this problem. |
protected int |
getCoverage(IFunction function)
Return a count of the number of positions on the grid board which are referenced by the given function. |
protected IGame |
getGame()
|
protected String |
getGamePropertiesPath()
Return the game properties path. |
int |
getMinTrialCount()
|
protected Class |
getReturnType()
Return the overall return type for the chromosomes. |
boolean |
isVerbose()
|
static void |
main(String[] args)
Application method. |
protected void |
rewardAndPunish(IChromosome chromosome0,
IChromosome chromosome1)
Reward and punish the given chromosomes. |
protected void |
setAgent0(IComputerAgent agent)
Set the first agent. |
protected void |
setAgent1(IComputerAgent agent)
Set the second agent. |
protected void |
setGame(IGame game)
Set the game. |
void |
setMinTrialCount(int minTrialCount)
|
void |
setVerbose(boolean isVerbose)
|
void |
writeReport()
Write a report. |
protected void |
writeStats(Writer writer,
int localGens)
Write statistics using the given parameters. |
protected void |
writeStatsHeader(Writer writer)
Write a header for the statistics. |
Methods inherited from class org.vizzini.ai.geneticprogramming.AbstractGeneticAlgorithmGP |
---|
addFunction, addTerminal, createChromosome, getContext, getFunctionCount, getFunctionGenerator, getInitialMaxDepth, getTerminalCount, isSimpleBetter, onePointCrossover, penalizeComplexity, setContext, setInitialMaxDepth, setSimpleBetter |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.vizzini.ai.geneticalgorithm.IGeneticAlgorithm |
---|
getCrossoverFraction, getCrossoverType, getElapsedTime, getGeneration, getMostFit, getMutationFraction, getMutationMagnitude, getMutationRate, getPopulationSize, getProcessingRate, reset, runGenerations, setAverageCrossoverFraction, setCrossoverFraction, setCrossoverType, setDuplicateAllowed, setMutationFraction, setMutationMagnitude, setMutationRate, setPopulationSize |
Constructor Detail |
---|
public TicTacToeGeneticAlgorithmGP(boolean isBoardPrinted) throws IOException, InstantiationException, IllegalAccessException
IOException
InstantiationException
IllegalAccessException
Method Detail |
---|
public static void main(String[] args) throws Exception
args
- 0-population size (optional)Exception
public int getMinTrialCount()
public boolean isVerbose()
public void setMinTrialCount(int minTrialCount)
minTrialCount
- the minTrialCount to setpublic void setVerbose(boolean isVerbose)
isVerbose
- the isVerbose to setpublic void writeReport()
writeReport
in interface IGeneticAlgorithm
writeReport
in class AbstractGeneticAlgorithm
protected void configureAgent(IComputerAgent agent, IChromosomeGP chromosome)
protected IComputerAgent createAgent0()
protected IComputerAgent createAgent1()
protected IGame createGame() throws InstantiationException, IllegalAccessException
InstantiationException
IllegalAccessException
protected void evaluateFitness()
evaluateFitness
in class AbstractGeneticAlgorithmGP
protected int evaluateFitness(int index, IChromosomeGP chromosome, boolean isPrinting)
evaluateFitness
in class AbstractGeneticAlgorithmGP
index
- Index of the chromosome in the population.chromosome
- Chromosome.isPrinting
- Flag indicating if the method should print.protected int getCoverage(IFunction function)
function
- Function.protected IGame getGame()
protected String getGamePropertiesPath()
protected Class getReturnType()
getReturnType
in class AbstractGeneticAlgorithmGP
protected void rewardAndPunish(IChromosome chromosome0, IChromosome chromosome1)
protected void setAgent0(IComputerAgent agent)
protected void setAgent1(IComputerAgent agent)
protected void setGame(IGame game)
protected void writeStats(Writer writer, int localGens)
writeStats
in class AbstractGeneticAlgorithm
writer
- Writer.localGens
- Current generation.protected void writeStatsHeader(Writer writer)
writeStatsHeader
in class AbstractGeneticAlgorithm
writer
- Writer.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2007 Vizzini.org. All Rights Reserved. | 2007.12.25.03.00.02 |