genetic_algorithm

package module
v0.0.0-...-0872a5e Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2014 License: MIT Imports: 8 Imported by: 6

README

genetic_algorithm

Genetic algorithm library. Written in the Go programming language (Golang).

Installation

If you don't have the Go development environment installed, visit the Getting Started document and follow the instructions. Once you're ready, execute the following command:

go get -u github.com/WiseBird/genetic_algorithm

Documentation

Index

Constants

View Source
const (
	// Will roll for every element in chromosome, mutate it if success
	MutatorOneByOneType = 0
	// Will mutete exactly (Npop * Nel * P) elements
	MutatorExactCountType = 1
)

Variables

View Source
var (
	NopMutator = &nopMutator{}
)

Functions

func NewOrderCrossoverVer1

func NewOrderCrossoverVer1() *orderCrossover

func NewOrderCrossoverVer2

func NewOrderCrossoverVer2() *orderCrossover

Types

type BinaryChromosome

type BinaryChromosome struct {
	*ChromosomeBase
	// contains filtered or unexported fields
}

func NewBinaryChromosome

func NewBinaryChromosome(genes BinaryGenes) *BinaryChromosome

func (*BinaryChromosome) BinaryGenes

func (chrom *BinaryChromosome) BinaryGenes() BinaryGenes

func (*BinaryChromosome) Genes

func (chrom *BinaryChromosome) Genes() GenesInterface

func (*BinaryChromosome) String

func (chrom *BinaryChromosome) String() string

type BinaryGenes

type BinaryGenes []bool

func (BinaryGenes) Copy

func (g BinaryGenes) Copy(genes GenesInterface, from1, from2, to2 int) int

func (BinaryGenes) Get

func (g BinaryGenes) Get(i int) interface{}

func (BinaryGenes) Len

func (g BinaryGenes) Len() int

func (BinaryGenes) Set

func (g BinaryGenes) Set(i int, val interface{})

func (BinaryGenes) Swap

func (g BinaryGenes) Swap(i, j int)

type BinaryMutator

type BinaryMutator struct {
}

Mutator for binary chromosomes Simply inverts specified bit

func (*BinaryMutator) MutateCromosome

func (mutator *BinaryMutator) MutateCromosome(chrom ChromosomeInterface, ind int)

type BinaryRandomInitializer

type BinaryRandomInitializer struct {
}

func NewBinaryRandomInitializer

func NewBinaryRandomInitializer() *BinaryRandomInitializer

func (*BinaryRandomInitializer) Init

func (initializer *BinaryRandomInitializer) Init(count, chromSize int) Chromosomes

type ChromosomeBase

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

Base class for chromosomes.

func NewChromosomeBase

func NewChromosomeBase() *ChromosomeBase

func (*ChromosomeBase) Cost

func (chrom *ChromosomeBase) Cost() float64

func (*ChromosomeBase) SetCost

func (chrom *ChromosomeBase) SetCost(cost float64)

type ChromosomeInterface

type ChromosomeInterface interface {
	Genes() GenesInterface
	SetCost(float64)
	Cost() float64
}

func NewEmptyBinaryChromosome

func NewEmptyBinaryChromosome(genesLen int) ChromosomeInterface

func NewEmptyOrderedChromosome

func NewEmptyOrderedChromosome(genesLen int) ChromosomeInterface

type Chromosomes

type Chromosomes []ChromosomeInterface

func (Chromosomes) Len

func (c Chromosomes) Len() int

func (Chromosomes) Less

func (c Chromosomes) Less(i, j int) bool

func (Chromosomes) MeanCost

func (c Chromosomes) MeanCost() float64

func (Chromosomes) SetCost

func (c Chromosomes) SetCost(cost CostFunction)

func (Chromosomes) String

func (c Chromosomes) String() string

func (Chromosomes) Swap

func (c Chromosomes) Swap(i, j int)

type CostFunction

type CostFunction func(ChromosomeInterface) float64

type CrossoverInterface

type CrossoverInterface interface {
	ParentsCount() int
	Crossover(Chromosomes) Chromosomes
}

type CycleCrossover

type CycleCrossover struct {
}

Crossover for ordered chromosomes. Tends to preserve absolute order.

func NewCycleCrossover

func NewCycleCrossover() *CycleCrossover

func (*CycleCrossover) Crossover

func (crossover *CycleCrossover) Crossover(parents Chromosomes) Chromosomes

func (*CycleCrossover) ParentsCount

func (crossover *CycleCrossover) ParentsCount() int

type DisplacementMutator

type DisplacementMutator struct {
	*MutatorIntervalBase
}

Mutator selects some part of the chromosome and places it in random position

func NewDisplacementMutator

