dGA

inline fun <V, F> dGA(noinline factory: PopulationFactory<V, F>, noinline fitnessFunction: (V) -> F, populationName: String = DistributedPopulation.DEFAULT_DISTRIBUTED_POPULATION_NAME, children: List<GA<V, F>> = emptyList(), config: DistributedConfigScope<V, F>.() -> Unit): DistributedGA<V, F>

Creates DistributedGA with Kotlin DSL.

DistributedGA is friendly with parallelism, achieve almost linear speed up!

DistributedGA supports Shared statistics (see DistributedGA.statisticsProvider).

This builder support Distributed Inheritance for child created in config:

Distributed Inheritance - defines the feature for DistributedGA to inherit common properties (see above) to their children created in config scope. Each parameter from list can be overridden for each child with standard builders.

Example for OneMax task (island evolutionary strategy):

dGA(
// default factory for child populations
factory = { booleans(size = 100) },
// default fitness function for child populations
fitnessFunction = { value -> value.count { it } },
) {
// set pseudo random number generator for GA and their children
random = Random(seed = 42)

// set parallelism configuration
parallelismConfig {
// distributed parallelism - run each child GA independently in their own coroutine!
workersCount = 4
}

// create and add children GAs
+pGAs(
count = 4, // island count
population = { population(size = 50) }, // island population
) {
elitism = 5 // set island elitism

// create evolution strategy for island (can be different for each one)
evolve {
selTournament(size = 3) // island select
cxOnePoint(chance = 0.8) // island crossover
mutFlipBit(chance = 0.2, flipBitChance = 0.01) // island mutation
evaluation() // evaluate island population
stopBy(maxIteration = 20) { bestFitness == 100 } // island stop condition
}
}

// set distributed evolution strategy:
// launches children with ga.start() (default == true) before each iteration
evolve(useDefault = true) {
// limit only iterations for dGA not need stop condition by here cause useDefault is true
stopBy(maxIteration = 5)
// executes migration step between children (islands)
migration(percent = 0.1)
}

after {
println("GA FINISHED, Result = $best")
}
}.startBlocking()

Parameters

factory

default population factory for child GAs

fitnessFunction

default fitness function for evaluation step

populationName
children

child GA of DistributedGA (default is empty, recommend to use pGAs, cGAs functions to add children in config, see example above)

config

scope function to initialize DistributedGA

See also