resize

suspend fun <V, F> PanmicticEvolveScope<V, F>.resize(newSize: Int? = null, newBuffer: Int? = null, evaluateBuffered: Boolean = true, parallelismLimit: Int = parallelismConfig.workersCount, fitnessFunction: (V) -> F = this.fitnessFunction)

Sets PanmicticPopulation.size and PanmicticPopulation.buffer of population.

Prefer adjustSize over resize to increase or decrease only size by step.

Prefer adjustBuffer over resize to increase or decrease only buffer by step.

NOTE!

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

Parameters

newSize

Set as new PanmicticPopulation.size value if not null.

newBuffer

Set as new PanmicticPopulation.buffer value if not null. But PanmicticPopulation.buffer can be changed by changing PanmicticPopulation.size, see above.

  • Always must be positive or zero

  • Manual changing PanmicticPopulation.buffer will copy the existing population to a new array, which can take a significant amount of time

  • When manual increasing the value - its generate new chromosomes with Population.factory

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
resize(newSize = size + 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