func NewDisplacementMutator(probability float64, chromosomeConstructor EmptyChromosomeConstructor) *DisplacementMutator

Probability is applied to each chromosome

func (*DisplacementMutator) MutateGenes

func (mutator *DisplacementMutator) MutateGenes(genes GenesInterface, from, to int)

type EdgeRecombinationCrossover

type EdgeRecombinationCrossover struct {
}

The edge recombination operator (ERO) is an operator that creates a path that is similar to a set of existing paths (parents) by looking at the edges rather than the vertices.

http://en.wikipedia.org/wiki/Edge_recombination_operator

func NewEdgeRecombinationCrossover

func NewEdgeRecombinationCrossover() *EdgeRecombinationCrossover

func (*EdgeRecombinationCrossover) Crossover

func (crossover *EdgeRecombinationCrossover) Crossover(parents Chromosomes) Chromosomes

func (*EdgeRecombinationCrossover) ParentsCount

func (crossover *EdgeRecombinationCrossover) ParentsCount() int

type EmptyChromosomeConstructor

type EmptyChromosomeConstructor func(genesLen int) ChromosomeInterface

type GenesInterface

type GenesInterface interface {
	Len() int
	Copy(genes GenesInterface, from1, from2, to2 int) int
	Swap(int, int)
	Get(int) interface{}
	Set(int, interface{})
}

type HierarchicalDuration

type HierarchicalDuration struct {
	Name     string
	Duration time.Duration
	Calls    int

	Children map[string]*HierarchicalDuration
}

func (*HierarchicalDuration) String

func (hierarchy *HierarchicalDuration) String() string

type IncrementalOptimizer

type IncrementalOptimizer struct {
	*OptimizerBase
	// contains filtered or unexported fields
}

func NewIncrementalOptimizer

func NewIncrementalOptimizer() *IncrementalOptimizer

func (*IncrementalOptimizer) Weeder

func (optimizer *IncrementalOptimizer) Weeder(weeder WeederInterface) *IncrementalOptimizer

type InitializerInterface

type InitializerInterface interface {
	Init(count, chromSize int) Chromosomes
}

type InvertDisplacementMutator

type InvertDisplacementMutator struct {
	*MutatorIntervalBase
	// contains filtered or unexported fields
}

InvertMutator + DisplacementMutator Mutator selects some part of the chromosome inverts it then place at other position

func NewInvertDisplacementMutator

func NewInvertDisplacementMutator(probability float64, chromosomeConstructor EmptyChromosomeConstructor) *InvertDisplacementMutator

Probability is applied to each chromosome

func (*InvertDisplacementMutator) MutateGenes

func (mutator *InvertDisplacementMutator) MutateGenes(genes GenesInterface, from, to int)

type InvertMutator

type InvertMutator struct {
	*MutatorIntervalBase
}

Mutator selects some part of the chromosome and inverts it

func NewInvertMutator

func NewInvertMutator(probability float64, chromosomeConstructor EmptyChromosomeConstructor) *InvertMutator

Probability is applied to each chromosome

func (*InvertMutator) MutateGenes

func (mutator *InvertMutator) MutateGenes(genes GenesInterface, from, to int)

type InvertSwapMutator

type InvertSwapMutator struct {
	*MutatorIntervalBase
	// contains filtered or unexported fields
}

InvertMutator + SwapMutator Mutator selects some part of the chromosome inverts it then swap on gene from it with one gene outside of the interval

func NewInvertSwapMutator

func NewInvertSwapMutator(probability float64, chromosomeConstructor EmptyChromosomeConstructor) *InvertSwapMutator

Probability is applied to each chromosome

func (*InvertSwapMutator) MutateGenes

func (mutator *InvertSwapMutator) MutateGenes(genes GenesInterface, from, to int)

type MultiPointCrossover

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

func NewMultiPointCrossover

func NewMultiPointCrossover(chromConstr EmptyChromosomeConstructor, crossPointsCount int) *MultiPointCrossover

func NewOnePointCrossover

func NewOnePointCrossover(chromConstr EmptyChromosomeConstructor) *MultiPointCrossover

func NewTwoPointCrossover

func NewTwoPointCrossover(chromConstr EmptyChromosomeConstructor) *MultiPointCrossover

func (*MultiPointCrossover) CanProduceCopiesOfParents

func (crossover *MultiPointCrossover) CanProduceCopiesOfParents(val bool) *MultiPointCrossover

func (*MultiPointCrossover) Crossover

func (crossover *MultiPointCrossover) Crossover(parents Chromosomes) Chromosomes

func (*MultiPointCrossover) ParentsCount

func (crossover *MultiPointCrossover) ParentsCount() int

