DistributedGA

interface DistributedGA<V, F> : GA<V, F>

DistributedGA - also known as the island genetic algorithm (dGA).

V - value of Chromosome

F - fitness value of Chromosome

DistributedGA is an algorithm that divides a large population into subpopulations and runs the genetic algorithm on each subpopulation independently. Kgal offers a broader and more universal definition for a DistributedGA: dGA is an algorithm that controls the evolutionary processes of child genetic algorithms (children).

The launched evolutionary processes of child GAs are calculated independently of each other, which allows for efficient and safe use of parallelism: set the value ParallelismConfig.workersCount equal to the number of child GAs (children.size), this will allow children to be launched on separate parallel coroutines that achieves almost linear speedup compared to the classical version of the genetic algorithm.

dGA(...) {
parallelismConfig {
// distributed parallelism:
// run each child GA independently in their own coroutine!
workersCount = DISTRIBUTED_GA_COUNT
}
}

The most popular type for DistributedGA is the island GA model, island evolutionary strategy includes:

  1. launching child genetic algorithms (including parallel mode) default

  2. synchronization of genetic algorithms (waiting for all to complete) default

  3. checking stop conditions (NOTE don't forget to set a limit on the number of iterations with stopBy(DISTRIBUTED_MAX_ITERATION), otherwise the evolution will happen endlessly)

  4. using genetic operators to interact between populations (for example: migration)

The first two steps are automated by kgal in the default behavior of the function DistributedConfigScope.evolve, so the island evolutionary strategy can be specified as:

evolve {
// maxIteration stop condition is necessary!
stopBy(maxIteration = DISTRIBUTED_MAX_ITERATION)
migration(percent = 0.1)
}

DistributedGA supports Shared statistics, see statisticsProvider.

Creates with Kotlin DSL by dGA.

See also

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Duration between all subsessions of Session.

Link copied to clipboard

Creates SessionsInfo that describes all activity of GA.

Link copied to clipboard
val <V, F> GA<V, F>.best: Chromosome<V, F>?

The best Chromosome in Population by fitness.

Link copied to clipboard
val <V, F> GA<V, F>.bestFitness: F?

The best fitness of Chromosome in Population.

Link copied to clipboard
abstract val children: List<GA<V, F>>

Contains current child genetic algorithms.

Link copied to clipboard

Population Factory of GA.

Link copied to clipboard
abstract var fitnessFunction: (V) -> F

Fitness function - a function that evaluates the quality or "fitness" of each individual (chromosome) in a population. The fitness function determines how well a particular solution matches the target problem. It can be changed.

Link copied to clipboard
abstract val isActive: Boolean

Return true if GA is active.

Link copied to clipboard
abstract val iteration: Int

Current iteration of genetic algorithm.

Link copied to clipboard
@get:JvmName(name = "getMeanDouble")
val GA<*, Double>.mean: Double
@get:JvmName(name = "getMeanInt")
val GA<*, Int>.mean: Double
@get:JvmName(name = "getMeanLong")
val GA<*, Long>.mean: Double

Mean fitness value of chromosomes in Population

Link copied to clipboard
@get:JvmName(name = "getMedianDouble")
val GA<*, Double>.median: Double
@get:JvmName(name = "getMedianInt")
val GA<*, Int>.median: Double
@get:JvmName(name = "getMedianLong")
val GA<*, Long>.median: Double

Median fitness value of chromosomes in Population

Link copied to clipboard
val GA<*, *>.name: String

Population Name of GA.

Link copied to clipboard
abstract override val population: DistributedPopulation<V, F>

The DistributedGA does not have its own population, but kgal defines this property as the total population of all subpopulations of child GAs (children).

Link copied to clipboard
abstract val random: Random

Random associated with GA. Defines a pseudorandom number generator for predictive calculations.

Link copied to clipboard
val GA<*, *>.size: Int

Population Size of GA.

Link copied to clipboard
abstract val state: State

State describes the current state of the genetic algorithm.

Link copied to clipboard
abstract override val statisticsProvider: StatisticsProvider

Shared statistics: DistributedGA is collector for each child statistics - statistics of DistributedGA includes all statistics of children:

Link copied to clipboard
abstract val timeStore: TimeStore

Store for all TimeMarkers of GA.

Link copied to clipboard
val <V, F> GA<V, F>.timeTotal: Duration

Duration between the first STARTED and last value of timeStore

Link copied to clipboard
val <V, F> GA<V, F>.worst: Chromosome<V, F>?

The worst Chromosome in Population by fitness.

Link copied to clipboard
val <V, F> GA<V, F>.worstFitness: F?

The worst fitness of Chromosome in Population.

Functions

Link copied to clipboard
inline suspend fun GA<*, *>.clearCollectors()

Unsubscribe and clear all collectors for StatisticsProvider.

Link copied to clipboard
fun <V, F> GA<V, F>.collect(id: String = BASE_COLLECTOR_ID, collector: STAT_COLLECTOR): GA<V, F>

Allows you to collect statistical data using reactive programming by kotlinx.coroutines.flow.

Link copied to clipboard
inline suspend fun GA<*, *>.removeCollector(id: String)

Unsubscribe and remove collector by id.

Link copied to clipboard
abstract suspend fun restart(forceStop: Boolean = false, resetPopulation: Boolean = true)

Immediately restart genetic algorithm.

Link copied to clipboard
abstract suspend fun resume()

Resume stopped genetic algorithm.

Link copied to clipboard
abstract suspend fun start()

Start genetic algorithm.

Link copied to clipboard
fun GA<*, *>.startBlocking(context: CoroutineContext = EmptyCoroutineContext)

Start GA with runBlocking, non suspend function.

Link copied to clipboard
abstract suspend fun stop(stopPolicy: StopPolicy = StopPolicy.Default)

Stop genetic algorithm.