ga

package
v0.0.0-...-7a5de80 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ga implements Genetic Algorithms.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChampionIndividual

type ChampionIndividual struct {
	X DecisionVector
}

ChampionIndividual is a representation of the best individual currently available in the population.

type ConstraintVector

type ConstraintVector []float64

ConstraintVector is a []float64 abstraction representing the constraint vector.

type DE

type DE struct {
	// Generations denotes the number of generations the population evolves
	// for. Special value -1 disables limiting the number of generations.
	Generations int
	// BenchMinIters is the number of iterations the bench function will be re-run (for statistical purposes).
	BenchMinIters int
	// Dimensions to solve the problem for.
	Dimensions []int
	// F is the differential weight (mutation/weighting factor).
	F float64
	// CR is the crossover probability constant.
	CR float64
	// MutationStrategy selects the mutation strategy, i.e. the variant of the
	// DE algorithm (0..17), see mutationStrategies.go for more details.
	MutationStrategy int
	// NP is the initial population size.
	NP int
	// BenchName is a name of the problem to optimise.
	BenchName string
	// contains filtered or unexported fields
}

DE is a holder for the settings of an instance of a Differential Evolution (DE) algorithm.

func NewDE

func NewDE() *DE

NewDE returns a pointer to a new, uninitialised DE instance.

func (*DE) Init

func (d *DE) Init(
	generations, benchMinIters, mutStrategy, np int,
	f, cr float64,
	dimensions []int,
	bench string,
	ch chan []stats.Stats,
	chAlgoMeans chan *stats.AlgoBenchMean,
)

Init initialises the DE algorithm, performs sanity checks on the inputs.

func (*DE) InitAndRun

func (d *DE) InitAndRun(
	generations, benchMinIters, mutStrategy, np int,
	f, cr float64,
	dimensions []int,
	bench string,
	ch chan []stats.Stats,
	chAlgoMeans chan *stats.AlgoBenchMean,
)

InitAndRun initialises the DE algorithm, performs sanity checks on the inputs and calls the Run method.

func (*DE) Run

func (d *DE) Run()

Run self-adapting differential evolution algorithm.

type DecisionVector

type DecisionVector []float64

DecisionVector is a []float64 abstraction representing the decision vector.

type FitnessVector

type FitnessVector []float64

FitnessVector is a []float64 abstraction representing the fitness vector.

type JDE

type JDE struct {
	// Generations denotes the number of generations the population evolves
	// for. Special value -1 disables limiting the number of generations.
	Generations int
	// BenchMinIters is the number of iterations the bench function will be re-run (for statistical purposes).
	BenchMinIters int
	// Dimensions to solve the problem for.
	Dimensions []int
	// F is the initial value of the differential weight (mutation/weighting factor).
	F float64
	// CR is the initial value of the crossover probability constant.
	CR float64

	// MutationStrategy selects the mutation strategy, i.e. the variant of the
	// jDE algorithm (0..17), see mutationStrategies.go for more details.
	MutationStrategy int
	// AdptScheme is the parameter self-adaptation scheme (0..1).
	AdptScheme int
	// NP is the initial population size.
	NP int
	// BenchName is a name of the problem to optimise.
	BenchName string
	// contains filtered or unexported fields
}

JDE is a holder for the settings of an instance of a self-adapting differential evolution (jDE) algorithm.

func NewjDE

func NewjDE() *JDE

NewjDE returns a pointer to a new, uninitialised jDE instance.

func (*JDE) Init

func (j *JDE) Init(
	generations, benchMinIters, mutStrategy, adptScheme, np int,
	f, cr float64,
	dimensions []int,
	bench string,
	ch chan []stats.Stats,
	chAlgoMeans chan *stats.AlgoBenchMean,
)

Init initialises the jDE algorithm, performs sanity checks on the inputs.

func (*JDE) InitAndRun

func (j *JDE) InitAndRun(
	generations, benchMinIters, mutStrategy, adptScheme, np int,
	f, cr float64,
	dimensions []int,
	bench string,
	ch chan []stats.Stats,
	chAlgoMeans chan *stats.AlgoBenchMean,
)

InitAndRun initialises the jDE algorithm, performs sanity checks on the inputs and calls the Run method.

func (*JDE) Run

func (j *JDE) Run()

Run self-adapting differential evolution algorithm.

type Population

type Population struct {
	// Population is a slice of population individuals.
	Population []PopulationIndividual
	// Champion represents the best individual of the population.
	Champion ChampionIndividual
	// Problem is the current benchmarking function this population is attempting to optimise.
	Problem string
	// ProblemFunction is the actual function to optimise.
	ProblemFunc func([]float64) float64
	// Dimen is the dimensionality of the problem being optimised.
	Dimen int
	// Seed is the value used to (re)init population.
	Seed uint64

	// BestF is the best recorded value of the differential weight F.
	BestF float64
	// BestCR is the best recorded value of the differential weight CR.
	BestCR float64
	// CurF is the current value of F.
	CurF float64
	// CurCR is the current value of the differential weight CR.
	CurCR float64
	// contains filtered or unexported fields
}

Population groups population individuals (agents) with metadata about the population.

func (*Population) Clear

func (p *Population) Clear()

Clear sets all vectors to 0.

func (*Population) GetBestIdx

func (p *Population) GetBestIdx() int

GetBestIdx returns the index of the best population individual.

func (*Population) GetIndividual