type MutatorGeneBase

type MutatorGeneBase struct {
	MutatorGeneBaseVirtualMInterface
	// contains filtered or unexported fields
}

Base class for mutators that mutate separate genes

func NewBinaryMutator

func NewBinaryMutator(probability float64) *MutatorGeneBase

Probability is applied to each element separately.

func NewGeneBaseMutator

func NewGeneBaseMutator(virtual MutatorGeneBaseVirtualMInterface, probability float64) *MutatorGeneBase

func NewSwapMutator

func NewSwapMutator(probability float64) *MutatorGeneBase

Probability is applied to each element separately.

func (*MutatorGeneBase) ExactCount

func (mutator *MutatorGeneBase) ExactCount() *MutatorGeneBase

Will mutete exactly (Npop * Nel * P) elements

func (*MutatorGeneBase) Mutate

func (mutator *MutatorGeneBase) Mutate(population Chromosomes)

func (*MutatorGeneBase) OneByOne

func (mutator *MutatorGeneBase) OneByOne() *MutatorGeneBase

Will roll for every element in chromosome, mutate it if success

func (*MutatorGeneBase) WithElitism

func (mutator *MutatorGeneBase) WithElitism(count int) *MutatorGeneBase

The best chromosome[s] can't be mutated

func (*MutatorGeneBase) WithoutElitism

func (mutator *MutatorGeneBase) WithoutElitism() *MutatorGeneBase

All chromosomes can be mutated

type MutatorGeneBaseVirtualMInterface

type MutatorGeneBaseVirtualMInterface interface {
	MutateCromosome(chrom ChromosomeInterface, ind int)
}

MutatorGeneBase's virtual methods

type MutatorInterface

type MutatorInterface interface {
	Mutate(Chromosomes)
}

Mutator interface

type MutatorIntervalBase

type MutatorIntervalBase struct {
	MutatorIntervalBaseVirtualMInterface
	// contains filtered or unexported fields
}

Base class for mutators that mutate some interval of genes

func NewInsertionMutator

func NewInsertionMutator(probability float64, chromosomeConstructor EmptyChromosomeConstructor) *MutatorIntervalBase

Mutator selects random element from chromosome and places it in random position Probability is applied to each chromosome

func NewMutatorIntervalBase

func NewMutatorIntervalBase(virtual MutatorIntervalBaseVirtualMInterface, probability float64, chromosomeConstructor EmptyChromosomeConstructor) *MutatorIntervalBase

Probability is applied to each chromosome By default interval will be equal one third of the chromosome

func (*MutatorIntervalBase) ExactInterval

func (mutator *MutatorIntervalBase) ExactInterval(from, to int) *MutatorIntervalBase

Sets interval len to be randomly choosen from [from:to]

func (*MutatorIntervalBase) Mutate

func (mutator *MutatorIntervalBase) Mutate(population Chromosomes)

func (*MutatorIntervalBase) PercentageInterval

func (mutator *MutatorIntervalBase) PercentageInterval(from, to float64) *MutatorIntervalBase

Sets interval len to be randomly choosen from [from*chromLen : to*chromLen]

type MutatorIntervalBaseVirtualMInterface

type MutatorIntervalBaseVirtualMInterface interface {
	MutateGenes(genes GenesInterface, from, to int)
}

MutatorIntervalBase's virtual methods

type OptimizerAggregator

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

func NewOptimizerAggregator

func NewOptimizerAggregator() *OptimizerAggregator

func (*OptimizerAggregator) Iterations

func (aggregator *OptimizerAggregator) Iterations(iterations int) *OptimizerAggregator

func (*OptimizerAggregator) Optimize

func (*OptimizerAggregator) Optimizer

func (aggregator *OptimizerAggregator) Optimizer(optimizer OptimizerInterface) *OptimizerAggregator

func (*OptimizerAggregator) StatisticsAggregatorConstructor

func (aggregator *OptimizerAggregator) StatisticsAggregatorConstructor(constr StatisticsAggregatorConstructor) *OptimizerAggregator

func (*OptimizerAggregator) StatisticsOptions

func (aggregator *OptimizerAggregator) StatisticsOptions(statisticsOptions StatisticsOptionsInterface) *OptimizerAggregator

type OptimizerBase

type OptimizerBase struct {
	OptimizerBaseVirtualMInterface
	// contains filtered or unexported fields
}

func NewOptimizerBase

func NewOptimizerBase(virtual OptimizerBaseVirtualMInterface) *OptimizerBase

func (*OptimizerBase) ChromSize

func (optimizer *OptimizerBase) ChromSize(chromSize int) *OptimizerBase

func (*OptimizerBase) CostFunction

