PHPackages                             bartvig/simple-ga - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bartvig/simple-ga

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bartvig/simple-ga
=================

1.0.5(6y ago)129MITPHP

Since Sep 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/bartvig/simple-ga)[ Packagist](https://packagist.org/packages/bartvig/simple-ga)[ RSS](/packages/bartvig-simple-ga/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (7)Used By (0)

simple-ga
=========

[](#simple-ga)

Simple Genetic Algorithm Implementation in PHP

This is a rather quick and dirty implementation of genetic algorithms with a generic genome and a population of genomes.

Some elements such as population size, how many of the best genomes to copy to the next generation, number of new random genomes for each generation, and mutation quotient can be configured with dependency injection (with Pimple).

Other customizations can be performed by overriding the classes `Genome` and `Population`.

For an example of how to use SimpleGA, see

Installation
------------

[](#installation)

Use composer to install required libraries: `composer install`. Then you might have to run `composer dump-autoload -o` to make autoloading work properly.

Installation of composer is out of scope for this documentation.

How to run
----------

[](#how-to-run)

This is a generic implementation and can't be run on its own. See  for an example of how to use this implementation.

Configuration
-------------

[](#configuration)

These variables must be configured in a Pimple container:

- `population_size`: number of genomes in a population.
- `population_random`: how many genomes to generate randomly for each population. This can be useful to introduce new random genes in a population.
- `elite_count`: number of best genomes to copy to the next generation.
- `mutation_promille`: mutation rate in thousandths, e.g. a mutation rate of 5% is `50`.
- `genome`: generation of a specific genome implementation. This should return a new instance of a genome class. Example (when the Pimple container is called `$container`): `$container['genome'] = $container->factory(function ($c) { return new \QueensGA\QueensGenome($c); });`

This variable can be configured:

- `evaluate_points`: this is an associative array of keys and values to evaluate genomes against. E.g. some points in a quadratic equation: `[ 0 => 0, 2 => 4, 4 => 16 ]`.

Genome
------

[](#genome)

A genome is a proposed solution to the problem we're trying to solve.

### These functions must be overridden

[](#these-functions-must-be-overridden)

`Genome::mutate()` and `Genome::evaluate()` don't do anything and must be overridden by a specific implementation of a problem to be solved with the genetic algorithm.

`mutate()` should change one or more genes in a genome by random. There is no default mutation.

`evaluate()` has to evaluate the fitness of the genome - the more fit the genome, the lower the value. 0 is the lowest allowed fitness.

### Optional functions to override

[](#optional-functions-to-override)

By default the genes of a genome are elements in an array. This makes crossover and producing offspring easy, as we only need to slice and merge arrays. You can override `Genome::generate()` and `Genome::getPart()`, if you want the genes to be constructed as something else than an array.

If you want to output a genome in each generation or when the execution is done, you should override `Genome::toString()`.

Population
----------

[](#population)

A population of genomes is handled by generating genomes, sorting genomes according to fitness, producing new genomes, and mutate genomes.

This class doesn't need to be overridden and handles the basics. `Population::initialize()` initializes the population according to the configuration. For each new generation, call `Population::nextGeneration()`. This function performs the following steps, using values from the configuration:

1. Copy most `elite_count` fit genomes to the next generation.
2. Produce offspring. More fit genomes are more likely to be selected for crossover. Two genomes are selected and two crossover points are chosen by random to generate two half genomes for each parent. These half genomes are mixed to produce two children.
3. Evaluate entire population. If `evaluate_points` is configured, use these values to evaluate the genomes. Else the genomes are evaluated on their own without external values.

When a generation is complete, you can get the most fit genome with `Population::getFittestGenome()`.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~166 days

Recently: every ~208 days

Total

6

Last Release

2338d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ff31cb58bd262e057a9240d3e8fb0bc755e113d5a151d26681b23665b1f9ba99?d=identicon)[bartvig](/maintainers/bartvig)

---

Top Contributors

[![bartvig](https://avatars.githubusercontent.com/u/10400811?v=4)](https://github.com/bartvig "bartvig (45 commits)")

### Embed Badge

![Health badge](/badges/bartvig-simple-ga/health.svg)

```
[![Health](https://phpackages.com/badges/bartvig-simple-ga/health.svg)](https://phpackages.com/packages/bartvig-simple-ga)
```

###  Alternatives

[ckfinder/ckfinder-laravel-package

CKFinder 3 package for Laravel

159497.2k48](/packages/ckfinder-ckfinder-laravel-package)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[ckfinder/ckfinder-symfony-bundle

CKFinder bundle for Symfony

42435.7k](/packages/ckfinder-ckfinder-symfony-bundle)[inpsyde/wp-app-container

DI Container and related tools to be used at website level.

41253.5k](/packages/inpsyde-wp-app-container)[rockettheme/toolbox

RocketTheme Toolbox Library

22526.9k3](/packages/rockettheme-toolbox)[rochamarcelo/cake-pimple-di

A cakephp plugin for dependency injection based on Pimple library

12176.8k](/packages/rochamarcelo-cake-pimple-di)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
