goga: github.com/rrs/goga Index | Files

package goga

import "github.com/rrs/goga"

Index

func Evolve

func Evolve(
    popSize, nGenes, nRuns int,
    initialiser Initialiser,
    evaluator Evaluator,
    selecter Selector,
    mater Mater,
    printPop bool)

func Print

func Print(p Population)

prints out each individual

type Crosser

type Crosser interface {
    Cross(father, mother *Individual) (*Individual, *Individual)
}

Crosser defines a cross function between two individuals returns two children

func NewSinglePointCrossover

func NewSinglePointCrossover(chance float64, nGenes int) Crosser

func NewUniformCrossover

func NewUniformCrossover(chance float64, nGenes int) Crosser

type Evaluator

type Evaluator interface {
    Evaluate(p Population) (Population, bool)
}

handles problem specific evaluation returns a bool value to alert the caller to succesfully achieving the termination condition and retuns Population to allow the use of elitism (see allones example)

type Gene

type Gene interface {
    Clone() Gene
    Mutate()
    String() string
}

Clone: return a deep copy Mutate: handles gene specific mutation String: return a printable version of the data

type Individual

type Individual struct {
    Genes   []Gene
    Fitness int
}

holds a slice of genes and a fitness value it is possible to contain any number of types of genes

func (Individual) String

func (individual Individual) String() string

printable version of the individual

type Initialiser

type Initialiser interface {
    Init(p Population, nGenes int)
}

handles problem specific initialisation takes an empty population and fills it with initialised *Individual

type Mater

type Mater interface {
    Mate(Population, Population) Population
}

Combines the crossover and mutation steps

func NewParallelMater

func NewParallelMater(crosser Crosser, mutator Mutator) Mater

func NewProceduralMater

func NewProceduralMater(crosser Crosser, mutator Mutator) Mater

type Mutator

type Mutator interface {
    Mutate(*Individual)
}

func NewSimpleMutator

func NewSimpleMutator(chance float64) Mutator

type ParallelMater

type ParallelMater struct {
    // contains filtered or unexported fields
}

uses crossover and mutation in a parallel manner

func (*ParallelMater) Mate

func (mp *ParallelMater) Mate(pop, parents Population) Population

type Population

type Population []*Individual

Population has utility methods which are useful on a slice of type *Individual

func (Population) Contains

func (p Population) Contains(individual *Individual) bool

returns true if individual is contained within Population p

func (Population) Delete

func (p Population) Delete(individual *Individual)

removes the individual if it exists in the Population p

func (Population) DeleteI

func (p Population) DeleteI(i int)

removes the individual at index i and shortens the slice

type ProceduralMater

type ProceduralMater struct {
    // contains filtered or unexported fields
}

uses crossover and mutation in a procedural manner

func (*ProceduralMater) Mate

func (mp *ProceduralMater) Mate(pop, parents Population) Population

type RouletteSelection

type RouletteSelection struct {
    // contains filtered or unexported fields
}

func (*RouletteSelection) Select

func (rs *RouletteSelection) Select(pop Population) Population

type Selector

type Selector interface {
    Select(population Population) Population
}

A Selecter is used for the selection process, select returns a group of individuals selected by some probabilistic method giving a higher chance to individuals with a higher fitness

func NewRouletteSelection

func NewRouletteSelection(nParents int) Selector

func NewTournamentSelection

func NewTournamentSelection(nParents, tounamentSize int) Selector

type SimpleMutator

type SimpleMutator struct {
    // contains filtered or unexported fields
}

func (*SimpleMutator) Mutate

func (sm *SimpleMutator) Mutate(individual *Individual)

type SinglePointCrossover

type SinglePointCrossover struct {
    // contains filtered or unexported fields
}

Simple single point crossover will with probability chance randomly pick a point between 1 and nGenes - 1 to cross the individuals

func (*SinglePointCrossover) Cross

func (spc *SinglePointCrossover) Cross(father, mother *Individual) (*Individual, *Individual)

type TournamentSelection

type TournamentSelection struct {
    // contains filtered or unexported fields
}

Tounament selection selects a group of individuals of size tournamentSize completely at random from the population, then the fittest individual is selected from that group, the lower the group size the higher the selection pressure on weak individuals, this can be quite desirable.

func (*TournamentSelection) Select

func (ts *TournamentSelection) Select(pop Population) Population

type UniformCrossover

type UniformCrossover struct {
    // contains filtered or unexported fields
}

Uniform crossover will cross each gene posistion in the two individuals with probability chance

func (*UniformCrossover) Cross

func (uc *UniformCrossover) Cross(father, mother *Individual) (*Individual, *Individual)

Files

mater.go ga.go crossover.go population.go mutator.go selector.go individual.go evolve.go

Package goga imports 3 packages (graph). Updated 2013-03-22. Refresh.