Skip to content

Latest commit

 

History

History
116 lines (78 loc) · 4.1 KB

README.md

File metadata and controls

116 lines (78 loc) · 4.1 KB

Genetic Algorithms in C++

linux windows macos sanitizers code analysis docs

Overview

gapp is a library of genetic algorithm implementations in C++ for solving single- and multi-objective optimization problems. The algorithms are highly customizable, with all of their parts possibly defined by the user, but the library also includes GAs for several commonly used encoding types, frequently used crossover and mutation methods for each of these encodings, several stop conditions, and other utilities that can be used.

Usage example

#include <gapp/gapp.hpp>
#include <iostream>

using namespace gapp;

class SinX : public FitnessFunction<RealGene, 1> 
{
    FitnessVector invoke(const Chromosome<RealGene>& x) const override { return { std::sin(x[0]) }; }
};

int main()
{
    auto solutions = RCGA{}.solve(SinX{}, Bounds{ 0.0, 3.14 });

    std::cout << "The maximum of sin(x) in [0.0, 3.14] is at x = " << solutions[0].chromosome[0];
}

Possible console output:

The maximum of sin(x) in [0.0, 3.14] is at x = 1.57079

Requirements

The following are needed for building and using the library:

  • C++20 compiler (gcc 11.0, clang 15.0, msvc 14.30 or later)
  • CMake 3.21 or later
  • Catch2 3.3 or later (optional, only needed for the tests)

Installing the library

See install-guide.md for a more detailed installation and usage guide.

The library uses CMake as its build system. Assuming you have all of the requirements listed above, the steps for installing the library in Release config are:

git clone https://github.com/KRM7/gapp.git --branch v0.2.0
cd gapp/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF
cmake --build . --config Release
sudo cmake --install . --config Release

Alternatively, you can also use the install script that is provided with the library, which will install all available configurations:

git clone https://github.com/KRM7/gapp.git --branch v0.2.0
sudo bash ./gapp/tools/install.sh

Once the library is installed, you can import it using find_package and then link against the gapp::gapp target provided by the library:

find_package(gapp REQUIRED)
target_link_libraries(YourTarget PRIVATE gapp::gapp)

Documentation

The documentation for the library can be found in the docs directory:

The API documentation is available here.

Examples

The examples directory contains several examples for using the library.