
Library facilitates implementation of genetic algorithms with features like panmictic, cellular, and distributed algorithms. Supports dynamic populations, elitism, parallelism, and extensive customization with built-in genetic operators.
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()selection, crossover, mutation, evaluation, migration (DistributedGA only)start(), stop(), resume(), restart()
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.
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()selection, crossover, mutation, evaluation, migration (DistributedGA only)start(), stop(), resume(), restart()
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.