func (optimizer *OptimizerBase) CostFunction(cost CostFunction) *OptimizerBase

func (*OptimizerBase) Crossover

func (optimizer *OptimizerBase) Crossover(crossover CrossoverInterface) *OptimizerBase

func (*OptimizerBase) Initializer

func (optimizer *OptimizerBase) Initializer(initializer InitializerInterface) *OptimizerBase

func (*OptimizerBase) Mutator

func (optimizer *OptimizerBase) Mutator(mutator MutatorInterface) *OptimizerBase

func (*OptimizerBase) Optimize

func (*OptimizerBase) PopSize

func (optimizer *OptimizerBase) PopSize(popSize int) *OptimizerBase

func (*OptimizerBase) Selector

func (optimizer *OptimizerBase) Selector(selector SelectorInterface) *OptimizerBase

func (*OptimizerBase) SetupStatisticsOptions

func (optimizer *OptimizerBase) SetupStatisticsOptions() StatisticsOptionsInterface

func (*OptimizerBase) StatisticsConstructor

func (optimizer *OptimizerBase) StatisticsConstructor(constr StatisticsConstructor) *OptimizerBase

func (*OptimizerBase) StatisticsOptions

func (optimizer *OptimizerBase) StatisticsOptions(statisticsOptions StatisticsOptionsInterface) *OptimizerBase

func (*OptimizerBase) StopCriterion

func (optimizer *OptimizerBase) StopCriterion(stopCriterion StopCriterionInterface) *OptimizerBase

type OptimizerBaseVirtualMInterface

type OptimizerBaseVirtualMInterface interface {
	// contains filtered or unexported methods
}

MutatorBase's virtual methods

type OptimizerInterface

type OptimizerInterface interface {
	Optimize() (ChromosomeInterface, StatisticsDataInterface)
}

type OptimizerWithStatisticsOptionsSetup

type OptimizerWithStatisticsOptionsSetup interface {
	SetupStatisticsOptions() StatisticsOptionsInterface
}

type OrderBasedCrossover

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

Crossover for ordered chromosomes. Tends to preserve relative order.

parent1: A B C D E F parent2: d f b e a c

mask: * * _ * _ _ parent1: A B C D E F The genes 'A B D' will be copied in child in order from parent1 and in paces from parent2

child1 step1: A _ B _ D _

parent2: d f b e a c filler block: _ f _ e _ c

child1: A f B e D c Despite the fact that OrderBased behaves differently from Position crossover they are identical in expectation.

Source: Modeling Simple Genetic Algorithms for Permutation Problems. Darrell Whitley , Nam-wook Yoo (1995) http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.3585

func NewOrderBasedCrossover

func NewOrderBasedCrossover() *OrderBasedCrossover

func (*OrderBasedCrossover) CanProduceCopiesOfParents

func (crossover *OrderBasedCrossover) CanProduceCopiesOfParents(val bool) *OrderBasedCrossover

func (*OrderBasedCrossover) Crossover

func (crossover *OrderBasedCrossover) Crossover(parents Chromosomes) Chromosomes

func (*OrderBasedCrossover) ParentsCount

func (crossover *OrderBasedCrossover) ParentsCount() int

type OrderCrossoverVer1

type OrderCrossoverVer1 struct{}

Crossover for ordered chromosomes. Tends to preserve relative order.

parent1: A B C D E parent2: d b e a c

cross section: _ * * _ _

child1 step1: _ B C _ _

parent2: d b e a c filler block: d _ e a _ The first element of filler block is added at the end of the cross setion.

child1: a B C d e

Source: Modeling Simple Genetic Algorithms for Permutation Problems. Darrell Whitley , Nam-wook Yoo (1995) http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.3585

type OrderCrossoverVer2

type OrderCrossoverVer2 struct{}

Crossover for ordered chromosomes. Tends to preserve relative order.

parent1: A B C D E parent2: d b e a c

cross section: _ * * _ _

child1 step1: _ B C _ _

parent2: d b e a c filler block: d _ e a _ The first element of filler block is added at the start of the child.

child1: d B C e a

Source: On Genetic Crossover Operators for Relative Order Preservation http://www.dmi.unict.it/mpavone/nc-cs/materiale/moscato89.pdf

type OrderedChromosome

type OrderedChromosome struct {
	*ChromosomeBase
	// contains filtered or unexported fields
}

func NewOrderedChromosome

func NewOrderedChromosome(genes OrderedGenes) *OrderedChromosome

func (*OrderedChromosome) Genes

func (chrom *OrderedChromosome) Genes() GenesInterface

func (*OrderedChromosome) Ind

func (chrom *OrderedChromosome) Ind(val int) int

func (*OrderedChromosome) OrderedGenes