func (p *Population) GetIndividual(n uint) *PopulationIndividual

GetIndividual returns a reference to individual at position n.

func (*Population) GetWorstIdx

func (p *Population) GetWorstIdx() int

GetWorstIdx returns the index of the worst population individual.

func (*Population) Init

func (p *Population) Init()

Init initialises all individuals to random values.

func (*Population) MeanVelocity

func (p *Population) MeanVelocity() float64

MeanVelocity computes the mean current velocity of all individuals in the population.

func (*Population) Reinit

func (p *Population) Reinit()

Reinit reinitialises all individuals.

func (*Population) ReinitN

func (p *Population) ReinitN(n uint)

ReinitN reinitialises the individual at position n.

func (*Population) SelectDonors

func (p *Population) SelectDonors(currentIdx int) []PopulationIndividual

func (*Population) Size

func (p *Population) Size() int

Size returns the number of population individuals.

type PopulationIndividual

type PopulationIndividual struct {
	CurX DecisionVector
	CurF FitnessVector

	BestX DecisionVector
	BestC ConstraintVector
	BestF FitnessVector
}

PopulationIndividual represents a single population individual.

type SOMAT3A

type SOMAT3A struct {
	// Generations is the number of generations to evolve for. Disable limit
	// with -1.
	Generations int
	// BenchMinIters is the number of iterations that the bench function will
	// be re-run.
	BenchMinIters int
	// Dimensions in which to look for a solution.
	Dimensions []int
	// NP is the initial population size.
	NP int
	// K is the number of individuals to choose the leader from.
	K int
	// M denotes how many individuals are picked from the population to form a
	// `team` during the organisation phase, can be thought of as "team size".
	M int
	// N is the number of best individuals in each team selected for actual
	// migration.
	N int
	// Njumps is the fixed number of jumps that each chosen migrating
	// individual performs on their way to the leader.
	Njumps int
	// BenchName is the human-friendly name of the benchmarking function.
	BenchName string
	// contains filtered or unexported fields
}

SOMAT3A holds the settings for an instance of SOMA T3A algorithm. nolint: unused

func NewSOMAT3A

func NewSOMAT3A() *SOMAT3A

NewSOMAT3A returns a pointer to a new, uninitialised SOMAT3A instance.

func (*SOMAT3A) Init

func (s *SOMAT3A) Init(
	generations, benchMinIters, np, k, m, n, njumps int,
	dimensions []int,
	bench string,
	ch chan []stats.Stats,
	chAlgoMeans chan *stats.AlgoBenchMean,
) error

Init performs checks on the input params and initialises an instance of SOMAT3A.

func (*SOMAT3A) Run

func (s *SOMAT3A) Run()

Run runs the SOMA T3A algo for each of `s.Dimensions` with benchmarking function `s.BenchName`, repeats the run `s.BenchMinIters` times and returns the stats via chans.

type SOMAT3AChampionIndividual

type SOMAT3AChampionIndividual struct {
	X DecisionVector
}

ChampionIndividual is a representation of the best individual currently available in the population.

type SOMAT3APopulation

type SOMAT3APopulation struct {
	// Population is a slice of population individuals.
	Population []SOMAT3APopulationIndividual
	// Champion represents the best individual of the population.
	Champion SOMAT3AChampionIndividual
	// Problem is the current benchmarking function this population is attempting to optimise.
	Problem string
	// ProblemFunction is the actual function to optimise.
	ProblemFunc func([]float64) float64
	// Dimen is the dimensionality of the problem being optimised.
	Dimen int

	// Seed is the value used to (re)init population.
	Seed uint64

	// PRT is the perturbation parameter.
	PRT float64
	// K is the number of individuals to choose the leader from.
	K int
	// M denotes how many individuals are picked from the population to form a
	// `team` during the organisation phase, can be thought of as "team size".
	M int
	// N is the number of best individuals in each team selected for actual
	// migration.
	N int
	// Njumps is the fixed number of jumps that each chosen migrating
	// individual performs on their way to the leader.
	Njumps int
	// contains filtered or unexported fields
}

Population groups population individuals (agents) with metadata about the population.

func (*SOMAT3APopulation) Clear

func (p *SOMAT3APopulation) Clear()

Clear sets all vectors to 0.

func (*SOMAT3APopulation) GetBestIdx

func (p *SOMAT3APopulation) GetBestIdx() int

GetBestIdx returns the index of the best population individual.

func (*SOMAT3APopulation) GetIndividual

func (p *SOMAT3APopulation) GetIndividual(n uint) *PopulationIndividual

GetIndividual returns a reference to individual at position n.

func (*SOMAT3APopulation) GetWorstIdx

func (p *SOMAT3APopulation) GetWorstIdx() int

GetWorstIdx returns the index of the worst population individual.

func (*SOMAT3APopulation) Init

func (p *SOMAT3APopulation) Init()

Init initialises all individuals to random values.

func (*SOMAT3APopulation) Reinit

func (p *SOMAT3APopulation) Reinit()

Reinit reinitialises all individuals.

func (*SOMAT3APopulation) Size

func (p *SOMAT3APopulation) Size() int

Size returns the number of population individuals.

type SOMAT3APopulationIndividual

type SOMAT3APopulationIndividual struct {
	CurX      DecisionVector
	PRTVector []float64
	Jumps     [][]float64
}

PopulationIndividual represents a single population individual.

Jump to

Keyboard shortcuts

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