public abstract class GeneticAlgorithm extends Object
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 List<Chromosome> |
population
This is the (current) population pool.
|
protected RandomLongGenerator |
uniform
This is a uniform random number generator.
|
| Constructor and Description |
|---|
GeneticAlgorithm(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 abstract List<? extends Chromosome> |
getFirstGeneration()
Initialize the first population.
|
protected static ArrayList<Chromosome> |
getNewPool(int size)
Allocate space for a population pool.
|
protected List<Chromosome> |
getNextGeneration(List<Chromosome> parents,
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 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 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 List<Chromosome> population
public GeneticAlgorithm(RandomLongGenerator uniform)
uniform - a uniform random number generator; if uniform is a
ThreadIDRNG, the simulations will run in parallelprotected abstract List<? extends Chromosome> getFirstGeneration()
protected abstract boolean isConverged()
true if the search has convergedpublic void run()
protected Object step()
protected Chromosome getChild(int i)
i - an index that ranges from 0 to (population size - 1)protected Chromosome getOne()
protected List<Chromosome> getNextGeneration(List<Chromosome> parents, 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 ArrayList<Chromosome> getNewPool(int size)
size - the population sizeCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.