xover

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2019 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidXOverNumPoints is the error returned when trying to set an
	// invalid number of crossover points
	ErrInvalidXOverNumPoints = errors.New("crossover points must be in the [0,MaxInt32] range")
	// ErrInvalidXOverProb is the error returned when trying to set an invalid
	// probability of crossover
	ErrInvalidXOverProb = errors.New("crossover probability must be in the [0,1] range")
)

Functions

This section is empty.

Types

type BitstringMater

type BitstringMater struct{}

BitstringMater mates a pair of bit-strings to produce a new pair of bit-strings

func (BitstringMater) Mate

func (BitstringMater) Mate(
	parent1, parent2 interface{}, nxpts int64,
	rng *rand.Rand) []interface{}

Mate performs crossover on a pair of parents to generate a pair of offspring.

parent1 and parent2 are the two individuals that provides the source material for generating offspring.

type ByteSliceMater

type ByteSliceMater struct{}

ByteSliceMater mates two []byte and produces a new pair of []byte

func (ByteSliceMater) Mate

func (m ByteSliceMater) Mate(
	parent1, parent2 interface{}, nxpts int64,
	rng *rand.Rand) []interface{}

Mate performs crossover on a pair of parents to generate a pair of offspring.

type Crossover

type Crossover struct {
	Mater
	// contains filtered or unexported fields
}

Crossover implements a standard crossover operator.

It supports all crossover processes that operate on a pair of parent candidates. Both the number of crossovers points and the crossover probability are configurable. Crossover is applied to a proportion of selected parent pairs, with the remainder copied unchanged into the output population. The size of this evolved proportion is controlled by the code crossoverProbability parameter.

func New

func New(mater Mater) *Crossover

New creates a Crossover operator based off the provided Mater.

The returned Crossover performs a one point crossover with 1.0 (i.e always) probability.

func (*Crossover) Apply

func (op *Crossover) Apply(sel []interface{}, rng *rand.Rand) []interface{}

Apply applies the crossover operation to the selected candidates.

Pairs of candidates are chosen randomly from the selected candidates and subjected to crossover to produce a pair of offspring candidates. The selected candidates, sel, are the evolved individuals that have survived to be eligible to reproduce.

Returns the combined set of evolved offsprings generated by applying crossover to the selected candidates.

func (*Crossover) SetPoints

func (op *Crossover) SetPoints(npts int) error

SetPoints sets the number of crossover points.

If npts is not in the [0,MaxInt32] range SetPoints will return ErrInvalidXOverNumPoints.

func (*Crossover) SetPointsRange

func (op *Crossover) SetPointsRange(min, max int) error

SetPointsRange sets the range of possible crossover points.

The specific number of crossover points will be randomly chosen with the pseudo random number generator argument of Apply, by linearly converting from [0,MaxInt32) to [min,max).

If min and max are not bounded by [0,MaxInt32] SetPointsRange will return ErrInvalidXOverNumPoints.

func (*Crossover) SetProb

func (op *Crossover) SetProb(prob float64) error

SetProb sets the crossover probability,

If prob is not in the [0,1] range SetProb will return ErrInvalidXOverProb.

func (*Crossover) SetProbRange

func (op *Crossover) SetProbRange(min, max float64) error

SetProbRange sets the range of possible crossover probabilities.

The specific crossover probability will be randomly chosen with the pseudo random number generator argument of Apply, by linearly converting from [0,1) to [min,max).

If min and max are not bounded by [0,1] SetProbRange will return ErrInvalidXOverProb.

type IntSliceMater

type IntSliceMater struct{}

IntSliceMater mates a pair of int slices to produce a new pair of int slices

func (IntSliceMater) Mate

func (m IntSliceMater) Mate(parent1, parent2 interface{}, npts int64,
	rng *rand.Rand) []interface{}

Mate performs crossover on a pair of parents to generate a pair of offspring.

type Mater

type Mater interface {

	// Mate performs crossover on a pair of parents to generate a pair of
	// offspring.
	//
	// parent1 and parent2 are the two individuals that provides the source
	// material for generating offspring.
	// TODO: should return 2 values of a slice of 2 values
	Mate(parent1, parent2 interface{},
		numberOfCrossoverPoints int64,
		rng *rand.Rand) []interface{}
}

Mater is the interface implemented by objects defining the Mate function.

type StringMater

type StringMater struct{}

StringMater mates a pair of strings to produce a new pair of bit strings

func (StringMater) Mate

func (m StringMater) Mate(
	parent1, parent2 interface{}, nxpts int64,
	rng *rand.Rand) []interface{}

Mate performs crossover on a pair of parents to generate a pair of offspring.

Jump to

Keyboard shortcuts

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