{"id":39896865,"url":"https://github.com/vrettasm/pygeneticalgorithms","last_synced_at":"2026-02-01T16:02:21.316Z","repository":{"id":247387834,"uuid":"311952715","full_name":"vrettasm/PyGeneticAlgorithms","owner":"vrettasm","description":"This repository implements a genetic algorithm (GA) in Python3 programming language, using only Numpy and Joblib as additional libraries. It provides a basic StandardGA model as well as a more advanced IslandModelGA that evolves in parallel several different populations..","archived":false,"fork":false,"pushed_at":"2026-01-30T09:49:16.000Z","size":31098,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2026-01-31T01:38:42.536Z","etag":null,"topics":["genetic-algorithm","numpy","optimization-algorithms","parallel-genetic-algorithm","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vrettasm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-11-11T11:38:44.000Z","updated_at":"2026-01-30T09:49:19.000Z","dependencies_parsed_at":"2024-08-26T10:45:01.751Z","dependency_job_id":"cf26fd1a-3e51-4ae8-863d-da265e9cb5ad","html_url":"https://github.com/vrettasm/PyGeneticAlgorithms","commit_stats":null,"previous_names":["vrettasm/pygeneticalgorithms"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/vrettasm/PyGeneticAlgorithms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrettasm%2FPyGeneticAlgorithms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrettasm%2FPyGeneticAlgorithms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrettasm%2FPyGeneticAlgorithms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrettasm%2FPyGeneticAlgorithms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vrettasm","download_url":"https://codeload.github.com/vrettasm/PyGeneticAlgorithms/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrettasm%2FPyGeneticAlgorithms/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28981893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T15:35:50.179Z","status":"ssl_error","status_checked_at":"2026-02-01T15:35:38.075Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["genetic-algorithm","numpy","optimization-algorithms","parallel-genetic-algorithm","python3"],"created_at":"2026-01-18T15:08:43.483Z","updated_at":"2026-02-01T16:02:21.310Z","avatar_url":"https://github.com/vrettasm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyGenAlgo: A simple and powerful toolkit for genetic algorithms.\n\n![Logo](./logo/pga_logo.png)\n\n[![DOI](https://zenodo.org/badge/311952715.svg)](https://doi.org/10.5281/zenodo.18171837)\n\n[![linting: pylint](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/pylint-dev/pylint)\n\n**Pylint score: 9.10 / 10**\n\nThis repository implements a genetic algorithm toolbox in Python3 programming language, using only **Numpy** and **Joblib**\nas additional libraries. The basic approach offers a \"StandardGA\" class, where the whole population of chromosomes is\nreplaced by a new one at the end of each iteration (or epoch). More recently, a new computational model was added named\n\"IslandModelGA\" class that offers a new genetic operator (MigrationOperator), that allows for periodic migration of the\nbest individuals, among the (co-evolving) different island populations.\n  \n**NOTE**:\nFor computationally expensive fitness functions the StandardGA class provides the option of parallel evaluation\n(of the individual chromosomes), by setting in the method run(..., parallel=True). However, for fast fitness\nfunctions this will actually cause the algorithm to execute slower (due to the time required to open and close the\nparallel pool). So the default setting here is \"parallel=False\". Regarding the IslandModelGA, this is running in\nparallel mode by definition.\n\n  \u003e **NEWS**:\n  \u003e Recently three new features were added. The \"Neighborhood Selector\" operator is used for problems with multi-modal\n  \u003e objective functions. It allows the population to focus on multiple areas of the search space and detect more than\n  \u003e one optimal values. This features works in both computational modes (StandardGA and IslandModelGA). Moreover, the\n  \u003e Blend-α (BLX-α) crossover and Polynomial (PM-η) mutation operators were implemented with focus on real coded genomes.\n  \u003e \n\nThe current implementation offers a variety of genetic operators including:\n\n- **Selection operators**:\n  - [Linear Rank Selector](pygenalgo/operators/selection/linear_rank_selector.py)\n  - [Neighborhood Selector](pygenalgo/operators/selection/neighborhood_selector.py)\n  - [Random Selector](pygenalgo/operators/selection/random_selector.py)\n  - [Roulette Wheel Selector](pygenalgo/operators/selection/roulette_wheel_selector.py)\n  - [Stochastic Universal Selector](pygenalgo/operators/selection/stochastic_universal_selector.py)\n  - [Tournament Selector](pygenalgo/operators/selection/tournament_selector.py)\n  - [Truncation Selector](pygenalgo/operators/selection/truncation_selector.py)\n  - [Boltzmann Selector](pygenalgo/operators/selection/boltzmann_selector.py)\n\n- **Crossover operators**:\n  - [Single-Point Crossover](pygenalgo/operators/crossover/single_point_crossover.py)\n  - [Multi-Point Crossover](pygenalgo/operators/crossover/multi_point_crossover.py)\n  - [Uniform Crossover](pygenalgo/operators/crossover/uniform_crossover.py)\n  - [Order Crossover (OX1)](pygenalgo/operators/crossover/order_crossover.py)\n  - [Partially Mapped Crossover (PMX)](pygenalgo/operators/crossover/partially_mapped_crossover.py)\n  - [Position Based Crossover (POS)](pygenalgo/operators/crossover/position_based_crossover.py)\n  - [Blend-α Crossover (BLX-α)](pygenalgo/operators/crossover/blend_crossover.py)\n\n- **Mutation operators**:\n  - [Random Mutator](pygenalgo/operators/mutation/random_mutator.py)\n  - [Shuffle Mutator](pygenalgo/operators/mutation/shuffle_mutator.py)\n  - [Inverse Mutator](pygenalgo/operators/mutation/inverse_mutator.py)\n  - [Gaussian Mutator](pygenalgo/operators/mutation/gaussian_mutator.py)\n  - [Swap Mutator](pygenalgo/operators/mutation/swap_mutator.py)\n  - [Flip Mutator](pygenalgo/operators/mutation/flip_mutator.py)\n  - [Polynomial Mutator](pygenalgo/operators/mutation/polynomial_mutator.py)\n\n- **Migration operators**\n  - [Clockwise Migrator](pygenalgo/operators/migration/clockwise_migration.py)\n  - [Random Migrator](pygenalgo/operators/migration/random_migration.py)\n\n- **Meta operators**\n  - [Meta Selector](pygenalgo/operators/selection/meta_selector.py)\n  - [Meta Crossover](pygenalgo/operators/crossover/meta_crossover.py)\n  - [Meta Mutator](pygenalgo/operators/mutation/meta_mutator.py)\n  - [Meta Migration](pygenalgo/operators/migration/meta_migration.py)\n\n(**NOTE:** Meta operators call randomly other compatible operators (selection/crossover/mutation/migration)\nfrom a predefined set, with equal probability.)\n\nIncorporating additional genetic operators is easily facilitated by inheriting from the base classes:\n- [SelectionOperator](pygenalgo/operators/selection/select_operator.py)\n- [CrossoverOperator](pygenalgo/operators/crossover/crossover_operator.py)\n- [MutationOperator](pygenalgo/operators/mutation/mutate_operator.py)\n- [MigrationOperator](pygenalgo/operators/migration/migration_operator.py)\n\nand implementing the basic interface as described therein. In the examples that follow I show how one can use this code\nto run a GA for optimization problems (maximization/minimization) with and without constraints. The project is ongoing\nso new things might come along the way.\n\n### Installation\n\nThere are two options to install the software.\n\nThe easiest way is to download it from PyPI. Simply run the following command on a terminal:\n    \n    pip install pygenalgo\n\nAlternatively one can clone directly the latest version using git as follows:\n\n    git clone https://github.com/vrettasm/PyGeneticAlgorithms.git\n\nAfter the download of the code (or the git clone), one can use the following commands:\n\n    cd PyGeneticAlgorithms\n    pip install .\n\nThis will install the latest PyGenAlgo version in the package management system.\n\n### Required packages\n\nThe recommended version is Python 3.10 (and above). To simplify the required packages just use:\n\n    pip install -r requirements.txt\n\n### Fitness function\n\nThe most important thing the user has to do is to define the \"fitness function\". A template is provided here,\nin addition to the examples below. The cost_function decorator is used to indicate whether the function will\nbe maximized (default), or minimized. The second output parameter (\"solution_found\") is optional; only in the\ncases where we can evaluate if a termination condition is satisfied.\n\n```python\nfrom pygenalgo.genome.chromosome import Chromosome\nfrom pygenalgo.utils.utilities import cost_function\n\n\n# Fitness function \u003ctemplate\u003e.\n@cost_function(minimize=True)\ndef fitness_func(individual: Chromosome):\n    \"\"\"\n    This is how a fitness function should look like. The whole\n    evaluation should be implemented (or wrapped around) this\n    function.\n    \n    :param individual: Individual chromosome to be evaluated.\n    \n    :return: the function value evaluated at the individual.\n    \"\"\"\n\n    # Extract gene values from the chromosome.\n    x = individual.values()\n    \n    # ... CODE TO IMPLEMENT ...\n\n    # Compute the function value.\n    f_value = ...\n\n    # Condition for termination.\n    # We set it to True / False.\n    solution_found = ...\n\n    # Return the solution.\n    return f_value, solution_found\n# _end_def_\n```\nOnce the fitness function is defined correctly the next steps are straightforward as described in the examples.\n\n### Examples\n\nSome optimization examples on how to use these algorithms:\n\n| **Problem**                                                | **Variables** | **Objectives** | **Constraints** | **Optima** |\n|:-----------------------------------------------------------|:-------------:|:--------------:|:---------------:|:----------:|\n| [Sphere](examples/sphere.ipynb)                            |    M (=5)     |       1        |       no        |   single   |\n| [Rastrigin](examples/rastrigin.ipynb)                      |    M (=5)     |       1        |       no        |   single   |\n| [Rosenbrock](examples/rosenbrock_on_a_disk.ipynb)          |    M (=2)     |       1        |        1        |   single   |\n| [Binh \u0026 Korn](examples/binh_and_korn_multiobjective.ipynb) |    M (=2)     |       2        |        2        |   single   |\n| [Sphere (parallel)](examples/sphere_in_parallel.ipynb)     |    M (=10)    |       1        |       no        |   single   |\n| [Easom (parallel)](examples/easom_in_parallel.ipynb)       |    M (=2)     |       1        |       no        |   single   |\n| [Traveling Salesman](examples/tsp.ipynb)                   |    M (=10)    |       1        |       yes       |   single   |\n| [N-Queens](examples/queens_puzzle.ipynb)                   |    M (=8)     |       1        |       yes       |   single   |\n| [OneMax](examples/one_max.ipynb)                           |    M (=50)    |       1        |       no        |   single   |\n| [Tanaka](examples/tanaka_multiobjective.ipynb)             |    M (=2)     |       2        |        2        |   single   |\n| [Zakharov](examples/zakharov.ipynb)                        |    M (=8)     |       1        |       no        |   single   |\n| [Osyczka](examples/osyczka_kundu_multiobjective.ipynb)     |       6       |       2        |        6        |   single   |\n| [Shubert](examples/shubert_2D.ipynb)                       |       2       |       1        |       no        |  multiple  |\n| [Gaussian Mixture](examples/gaussian_mixture_2D.ipynb)     |       2       |       1        |       no        |  multiple  |\n\n\nConstraint optimization problems can be easily addressed using the [Penalty Method](https://en.wikipedia.org/wiki/Penalty_method).\nMoreover, multi-objective optimizations (with or without constraints) can also be solved, using the _weighted sum method_,\nas shown in the examples above. For multimodal optimizations check examples **Shubert** and **Gaussian Mixture**.\n\n## References and Documentation\n\nThis work is described in:\n\n- [Michail D. Vrettas and Stefano Silvestri (2025)](https://www.sciencedirect.com/science/article/pii/S2352711025000949)\n\"PyGenAlgo: a simple and powerful toolkit for genetic algorithms\". SoftwareX, vol. 30. DOI: 10.1016/j.softx.2025.102127.\n\nYou can find the latest documentation [here](https://pygeneticalgorithms.readthedocs.io/en/latest/).\n\n### Contact\n\nFor any questions/comments (**regarding this code**) please contact me at: vrettasm@gmail.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrettasm%2Fpygeneticalgorithms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvrettasm%2Fpygeneticalgorithms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrettasm%2Fpygeneticalgorithms/lists"}