func (chrom *OrderedChromosome) OrderedGenes() OrderedGenes

func (*OrderedChromosome) String

func (chrom *OrderedChromosome) String() string

type OrderedGenes

type OrderedGenes []int

func (OrderedGenes) Copy

func (g OrderedGenes) Copy(genes GenesInterface, from1, from2, to2 int) int

func (OrderedGenes) Get

func (g OrderedGenes) Get(i int) interface{}

func (OrderedGenes) Ind

func (g OrderedGenes) Ind(val int) int

func (OrderedGenes) Len

func (g OrderedGenes) Len() int

func (OrderedGenes) Set

func (g OrderedGenes) Set(i int, val interface{})

func (OrderedGenes) Swap

func (g OrderedGenes) Swap(i, j int)

type OrderedRandomInitializer

type OrderedRandomInitializer struct {
}

func NewOrderedRandomInitializer

func NewOrderedRandomInitializer() *OrderedRandomInitializer

func (*OrderedRandomInitializer) Init

func (initializer *OrderedRandomInitializer) Init(count, chromSize int) Chromosomes

type PartiallyMappedCrossover

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

Crossover for ordered chromosomes. Tends to preserve absolute order.

Source: Modeling Simple Genetic Algorithms for Permutation Problems. Darrell Whitley , Nam-wook Yoo (1995) http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.3585

func NewPartiallyMappedCrossover

func NewPartiallyMappedCrossover() *PartiallyMappedCrossover

func (*PartiallyMappedCrossover) CanProduceCopiesOfParents

func (crossover *PartiallyMappedCrossover) CanProduceCopiesOfParents(val bool) *PartiallyMappedCrossover

func (*PartiallyMappedCrossover) Crossover

func (crossover *PartiallyMappedCrossover) Crossover(parents Chromosomes) Chromosomes

func (*PartiallyMappedCrossover) ParentsCount

func (crossover *PartiallyMappedCrossover) ParentsCount() int

type PositionBasedCrossover

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

Crossover for ordered chromosomes. Generalization of OrderCrossoverVer2. Tends to preserve relative order.

parent1: A B C D E parent2: d b e a c

mask: _ * _ * _ parent1: A B C D E

child1 step1: _ B _ D _

parent2: d b e a c filler block: _ _ e a c

child1: e B a D c

Source: Modeling Simple Genetic Algorithms for Permutation Problems. Darrell Whitley, Nam-wook Yoo (1995) http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.3585

func NewPositionBasedCrossover

func NewPositionBasedCrossover() *PositionBasedCrossover

func (*PositionBasedCrossover) CanProduceCopiesOfParents

func (crossover *PositionBasedCrossover) CanProduceCopiesOfParents(val bool) *PositionBasedCrossover

func (*PositionBasedCrossover) Crossover

func (crossover *PositionBasedCrossover) Crossover(parents Chromosomes) Chromosomes

func (*PositionBasedCrossover) ParentsCount

func (crossover *PositionBasedCrossover) ParentsCount() int

type PrecedencePreservativeCrossover

type PrecedencePreservativeCrossover struct {
}

Crossover for ordered chromosomes. Tends to preserve absolute order.

Source: Introduction to Genetic Algorithms. S.N. Sivanandam, S. N. Deepa (2008) http://www.amazon.com/Introduction-Genetic-Algorithms-S-N-Sivanandam/dp/354073189X/

func NewPrecedencePreservativeCrossover

func NewPrecedencePreservativeCrossover() *PrecedencePreservativeCrossover

func (*PrecedencePreservativeCrossover) Crossover

func (crossover *PrecedencePreservativeCrossover) Crossover(parents Chromosomes) Chromosomes

func (*PrecedencePreservativeCrossover) ParentsCount

func (crossover *PrecedencePreservativeCrossover) ParentsCount() int

type RelativeOrderingCrossover

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

Crossover for ordered chromosomes. Tends to preserve relative order.

Ordering genetic algorithms and deception. Hillol Kargupta, Ka. Lyanmoy Deb, David E. Goldberg (1992) http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.94.6805

func NewRelativeOrderingCrossover

func NewRelativeOrderingCrossover(preservedGenes int) *RelativeOrderingCrossover

func (*RelativeOrderingCrossover) Crossover

func (crossover *RelativeOrderingCrossover) Crossover(parents Chromosomes) Chromosomes

func (*RelativeOrderingCrossover) ParentsCount

func (crossover *RelativeOrderingCrossover) ParentsCount() int

type RouletteWheelCostWeightingSelector

type RouletteWheelCostWeightingSelector struct {
	*SelectorBase
	// contains filtered or unexported fields
}

