ga

package module
v0.0.0-...-7d6a290 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 5 Imported by: 0

README

A Simple Genetic Algorithm

This package uses a genetic algorithm to solve various simple problems.

License

Currently licensed under the MIT license.

Building

Requires Go 1.14 or later.

Clone and run

go build github.com/jonhanks/ga/samples/calc1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fitness

type Fitness func(Individual) float32

type FitnessGenerator

type FitnessGenerator interface {
	Generate() Fitness
}

type Generator

type Generator interface {
	Generate() Individual
	Evolve(a, b Individual, r *rand.Rand) Individual
}

Generators create new Individuals.

type Individual

type Individual interface {
	Clone() Individual
	Mutate(r *rand.Rand) Individual
}

An Individual is the basic genome/sample/... that is being evolved

type Population

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

The Population is a collection of Individuals that is evolved to meet the fitness function

func NewPopulation

func NewPopulation(generator Generator, size int, f Fitness) *Population

Create a new population

func NewPopulationFG

func NewPopulationFG(generator Generator, size int, fg FitnessGenerator) *Population

func (*Population) Evolve

func (p *Population) Evolve() *Population

func (*Population) FitnessAt

func (p *Population) FitnessAt(i int) float32

func (*Population) Individual

func (p *Population) Individual(i int) Individual

func (*Population) Length

func (p *Population) Length() int

func (*Population) Test

func (p *Population) Test()

Test the population against the fitness function

Directories

Path Synopsis
samples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL