adjustSize

suspend fun <V, F> PanmicticEvolveScope<V, F>.adjustSize(step: Int, evaluateBuffered: Boolean = true, parallelismLimit: Int = parallelismConfig.workersCount, fitnessFunction: (V) -> F = this.fitnessFunction)

Sets PanmicticPopulation.size = PanmicticPopulation.size + step

NOTE!

evolve {
var size = population.size // = 100
var buffer = population.buffer // = 50
adjustSize(step = 10)
size = population.size // = 110
buffer = population.buffer // = 40
adjustSize(step = 50)
// buffer limit exceeded, created new array with maxSize = 160
size = population.size // = 160
buffer = population.buffer // = 0 (buffer overflow)
adjustSize(step = -60)
size = population.size // = 100
buffer = population.buffer // = 60 (buffer increased cause overflow)
}

Parameters

step

step value for new size

evaluateBuffered

param for optimization. Default value is true for predictable behaviour. If true - execute evaluation by fitnessFunction for new chromosomes in range: oldSize..

  • No evaluations if newSize is null or newSize less than oldSize

Set it to false for optimization by skipping double evaluation in case:

evolve {
// other genetic operators
adjustSize(by = 5, evaluateBuffered = false)
// Danger zone: New chromosomes can be not evaluated
evaluation() // evaluates in range 0..<newSize
// Safe zone: all active chromosomes evaluated
// other genetic operators
}
parallelismLimit

limit of parallel workers

fitnessFunction

fitnessFunction for evaluation

See also