pGA( // PanmicticGA (Classical GA)
population = population(size = 200) { booleans(size = 100) },
fitnessFunction = { value -> value.count { it } },
) {
random = Random(seed = 42)
elitism = 10
before {
println("GA STARTED, Init population: $population")
}
// create evolution strategy
evolve {
selTournament(size = 3) // select
cxOnePoint(chance = 0.8) // crossover
mutFlipBit(chance = 0.2, flipBitChance = 0.01) // mutate
evaluation() // evaluate population
stopBy(maxIteration = 50) { bestFitness == 100 } // finish GA by conditions
}
after {
println("GA FINISHED, Result = $best")
}
}.startBlocking()
- Panmictic (Classical) Genetic Algorithm (PanmicticGA)
- Dynamic population size
- Panmictic elitism
- Cellular Genetic Algorithm (CellularGA)
- VonNeumann and Moore neighborhoods
- Synchronous and Asynchronous types
- Multidimensional cellular population based on Toroidal Shape
- Cellular elitism
- Distributed Genetic Algorithm (DistributedGA), include Island Genetic Algorithm
- Support child genetic algorithms (more than subpopulations)
- Synchronization child GAs (launching, shared statistics, shared population)
- Built-in genetic operators:
selection
,crossover
,mutation
,evaluation
,migration
(DistributedGA only) - Flexible Customization
- Typed Chromosome (individuals), built-in variants
- Simple custom genetic operators based on low-api level
- Full control of the evolutionary process: mutable population, mutable fitness function, stops any moment, dynamic evolution strategies
- Parallelism support for all types of GAs powered by Kotlin Coroutines:
- Statistics powered by Kotlin Flows
- Built-in best, worst, mean, median, time, size stats
- Sessions statistics
- Explicit GA Api powered by Kotlin Coroutines:
start()
,stop()
,resume()
,restart()
- Kotlin DSL style
- api — examples of using api kgal capabilities
- controller — using interactive api (GA.start, GA.resume, GA.stop, GA.restart)
- customization — GA customization possibilities for various tasks
- population — creating populations for GA
- statistics — working with statistics
- api capabilities — great example of solving the One Max Problem using various kgal api capabilities
- tasks — a collection of examples of solved problems using kgal
- one max problem — solving of the most famous problem for GA
- extremum search — a collection of problems of finding extrema of complex functions
- single source shortest paths — solution to the SSSP problem by GA
- travelling salesman problem — solution to the TSP by GA + comparison with dynamic programming
Add dependencies (you can also add other modules that you need):
<dependency>
<groupId>io.github.orthodoxal</groupId>
<artifactId>kgal-core</artifactId>
<version>0.0.5</version>
</dependency>
And make sure that you use the latest Kotlin version:
<properties>
<kotlin.version>2.0.20</kotlin.version>
</properties>
Add dependencies (you can also add other modules that you need):
dependencies {
implementation("io.github.orthodoxal:kgal-core:0.0.5")
}
And make sure that you use the latest Kotlin version:
plugins {
// For build.gradle.kts (Kotlin DSL)
kotlin("jvm") version "2.0.20"
// For build.gradle (Groovy DSL)
id "org.jetbrains.kotlin.jvm" version "2.0.20"
}
Make sure that you have mavenCentral()
in the list of repositories:
repositories {
mavenCentral()
}
KGAL fully supports Kotlin Multiplatform
.
In common code that should get compiled for different platforms, you can add a dependency to kgal-core
right to the commonMain
source set:
commonMain {
dependencies {
implementation("io.github.orthodoxal:kgal-core:0.0.5")
}
}
See documentation generated by dokka
.