Selects individual with probability proportional to it fitness value. Warning! In order to use this selector cost value must be normalized, i.e. chromosome with cost=0 is the best solution.

func NewRouletteWheelCostWeightingSelector

func NewRouletteWheelCostWeightingSelector() *RouletteWheelCostWeightingSelector

func (*RouletteWheelCostWeightingSelector) Prepare

func (selector *RouletteWheelCostWeightingSelector) Prepare(population Chromosomes)

func (*RouletteWheelCostWeightingSelector) SelectInd

func (selector *RouletteWheelCostWeightingSelector) SelectInd() int

type RouletteWheelRankWeightingSelector

type RouletteWheelRankWeightingSelector struct {
	*SelectorBase
	// contains filtered or unexported fields
}

Selects individual with probability proportional to it fitness value. Warning! In order to use this selector cost value must be normalized, i.e. chromosome with cost=0 is the best solution.

func NewRouletteWheelRankWeightingSelector

func NewRouletteWheelRankWeightingSelector() *RouletteWheelRankWeightingSelector

func (*RouletteWheelRankWeightingSelector) Prepare

func (selector *RouletteWheelRankWeightingSelector) Prepare(population Chromosomes)

func (*RouletteWheelRankWeightingSelector) SelectInd

func (selector *RouletteWheelRankWeightingSelector) SelectInd() int

type SelectorBase

type SelectorBase struct {
	SelectorBaseVirtualMInterface
	// contains filtered or unexported fields
}

Base class for selectors.

func NewSelectorBase

func NewSelectorBase(virtual SelectorBaseVirtualMInterface) *SelectorBase

Constructor for SelectorBase

func (*SelectorBase) Prepare

func (selector *SelectorBase) Prepare(population Chromosomes)

func (*SelectorBase) Select

func (selector *SelectorBase) Select() ChromosomeInterface

func (*SelectorBase) SelectMany

func (selector *SelectorBase) SelectMany(count int) Chromosomes

func (*SelectorBase) SelectManyAreUnique

func (selector *SelectorBase) SelectManyAreUnique(value bool) *SelectorBase

Sets whether or not SelectMany will return only unique chromosomes

type SelectorBaseVirtualMInterface

type SelectorBaseVirtualMInterface interface {
	SelectInd() int
}

SelectorBase's virtual methods

type SelectorInterface

type SelectorInterface interface {
	// Called once before selection for each population
	Prepare(Chromosomes)

	// Selects one parent from population
	Select() ChromosomeInterface
	// Selects c parents from population
	SelectMany(c int) Chromosomes
}

Interface for selectors -

type SimpleOptimizer

type SimpleOptimizer struct {
	*OptimizerBase
	// contains filtered or unexported fields
}

func NewSimpleOptimizer

func NewSimpleOptimizer() *SimpleOptimizer

func (*SimpleOptimizer) CrossoverProbability

func (optimizer *SimpleOptimizer) CrossoverProbability(crossoverProbability float64) *SimpleOptimizer

func (*SimpleOptimizer) Elitism

func (optimizer *SimpleOptimizer) Elitism(elitism int) *SimpleOptimizer

type SimpleTournamentSelector

type SimpleTournamentSelector struct {
	*SelectorBase
	// contains filtered or unexported fields
}

Selects several random individuals from population and then selectd best.

func NewRandomSelector

func NewRandomSelector() *SimpleTournamentSelector

func NewSimpleTournamentSelector

func NewSimpleTournamentSelector(contestants int) *SimpleTournamentSelector

Constructor for simple tournament selector. When contestants = 1 behaves like random selector

func (*SimpleTournamentSelector) SelectInd

func (selector *SimpleTournamentSelector) SelectInd() int

type SimpleWeeder

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

SimpleWeeder weeds part of population proportional to rate.

func NewSimpleWeeder

func NewSimpleWeeder(rate float64) *SimpleWeeder

Creates new SimpleWeeder. Rate must be in [0,100)

func (*SimpleWeeder) Weed

type StatisticsAggregatorInterface

type StatisticsAggregatorInterface interface {
	Aggregate(StatisticsDataInterface)
	// Calcs mean of aggregated data
	// Should be called on the end of aggregation
	Compute() StatisticsDataInterface
}

Statistics aggregator

type StatisticsAggregatorWithOptions

type StatisticsAggregatorWithOptions interface {
	StatisticsAggregatorInterface
	Options() StatisticsOptionsInterface
}

type StatisticsDataDefault

type StatisticsDataDefault interface {
	Generations() int
	Duration() time.Duration
	Durations() *HierarchicalDuration
	MinCost() float64
	MinCosts() []float64
	GenerationsWithoutImprovements() int
	MinCostsVar() float64
	MeanCost() float64
	MeanCosts() []float64
	WorstCost() float64
	WorstCosts() []float64
}

