Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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 ¶
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 ¶
SetPoints sets the number of crossover points.
If npts is not in the [0,MaxInt32] range SetPoints will return ErrInvalidXOverNumPoints.
func (*Crossover) SetPointsRange ¶
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 ¶
SetProb sets the crossover probability,
If prob is not in the [0,1] range SetProb will return ErrInvalidXOverProb.
func (*Crossover) SetProbRange ¶
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
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