Skip to content

sfuhrm/geneticalgorithm

Repository files navigation

Genetic Algorithm in Java

Java CI with Maven Codacy Badge Codacy Badge Maven Central javadoc ReleaseDate License

Purpose

A genetic algorithm library in Java with focus on easy usage and high performance. Genetic algorithms are meta heuristics inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms. Genetic algorithms can solve optimization problems when there's only an evaluation function available (also known as fitness function).

Illustration: Integer guessing

The following illustration shows the library guessing a sequence of 30 int values with a genetic population size of 3000 hypothesis. At the beginning many components of the population are wrong (=red). With almost every generation (=line) the population improves in fitness and more and more components turn from wrong (=red) to correct (=green).

Guessing an int sequence

See sample code.

Using the library

The process of using the library is summarized in the following picture: Steps for using GeneticAlgorithm

An overview of the classes is given in the following class diagram: Class diagram of GeneticAlgorithm

There is a javadoc documentation online for a more detailed discussion on the classes.

Example

There is a stand-alone Java application in the Maven subproject geneticalgorithm-example-int-guessing. This example tries to guess one sequence of integer numbers. One example is to guess the sequence [0, 1, 2, 3, 4].

Please see the example code in GuessingExample.java.

Including genetic algorithm in your projects

The recommended way of including the library into your project is using Apache Maven:


<dependency>
    <groupId>de.sfuhrm</groupId>
    <artifactId>geneticalgorithm</artifactId>
    <version>3.0.0</version>
</dependency>

Requirements

The library uses Java 8 functions and will only work with Java 8 and above. There are no libraries needed besides those build-in the JDK.

Algorithm reference

The algorithm is based on the book Machine learning. Tom M. Mitchell. Published by McGraw-Hill (ISBN 0-07-115467-1).

License

Copyright 2016-2022 Stephan Fuhrmann

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.