Skip to content

Latest commit

 

History

History
201 lines (155 loc) · 8.07 KB

README.md

File metadata and controls

201 lines (155 loc) · 8.07 KB

KGAL - Kotlin Genetic Algorithm Library

GitHub license Download Kotlin

One Max Problem Example

 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()

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 {
    // 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()
}

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.