src

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultModel

type DefaultModel struct {
}

func (DefaultModel) Crossover

func (dm DefaultModel) Crossover(parent1 Individual, parent2 Individual) (Individual, error)

Crossover is fixed point crossover. It does not ensure uniqueness of genes.

func (DefaultModel) Mutate

func (dm DefaultModel) Mutate(individual Individual) (Individual, error)

func (DefaultModel) SelectParent

func (dm DefaultModel) SelectParent(population *Population) Individual

type GA

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

func NewCustomGA

func NewCustomGA(generationNumber int, populationSize int, mutationRate float64, elitismRate float64, individual Individual, model Model) GA

func NewDefaultGA

func NewDefaultGA(generationNumber int, populationSize int, mutationRate float64, individual Individual) GA

maybe use builder pattern?

func (*GA) Run

func (g *GA) Run() Individual

Implement user provided callback function that takes individual as parameter We will call this callback with parameter g.population.calculateBestIndividual User can get properties of this individual and save it in an array and use it.

func (*GA) RunWithLog

func (g *GA) RunWithLog(printIndividual printIndividual) Individual

type Individual

type Individual interface {
	CalculateFitness() float64
	GenerateIndividual() Individual
}

type Model

type Model interface {
	SelectParent(population *Population) Individual
	Crossover(parent1 Individual, parent2 Individual) (Individual, error)
	Mutate(individual Individual) (Individual, error)
}

type PermutationModel

type PermutationModel struct {
	DefaultModel
}

func (PermutationModel) Crossover

func (pm PermutationModel) Crossover(parent1 Individual, parent2 Individual) (Individual, error)

Crossover is ordered crossover implementation

func (PermutationModel) Mutate

func (pm PermutationModel) Mutate(individual Individual) (Individual, error)

Mutate is swap mutation implementation

type Population

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

Jump to

Keyboard shortcuts

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