{"id":18894515,"url":"https://github.com/developerpaul123/genetic","last_synced_at":"2025-04-15T00:32:07.996Z","repository":{"id":197911218,"uuid":"644598777","full_name":"DeveloperPaul123/genetic","owner":"DeveloperPaul123","description":"A performant and flexible genetic algorithm implemented in C++20/23.","archived":false,"fork":false,"pushed_at":"2024-08-22T03:04:10.000Z","size":1701,"stargazers_count":19,"open_issues_count":5,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-28T13:05:17.123Z","etag":null,"topics":["cpp20","cpp20-lib","cpp20-library","cpp23","cpplib","cpplibrary","evolutionary-algorithm","evolutionary-algorithms","genetic-algorithm","genetic-algorithms","modern-cpp","optimisation","optimization","optimization-algorithms","optimization-methods","optimization-tools"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeveloperPaul123.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-23T21:28:29.000Z","updated_at":"2025-02-12T13:07:35.000Z","dependencies_parsed_at":"2023-10-03T12:24:53.912Z","dependency_job_id":"fed2de06-b588-445d-a6bf-4902999f818e","html_url":"https://github.com/DeveloperPaul123/genetic","commit_stats":{"total_commits":6,"total_committers":2,"mean_commits":3.0,"dds":"0.16666666666666663","last_synced_commit":"720a5a892515319e6f5e33698681016ecca6444f"},"previous_names":["developerpaul123/genetic"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperPaul123%2Fgenetic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperPaul123%2Fgenetic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperPaul123%2Fgenetic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeveloperPaul123%2Fgenetic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeveloperPaul123","download_url":"https://codeload.github.com/DeveloperPaul123/genetic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248984439,"owners_count":21193753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp20","cpp20-lib","cpp20-library","cpp23","cpplib","cpplibrary","evolutionary-algorithm","evolutionary-algorithms","genetic-algorithm","genetic-algorithms","modern-cpp","optimisation","optimization","optimization-algorithms","optimization-methods","optimization-tools"],"created_at":"2024-11-08T08:22:43.641Z","updated_at":"2025-04-15T00:32:04.802Z","avatar_url":"https://github.com/DeveloperPaul123.png","language":"C++","readme":"\u003ch1 align=center\u003e\ngenetic\n\u003c/h1\u003e\n\n[![say thanks](https://img.shields.io/badge/Say%20Thanks-👍-1EAEDB.svg)](https://github.com/DeveloperPaul123/genetic/stargazers)\n[![Discord](https://img.shields.io/discord/652515194572111872)](https://discord.gg/CX2ybByRnt)\n\nA flexible and performant implementation of the genetic algorithm in C++20/23.\n\n## Features\n\n- Built entirely with C++20/23\n- Includes many default operators for most use cases\n- Supply your own operations for:\n  - Selection\n  - Crossover\n  - Mutation\n  - Fitness\n  - Termination\n\n## Integration\n\n`dp::genetic` is a header only library. All the files needed are in `include/genetic`.\n\n### CMake\n\n`genetic` defines two CMake targets:\n\n- `Genetic::Genetic`\n- `dp::genetic`\n\nYou can then use `find_package()`:\n\n```cmake\nfind_package(dp::genetic REQUIRED)\n```\n\nAlternatively, you can use something like [CPM](https://github.com/TheLartians/CPM) which is based on CMake's `Fetch_Content` module.\n\n```cmake\nCPMAddPackage(\n    NAME genetic\n    GITHUB_REPOSITORY DeveloperPaul123/genetic\n    GIT_TAG 0.1.0 # change this to latest commit or release tag\n)\n```\n\n## Usage\n\n[Knapsack problem](https://en.wikipedia.org/wiki/Knapsack_problem) example:\n\n```cpp\n\nstruct knapsack_box {\n    int value;\n    int weight;\n    auto operator\u003c=\u003e(const knapsack_box\u0026) const = default;\n};\n\n// weight capacity of our knapsack\nconstexpr auto max_weight = 15;\n\n// available boxes for the knapsack\nstd::vector\u003cknapsack_box\u003e available_items = {{4, 12}, {2, 1}, {10, 4}, {1, 1}, {2, 2}};\n\n// fitness evaluator (omitted for brevity)\nauto fitness = { // ...};\n\n// random mutation operator (omitted for brevity)\nauto mutator = { // ... };\n\n// crossover operator (i.e. child generator, omitted for brevity)\nauto crossover = { // ... };\n\n// the solution is all the boxes except for the heaviest one.\nconst knapsack solution = {-1, 1, 2, 3, 4};\nconst knapsack all_items = {0, 1, 2, 3, 4};\n\n// genetic algorithm settings.\nconstexpr dp::genetic::algorithm_settings settings{0.1, 0.5, 0.25};\n\n// generate an initial random population\nconstexpr auto population_size = 2;\nstd::vector\u003cknapsack\u003e initial_population{};\ninitial_population.reserve(population_size);\n\n// generate the initial population\nstd::ranges::generate_n(std::back_inserter(initial_population), population_size,\n                        knapsack_generator);\n\n// define the termination criteria\nauto termination = dp::genetic::fitness_termination_criteria(fitness(solution));\n\n// setup the params object for the algorithm\nauto params = dp::genetic::params\u003cknapsack\u003e::builder()\n                    .with_mutation_operator(mutator)\n                    .with_crossover_operator(crossover)\n                    .with_fitness_operator(fitness)\n                    .with_termination_operator(termination)\n                    .build();\n\nauto [best, fitness] = dp::genetic::solve(initial_population, settings, params);\n\n```\n\nFor more details see the `/examples` folder and the unit tests under `/test`.\n\n## Building\n\nThis project has been built with:\n\n- Visual Studio 2022\n- Clang `10.+` (via WSL on Windows)\n- GCC `11.+` (via WSL on Windows)\n- CMake `3.21+`\n\nTo build, run:\n\n```bash\ncmake -S . -B build\ncmake --build build\n```\n\n### Build Options\n\n| Option | Description | Default |\n|:-------|:------------|:--------:|\n| `DP_GENETIC_BUILD_TESTS` | Turn on to build unit tests. Required for formatting build targets. | ON |\n| `DP_GENETIC_BUILD_EXAMPLES` | Turn on to build examples | ON |\n\n### Run clang-format\n\nUse the following commands from the project's root directory to check and fix C++ and CMake source style.\nThis requires _clang-format_, _cmake-format_ and _pyyaml_ to be installed on the current system. To use this feature you must turn on `TP_BUILD_TESTS`.\n\n```bash\n# view changes\ncmake --build build/test --target format\n\n# apply changes\ncmake --build build/test --target fix-format\n```\nSee [Format.cmake](https://github.com/TheLartians/Format.cmake) for details.\n\n### Build the documentation\n\nThe documentation is automatically built and [published](https://developerpaul123.github.io/genetic) whenever a [GitHub Release](https://help.github.com/en/github/administering-a-repository/managing-releases-in-a-repository) is created.\nTo manually build documentation, call the following command.\n\n```bash\ncmake -S documentation -B build/doc\ncmake --build build/doc --target GenerateDocs\n# view the docs\nopen build/doc/doxygen/html/index.html\n```\n\nTo build the documentation locally, you will need [Doxygen](https://www.doxygen.nl/) and [Graphviz](https://graphviz.org/) on your system.\n\n## Contributing\n\nContributions are very welcome. Please see [contribution guidelines for more info](CONTRIBUTING.md).\n\n## License\n\nThe project is licensed under the MIT license. See [LICENSE](LICENSE) for more details.\n\n## Author\n\n| [\u003cimg src=\"https://avatars0.githubusercontent.com/u/6591180?s=460\u0026v=4\" width=\"100\"\u003e\u003cbr\u003e\u003csub\u003e@DeveloperPaul123\u003c/sub\u003e](https://github.com/DeveloperPaul123) |\n|:----:|\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloperpaul123%2Fgenetic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeveloperpaul123%2Fgenetic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloperpaul123%2Fgenetic/lists"}