|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--search.GeneticSearch
The GeneticSearch
class implements the genetic search algorithm
as follows:
Field Summary | |
protected double |
avgFitness
|
protected int |
chromosomeLength
|
protected double |
crossoverRate
|
protected boolean |
debugOn
|
protected double |
fitnessThreshold
|
protected java.lang.Class |
geneticObjectClass
|
protected java.lang.String |
geneticObjectClassName
|
protected double |
maxFitness
|
protected int |
maxNumPasses
|
protected double |
minFitness
|
protected double |
mutationRate
|
protected int |
numPasses
|
protected java.util.Hashtable |
operatorFitness
|
protected java.util.Vector |
population
|
protected int |
populationSize
|
protected int |
replacementSize
|
protected double[] |
summedFitness
|
protected double |
totalFitness
|
protected javax.swing.JTextArea |
traceTextArea
|
protected java.lang.String |
vocabulary
|
Constructor Summary | |
GeneticSearch()
Create a genetic search agent. |
Method Summary | |
GeneticSearchObject |
createChild(java.lang.String chromosome)
Creates and initializes a child genetic object from a chromosome if it is unique or, if duplicates are allowed, even if it is not unique. |
GeneticSearchObject[] |
createChildren(java.lang.String[] chromosome)
Creates and initializes new population members based on newly-derived chromosomes. |
protected java.util.Vector |
createNewMembers()
Generates a number of population members through the application of genetic operators. |
protected void |
displayPopulation()
Displays the entire population in the text window. |
protected void |
evaluatePopulation()
Evaluates each population member based on fitness. |
double |
getAvgFitness()
Gets the average raw fitness value for the current population. |
int |
getChromosomeLength()
Gets the length of the chromosome for the current population. |
double |
getCrossoverRate()
Gets the crossover rate. |
double |
getFitnessThreshold()
Gets the raw fitness threshold value. |
java.lang.String |
getGeneticObjectClassName()
Returns the name of the genetic object class. |
double |
getMaxFitness()
Gets the maximum raw fitness value for the current population. |
int |
getMaxNumPasses()
Gets the maximum number of generations to search. |
double |
getMinFitness()
Gets the minimum raw fitness value for the current population. |
double |
getMutationRate()
Get the current mutation rate. |
int |
getNumPasses()
Gets the number of generations that have been searched. |
java.util.Hashtable |
getOperatorFitness()
Gets the supported fitness operators and their fitness values. |
java.util.Vector |
getPopulation()
Gets the entire population. |
int |
getPopulationSize()
Gets the population size. |
int |
getReplacementSize()
Gets the replacement size. |
java.lang.String |
getVocabulary()
Get the chromosome vocabulary. |
void |
init()
Initalizes the popualation. |
protected void |
insertIntoPopulation(GeneticSearchObject newMember,
java.util.Vector list)
Inserts a member into the population according to its raw fitness value. |
protected void |
integratePopulation(java.util.Vector newPopulation)
Adds new members to the population. |
java.lang.String[] |
invokeOperator(java.lang.String operatorName,
java.lang.String[] parents)
Appies an operator to the parent chromosomes to create the child chromosomes. |
java.lang.String[] |
mutate(java.lang.String[] parents)
Mutates two parent chromosomes, subject to the mutation rate, to create two children chromosomes. |
java.lang.String |
mutateChromosome(java.lang.String chromosome)
Mutates a single chromosome by doing a bitwise test against the mutation rate and then rolling the dice to select a new bit value from the vocabulary. |
java.lang.String[] |
onePointCrossover(java.lang.String[] parents)
Given two parent chromosomes, does a single-point crossover, creating two children chromosomes. |
java.lang.String[] |
onePointCrossoverAndMutate(java.lang.String[] parents)
Given two parent chromosomes, does a single-point crossover, creating two children chromosomes and mutating bits at the specified rate |
void |
processOneGeneration()
Processes one generation by evaluating each chromosome and insert it into the population, creating new chromosomes and members using crossover/mutation operators, and deleting members of the old population to make room for new members. |
void |
reset()
Resets the population for another search. |
GeneticSearchObject |
rouletteWheelSelection()
Selects a member of the population using the roulette wheel algorithm. |
void |
search()
Does a complete genetic search by initializing the population then processing the population, one generation at a time until the maximum number of passes are made or the maximum fitness threshold is reached. |
java.lang.String |
selectOperator()
Randomly selects an operator to be applied to the parents. |
GeneticSearchObject[] |
selectParents()
Choose two population members to reproduce using the roulette wheel selection technique. |
void |
setCrossoverRate(double rate)
Sets the crossoverRate which is used when a crossover operator is selected to determine whether a crossover will actually be performed. |
void |
setDebugOn(boolean debugOn)
Sets the debug flag. |
void |
setFitnessThreshold(double thresh)
Sets the raw fitness threshold which is used to halt the search if the raw fitness value exceeds this threshold. |
void |
setGeneticObjectClassName(java.lang.String aClassName)
Sets the name of the class of genetic objects to be searched. |
void |
setMaxNumPasses(int num)
Sets the maximum number of generations to search. |
void |
setMutationRate(double rate)
Sets the mutation rate which is used when a mutate operator is selected to determine whether each bit is mutated or not. |
void |
setOperatorFitness(java.util.Hashtable opFitness)
Sets table of fitness operators and fitness values that are used during reproduction. |
void |
setPopulationSize(int size)
Sets the population size. |
void |
setReplacementSize(int size)
Sets the number of population members to replace in each generation. |
void |
setTextArea(javax.swing.JTextArea j)
Method setTextArea |
protected void |
trace(java.lang.String text)
Writes trace data out to the text window. |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected java.lang.Class geneticObjectClass
protected java.util.Vector population
protected java.util.Hashtable operatorFitness
protected int chromosomeLength
protected java.lang.String vocabulary
protected java.lang.String geneticObjectClassName
protected int maxNumPasses
protected double fitnessThreshold
protected int populationSize
protected int replacementSize
protected double crossoverRate
protected double mutationRate
protected double maxFitness
protected double minFitness
protected double avgFitness
protected double totalFitness
protected double[] summedFitness
protected int numPasses
protected javax.swing.JTextArea traceTextArea
protected boolean debugOn
Constructor Detail |
public GeneticSearch()
Method Detail |
public void setTextArea(javax.swing.JTextArea j)
j
- the JTextArea objectpublic void setDebugOn(boolean debugOn)
debugOn
- the boolean value for the debug flagpublic void init()
public void processOneGeneration()
public void search()
public void setGeneticObjectClassName(java.lang.String aClassName)
aClassName
- the String that represents the fully-specified
(package prefixed) class name of the genetic
objects to be searchedpublic java.lang.String getGeneticObjectClassName()
public void setPopulationSize(int size)
size
- the integer value that represents the size of the populationpublic int getPopulationSize()
public java.util.Vector getPopulation()
null
if the population does not exist. Otherwise,
returns the entire population vector.public void setReplacementSize(int size)
size
- the number of members to be replacedpublic int getReplacementSize()
public java.lang.String getVocabulary()
public int getNumPasses()
public void setMaxNumPasses(int num)
num
- the maximum number of generations to searchpublic int getMaxNumPasses()
public void setFitnessThreshold(double thresh)
thresh
- the fitness thresholdpublic double getFitnessThreshold()
public void setCrossoverRate(double rate)
rate
- the double value for the crossover ratepublic double getCrossoverRate()
public void setMutationRate(double rate)
rate
- the double value for the mutation ratepublic double getMutationRate()
public double getAvgFitness()
public double getMinFitness()
public double getMaxFitness()
public int getChromosomeLength()
public void setOperatorFitness(java.util.Hashtable opFitness)
opFitness
- a Hashtable of fitness operators and fitness values
(selection probabilities). The sum of the fitness values
should equal 100.public java.util.Hashtable getOperatorFitness()
public GeneticSearchObject[] createChildren(java.lang.String[] chromosome)
chromosome
- a String array of chromosomesGeneticSearchObjects
public GeneticSearchObject createChild(java.lang.String chromosome)
chromosome
- the String representation of the child chromosomeprotected void evaluatePopulation()
protected java.util.Vector createNewMembers()
protected void integratePopulation(java.util.Vector newPopulation)
newPopulation
- a Vector of new genetic objects to be added to
the populationprotected void insertIntoPopulation(GeneticSearchObject newMember, java.util.Vector list)
newMember
- the GeneticSearchObject to insert into the populationlist
- the Vector that contains the populationpublic GeneticSearchObject[] selectParents()
public java.lang.String selectOperator()
public GeneticSearchObject rouletteWheelSelection()
public void reset()
public java.lang.String[] invokeOperator(java.lang.String operatorName, java.lang.String[] parents)
operatorName
- the String name of operator to be invokedparents
- the String array that contains parent chromosomespublic java.lang.String[] onePointCrossoverAndMutate(java.lang.String[] parents)
parents
- the String array that contains the parent chromosomes
from which two children chromosomes are createdpublic java.lang.String mutateChromosome(java.lang.String chromosome)
chromosome
- the String that represents the original chromosomepublic java.lang.String[] onePointCrossover(java.lang.String[] parents)
parents
- the String array that contains the parent chromosomes
from which the children are createdpublic java.lang.String[] mutate(java.lang.String[] parents)
parents
- the String array that represent the parent chromosomesprotected void trace(java.lang.String text)
text
- the String object that containsprotected void displayPopulation()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |