Documentation
¶
Index ¶
- func Mutate(g1, g2 Genome) (Genome, Genome)
- func OnePointCrossover(g1, g2 Genome) (Genome, Genome)
- func TwoPointCrossover(g1, g2 Genome) (Genome, Genome)
- func UniformCrossover(g1, g2 Genome) (Genome, Genome)
- type Bitset
- func (b *Bitset) Create(size int)
- func (b *Bitset) CreateCopy() Bitset
- func (b *Bitset) Get(index int) int
- func (b *Bitset) GetAll() []int
- func (b *Bitset) GetSize() int
- func (b *Bitset) Set(index, value int) bool
- func (b *Bitset) SetAll(value int)
- func (b *Bitset) Slice(startingBit, size int) Bitset
- type BitsetCreate
- type BitsetParse
- type EliteConsumer
- type GeneticAlgorithm
- type Genome
- type Mater
- type MaterFunctionProbability
- type NullBitsetCreate
- type NullEliteConsumer
- type NullMater
- type NullSelector
- type NullSimulator
- type Selector
- type SelectorFunctionProbability
- type Simulator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Mutate ¶
Mutate - Accepts 2 genomes and mutates a single bit in the first to create a new very slightly different genome i.e. input genomes of: 000000 and 111111 could produce output genomes of: 001000 and 111111
func OnePointCrossover ¶
OnePointCrossover - Accepts 2 genomes and combines them to create 2 new genomes using one point crossover i.e. input genomes of: 000000 and 111111 could produce output genomes of: 000111 and 111000
func TwoPointCrossover ¶
TwoPointCrossover - Accepts 2 genomes and combines them to create 2 new genomes using two point crossover i.e. input genomes of: 000000 and 111111 could produce output genomes of: 001100 and 110011
func UniformCrossover ¶
UniformCrossover - Accepts 2 genomes and combines them to create 2 new genomes using uniform crossover i.e. input genomes of: 000000 and 111111 could produce output genomes of: 101010 and 010101
Types ¶
type Bitset ¶
type Bitset struct {
// contains filtered or unexported fields
}
Bitset - a simple bitset implementation
func (*Bitset) CreateCopy ¶
CreateCopy returns a bit for bit copy of the bitset
func (*Bitset) Get ¶
Get returns the value in the bitset at index 'index' or -1 if the index is out of range
type BitsetCreate ¶
type BitsetCreate interface {
Go() Bitset
}
BitsetCreate - an interface to a bitset create struct
type BitsetParse ¶
BitsetParse - an interface to an object that is able to parse a bitset into an array of uint64s
func CreateBitsetParse ¶
func CreateBitsetParse() BitsetParse
CreateBitsetParse returns an instance of a bitset parser
type EliteConsumer ¶
type EliteConsumer interface {
OnElite(Genome)
}
EliteConsumer - an interface to the elite consumer
type GeneticAlgorithm ¶
type GeneticAlgorithm struct { Mater Mater EliteConsumer EliteConsumer Simulator Simulator Selector Selector BitsetCreate BitsetCreate // contains filtered or unexported fields }
GeneticAlgorithm - The main component of goga, holds onto the state of the algorithm - * Mater - combining evolved genomes * EliteConsumer - an optional class that accepts the 'elite' of each population generation * Simulator - a simulation component used to score each genome in each generation * BitsetCreate - used to create the initial population of genomes
func NewGeneticAlgorithm ¶
func NewGeneticAlgorithm() GeneticAlgorithm
NewGeneticAlgorithm returns a new GeneticAlgorithm structure with null implementations of EliteConsumer, Mater, Simulator, Selector and BitsetCreate
func (*GeneticAlgorithm) GetPopulation ¶
func (ga *GeneticAlgorithm) GetPopulation() []Genome
GetPopulation returns the population
func (*GeneticAlgorithm) Init ¶
func (ga *GeneticAlgorithm) Init(populationSize, parallelSimulations int)
Init initialises internal components, sets up the population size and number of parallel simulations
func (*GeneticAlgorithm) Simulate ¶
func (ga *GeneticAlgorithm) Simulate() bool
Simulate runs the genetic algorithm
func (*GeneticAlgorithm) SimulateUntil ¶
func (ga *GeneticAlgorithm) SimulateUntil(exitFunc func(Genome) bool) bool
SimulateUntil simulates a population until 'exitFunc' returns true The 'exitFunc' is passed the elite of each population and should return true if the elite reaches a certain criteria (e.g. fitness above a certain threshold)
type Genome ¶
IGenome associates a fitness with a bitset
type Mater ¶
Mater - an interface to a mater object
func NewMater ¶
func NewMater(materConfig []MaterFunctionProbability) Mater
NewMater returns an instance of an IMater with several MaterFuncProbabilities
type MaterFunctionProbability ¶
type MaterFunctionProbability struct { P float32 F func(Genome, Genome) (Genome, Genome) UseElite bool }
MaterFunctionProbability - An implementation of IMater that has a function and a probability where mater function 'F' is called with a probability of 'P' where 'P' is a value between 0 and 1 0 = never called, 1 = called for every genome
type NullBitsetCreate ¶
type NullBitsetCreate struct { }
NullBitsetCreate - a null implementation of the IBitsetCreate interface
func (*NullBitsetCreate) Go ¶
func (ngc *NullBitsetCreate) Go() Bitset
Go returns a bitset with no content
type NullEliteConsumer ¶
type NullEliteConsumer struct { }
NullEliteConsumer - a null implementation of the elite consumer
func (*NullEliteConsumer) OnElite ¶
func (nec *NullEliteConsumer) OnElite(Genome)
OnElite - null implementation on OnElite from the EliteConsumer interface
type NullMater ¶
type NullMater struct { }
NullMater - null implementation of the IMater interface
type NullSelector ¶
type NullSelector struct { }
NullSelector - a null implementation of the Selector interface
type NullSimulator ¶
type NullSimulator struct { }
NullSimulator - a null implementation of the Simulator interface
func (*NullSimulator) ExitFunc ¶
func (ns *NullSimulator) ExitFunc(Genome) bool
ExitFunc - a null implementation of Simulator's 'ExitFunc'
func (*NullSimulator) OnBeginSimulation ¶
func (ns *NullSimulator) OnBeginSimulation()
OnBeginSimulation - a null implementation of Simulator's 'OnBeginSimulation'
func (*NullSimulator) OnEndSimulation ¶
func (ns *NullSimulator) OnEndSimulation()
OnEndSimulation - a null implementation of Simulator's 'OnEndSimulation'
func (*NullSimulator) Simulate ¶
func (ns *NullSimulator) Simulate(Genome)
Simulate - a null implementation of Simulator's 'Simulate'
type Selector ¶
Selector - a selector interface used to pick 2 genomes to mate
func NewSelector ¶
func NewSelector(selectorConfig []SelectorFunctionProbability) Selector
NewSelector returns an instance of an ISelector with several SelectorFunctionProbabiities
type SelectorFunctionProbability ¶
SelectorFunctionProbability - Contains a selector function and a probability where selector function 'F' is called with probability 'P' where 'P' is a value between 0 and 1 0 = never called, 1 = called every time we need a new genome to mate