KGAL - Kotlin Genetic Algorithm Library

One Max Problem Example
pGA(
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")
}
evolve {
selTournament(size = 3)
cxOnePoint(chance = 0.8)
mutFlipBit(chance = 0.2, flipBitChance = 0.01)
evaluation()
stopBy(maxIteration = 50) { bestFitness == 100 }
}
after {
println("GA FINISHED, Result = $best")
}
}.startBlocking()
Main Features
Examples
Using in your projects
Maven
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>
Gradle
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 {
kotlin("jvm") version "2.0.20"
id "org.jetbrains.kotlin.jvm" version "2.0.20"
}
Make sure that you have mavenCentral() in the list of repositories:
repositories {
mavenCentral()
}
Multiplatform
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")
}
}
Documentation
See documentation generated by dokka.