type StatisticsDataInterface

type StatisticsDataInterface interface{}

type StatisticsDefault

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

Default realization of StatisticsInterface

func (*StatisticsDefault) Data

func (statistics *StatisticsDefault) Data() StatisticsDataInterface

func (*StatisticsDefault) Duration

func (statistics *StatisticsDefault) Duration() time.Duration

Returns duration of optimization. If optimization are in progress then returns time elapsed from start.

func (*StatisticsDefault) Durations

func (statistics *StatisticsDefault) Durations() *HierarchicalDuration

Returns entire tracked hierarchy of duration

func (*StatisticsDefault) End

func (statistics *StatisticsDefault) End()

func (*StatisticsDefault) Generations

func (statistics *StatisticsDefault) Generations() int

Number of generations

func (*StatisticsDefault) GenerationsWithoutImprovements

func (statistics *StatisticsDefault) GenerationsWithoutImprovements() int

Number of generations during which the min cost remains unchanged

func (*StatisticsDefault) MeanCost

func (statistics *StatisticsDefault) MeanCost() float64

Mean cost of last iteration

func (*StatisticsDefault) MeanCosts

func (statistics *StatisticsDefault) MeanCosts() []float64

Mean cost of each iteration Len would be `Iterations() + 1` because of initial value

func (*StatisticsDefault) MinCost

func (statistics *StatisticsDefault) MinCost() float64

Min cost for last iteration

func (*StatisticsDefault) MinCosts

func (statistics *StatisticsDefault) MinCosts() []float64

Min cost for each iteration Len would be `Generations() + 1` because of initial value

func (*StatisticsDefault) MinCostsVar

func (statistics *StatisticsDefault) MinCostsVar() float64

Variance of min costs Variance equals NaN until two different values of MinCost are obtained

func (*StatisticsDefault) OnGeneration

func (statistics *StatisticsDefault) OnGeneration(population Chromosomes)

Expects sorted population

func (*StatisticsDefault) Start

func (statistics *StatisticsDefault) Start(keys ...string)

func (*StatisticsDefault) WorstCost

func (statistics *StatisticsDefault) WorstCost() float64

Worst cost for last iteration

func (*StatisticsDefault) WorstCosts

func (statistics *StatisticsDefault) WorstCosts() []float64

Worst cost for each iteration Len would be `Iterations() + 1` because of initial value

type StatisticsDefaultAggregator

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

func (*StatisticsDefaultAggregator) Aggregate

func (aggregator *StatisticsDefaultAggregator) Aggregate(statistics StatisticsDataInterface)

func (*StatisticsDefaultAggregator) Compute

func (*StatisticsDefaultAggregator) Data

func (*StatisticsDefaultAggregator) Duration

func (aggregator *StatisticsDefaultAggregator) Duration() time.Duration

func (*StatisticsDefaultAggregator) Durations

func (aggregator *StatisticsDefaultAggregator) Durations() *HierarchicalDuration

func (*StatisticsDefaultAggregator) Generations

func (aggregator *StatisticsDefaultAggregator) Generations() int

func (*StatisticsDefaultAggregator) GenerationsWithoutImprovements

func (aggregator *StatisticsDefaultAggregator) GenerationsWithoutImprovements() int

func (*StatisticsDefaultAggregator) MeanCost

func (aggregator *StatisticsDefaultAggregator) MeanCost() float64

func (*StatisticsDefaultAggregator) MeanCosts

func (aggregator *StatisticsDefaultAggregator) MeanCosts() []float64

func (*StatisticsDefaultAggregator) MinCost

func (aggregator *StatisticsDefaultAggregator) MinCost() float64

func (*StatisticsDefaultAggregator) MinCosts

func (aggregator *StatisticsDefaultAggregator) MinCosts() []float64

func (*StatisticsDefaultAggregator) MinCostsVar

func (aggregator *StatisticsDefaultAggregator) MinCostsVar() float64

func (*StatisticsDefaultAggregator) Options

func (*StatisticsDefaultAggregator) WorstCost

func (aggregator *StatisticsDefaultAggregator) WorstCost() float64

func (*StatisticsDefaultAggregator) WorstCosts

func (aggregator *StatisticsDefaultAggregator) WorstCosts() []float64

type StatisticsDefaultOptions

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

Options for default statistics

func NewStatisticsDefaultOptions

func NewStatisticsDefaultOptions() *StatisticsDefaultOptions

func (*StatisticsDefaultOptions) Copy

func (*StatisticsDefaultOptions) Ensure

func (*StatisticsDefaultOptions) TrackDurations

