PHPackages                             darvin/genetic-algorithm - 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. darvin/genetic-algorithm

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

darvin/genetic-algorithm
========================

A PHP Library inspired by Charles Darwin's theory

v1.0.3(6y ago)031MITPHP

Since Mar 20Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jadenjoy/genetic-algorithm)[ Packagist](https://packagist.org/packages/darvin/genetic-algorithm)[ RSS](/packages/darvin-genetic-algorithm/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (4)Used By (0)

 [![](resources/images/icons/icon.png)](resources/images/icons/icon.png) Genetic Algorithm
===========================================================================================

[](#--------genetic-algorithm)

[![Latest Version on Packagist](https://camo.githubusercontent.com/11272b0fb229ada4cfe1f2a325ee28b03536a66f0c315a32e8460c732dfaa226/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64617276696e2f67656e657469632d616c676f726974686d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/darvin/genetic-algorithm)[![Quality Score](https://camo.githubusercontent.com/01072735bcaad5785f42051b048cf9f39b42b513a0dbb828b963891292b4a629/68747470733a2f2f7777772e636f64652d696e73706563746f722e636f6d2f70726f6a6563742f353231372f73636f72652f737667)](https://frontend.code-inspector.com/public/project/5217/genetic-algorithm/dashboard)[![Code Grade](https://camo.githubusercontent.com/5de6c8383f04022180ca0443b09e45bcf44268c8f478ba537ee2a6748bef1594/68747470733a2f2f7777772e636f64652d696e73706563746f722e636f6d2f70726f6a6563742f353231372f7374617475732f737667)](https://frontend.code-inspector.com/public/project/5217/genetic-algorithm/dashboard)[![License](https://camo.githubusercontent.com/73901afd3d69db41a57a32cec6e934b412d66c6c6c3b56ee0c26dc03d8c3cb3e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6164656e6a6f792f67656e657469632d616c676f726974686d)](https://packagist.org/packages/darvin/genetic-algorithm)

This package allows you to use **Genetic Algorithms** in your **projects**. It will help high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation, crossover and selection.

The simplest algorithm represents each chromosome as a bit string. Though it is possible to use any php data types **Float, String, Booleans, Array, Object**.

---

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

[](#installation)

You can install the package via composer:

```
composer require darvin/genetic-algorithm
```

---

Usage
-----

[](#usage)

#### Settings

[](#settings)

Algorithm needs settings to work, so lets starts with the default:

```
$config = new \Darvin\GeneticAlgorithm\Settings\DefaultSettings();
$algorithm = new Algorithm($config);
```

#### Individual Generation

[](#individual-generation)

An individual is characterized by a set of parameters (variables) known as Genes. Lets say that we encode the genes in a chromosome.

```
$algorithm->setPart("individual:gene", function (Gene $gene) {
    $characters = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-+,. ');
    $gene->value($characters[rand(0, count($characters)-1)]);
});
```

#### Fitness Function

[](#fitness-function)

The fitness function determines how fit an individual is (the ability of an individual to compete with other individuals). It gives a fitness score to each individual. The probability that an individual will be selected for reproduction is based on its fitness score.

```
$algorithm->setPart("fitness", function (Individual $individual) use ($solution) {
    $fitness = 0;
    for ($i=0; $i < $individual->genomeSize() && $i < count($solution); $i++) {
        $char_diff=abs(ord($individual->getGene($i)->value) - ord($solution[$i]));
        $fitness+=$char_diff;
    }
    return $fitness;
});
```

#### Events

[](#events)

You can setup Events to listen and control Algorithm.

##### Algorithm Start

[](#algorithm-start)

```
$algorithm->setPart("event:listen:algorithmStart", function (Algorithm $algorithm) {
    echo "Algorithm start.\n";
});
```

##### New Solution

[](#new-solution)

```
$algorithm->setPart("event:listen:newSolutionFound", function (Algorithm $algorithm) {
    echo "New solution found!";
});
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for further details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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 ~0 days

Total

3

Last Release

2248d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5a204a7dc65ae12a706e8c11eb91d7a8a93d17ddfa6d94a6b0a41496a63f9e0b?d=identicon)[jadenjoy](/maintainers/jadenjoy)

---

Top Contributors

[![jadenjoy](https://avatars.githubusercontent.com/u/22222462?v=4)](https://github.com/jadenjoy "jadenjoy (11 commits)")

### Embed Badge

![Health badge](/badges/darvin-genetic-algorithm/health.svg)

```
[![Health](https://phpackages.com/badges/darvin-genetic-algorithm/health.svg)](https://phpackages.com/packages/darvin-genetic-algorithm)
```

PHPackages © 2026

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