public abstract class GeneticAlgorithm
extends java.lang.Object
implements java.io.Serializable
protected so any can be overridden to allow customization.| Modifier and Type | Field and Description |
|---|---|
protected boolean |
parallel
This indicate if the algorithm is to run in parallel (multi-core).
|
protected java.util.ArrayList<Chromosome> |
population
This is the (current) population pool.
|
protected RandomLongGenerator |
uniform
This is a uniform random number generator.
|
| Constructor and Description |
|---|
GeneticAlgorithm(boolean parallel,
RandomLongGenerator uniform)
Construct an instance of this implementation of genetic algorithm.
|
| Modifier and Type | Method and Description |
|---|---|
protected Chromosome |
getBest(int i)
Get the i-th best chromosome.
|
protected Chromosome |
getChild(int i)
Produce a child chromosome.
|
protected static java.util.ArrayList<Chromosome> |
getNewPool(int size)
Allocate space for a population pool.
|
protected java.util.List<Chromosome> |
getNextGeneration(java.util.List<Chromosome> parents,
java.util.List<Chromosome> children)
Populate the next generation using the parent and children chromosome pools.
|
protected Chromosome |
getOne()
Pick a chromosome for mutation/crossover.
|
protected abstract java.util.ArrayList<Chromosome> |
initialization()
Initialize the first population.
|
protected abstract boolean |
isConverged()
This is the convergence criterion.
|
protected int |
nChildren()
Get the number of children before populating the next generation.
|
protected int |
nPopulation()
Get the size of the population pool, that is the number of chromosomes.
|
void |
run()
Run the genetic algorithm.
|
protected java.lang.Object |
step()
Run a step in genetic algorithm: produce the next generation of chromosome pool.
|
protected final boolean parallel
protected final RandomLongGenerator uniform
protected final java.util.ArrayList<Chromosome> population
public GeneticAlgorithm(boolean parallel,
RandomLongGenerator uniform)
parallel - true if the algorithm is to run in paralleluniform - a uniform random number generatorprotected abstract java.util.ArrayList<Chromosome> initialization()
protected abstract boolean isConverged()
true if the search has convergedpublic void run()
protected java.lang.Object step()
protected Chromosome getChild(int i)
i - an index that ranges from 0 to (population size - 1)protected Chromosome getOne()
protected java.util.List<Chromosome> getNextGeneration(java.util.List<Chromosome> parents, java.util.List<Chromosome> children)
parents - the parent chromosome poolchildren - the children chromosome poolprotected int nPopulation()
protected int nChildren()
protected Chromosome getBest(int i)
i - an indexprotected static java.util.ArrayList<Chromosome> getNewPool(int size)
size - the population size