func (options *StatisticsDefaultOptions) TrackDurations() *StatisticsDefaultOptions

func (*StatisticsDefaultOptions) TrackGenerationsWithoutImprovements

func (options *StatisticsDefaultOptions) TrackGenerationsWithoutImprovements() *StatisticsDefaultOptions

func (*StatisticsDefaultOptions) TrackMeanCost

func (options *StatisticsDefaultOptions) TrackMeanCost() *StatisticsDefaultOptions

func (*StatisticsDefaultOptions) TrackMeanCosts

func (options *StatisticsDefaultOptions) TrackMeanCosts() *StatisticsDefaultOptions

func (*StatisticsDefaultOptions) TrackMinCosts

func (options *StatisticsDefaultOptions) TrackMinCosts() *StatisticsDefaultOptions

func (*StatisticsDefaultOptions) TrackMinCostsVar

func (options *StatisticsDefaultOptions) TrackMinCostsVar() *StatisticsDefaultOptions

func (*StatisticsDefaultOptions) TrackWorstCost

func (options *StatisticsDefaultOptions) TrackWorstCost() *StatisticsDefaultOptions

func (*StatisticsDefaultOptions) TrackWorstCosts

func (options *StatisticsDefaultOptions) TrackWorstCosts() *StatisticsDefaultOptions

type StatisticsInterface

type StatisticsInterface interface {
	// Method for duration tracking
	// Call without parameters means that optimization is started
	Start(keys ...string)
	// Should be called when tracked operation is complete.
	End()
	// Optimizer will call this method on each generation
	// First call would be with initial population
	OnGeneration(Chromosomes)
	Data() StatisticsDataInterface
}

Accumulate statistics during optimization

func NewStatisticsDefault

func NewStatisticsDefault(options StatisticsOptionsInterface) StatisticsInterface

type StatisticsOptionsInterface

type StatisticsOptionsInterface interface {
	// Ensures that other tracks what ensurer tracks
	Ensure(other StatisticsOptionsInterface)
}

Options for statistics Defines what data gather and what not

type StopCriterionDefault

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

func NewStopCriterionDefault

func NewStopCriterionDefault() *StopCriterionDefault

func (*StopCriterionDefault) Max_Generations

func (criterion *StopCriterionDefault) Max_Generations(value int) *StopCriterionDefault

Stop when specified number of generations is reached

func (*StopCriterionDefault) Max_GenerationsWithoutImprovements

func (criterion *StopCriterionDefault) Max_GenerationsWithoutImprovements(value int) *StopCriterionDefault

Stop when min cost wasn't changed for value generations

func (*StopCriterionDefault) Min_Cost

func (criterion *StopCriterionDefault) Min_Cost(value float64) *StopCriterionDefault

Stop when min cost less than or equals value

func (*StopCriterionDefault) Min_MinCostsVar

func (criterion *StopCriterionDefault) Min_MinCostsVar(value float64) *StopCriterionDefault

Stop when variance of min costs less than or equals value

func (*StopCriterionDefault) Setup

func (criterion *StopCriterionDefault) Setup(opts StatisticsOptionsInterface)

func (*StopCriterionDefault) ShouldStop

func (criterion *StopCriterionDefault) ShouldStop(statistics StatisticsDataInterface) bool

type StopCriterionInterface

type StopCriterionInterface interface {
	// Method sets up statistics tracking
	// Executes one time before optimization
	Setup(StatisticsOptionsInterface)

	// Method executes each time before iteration
	ShouldStop(StatisticsDataInterface) bool
}

type SwapMutator

type SwapMutator struct {
}

Mutator simply swaps two elements

func (*SwapMutator) MutateCromosome

func (mutator *SwapMutator) MutateCromosome(chrom ChromosomeInterface, ind int)

type TournamentSelector

type TournamentSelector struct {
	*SelectorBase
	// contains filtered or unexported fields
}

Selects several random individuals from population and then runs tournament among them. See http://en.wikipedia.org/wiki/Tournament_selection

func NewTournamentSelector

func NewTournamentSelector(probability float64, contestants int) *TournamentSelector

Constructor for tournament selector.

Probability specify the probability that the best individual will be selected. Must be equal or grater than 0.5

func (*TournamentSelector) SelectInd

func (selector *TournamentSelector) SelectInd() int

type WeederInterface

type WeederInterface interface {
	Weed([]ChromosomeInterface) []ChromosomeInterface
}

Weeder weeds part of population.

Directories

Path Synopsis
examples
partition_with_plot
Draws plot of min and mean costs versus generations.
Draws plot of min and mean costs versus generations.
tsp

Jump to

Keyboard shortcuts

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