PHPackages                             ravaelles/php-evolver - 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. ravaelles/php-evolver

ActiveLibrary

ravaelles/php-evolver
=====================

A generic PHP Genetic Algorithm Framework.

v1.0.0(7y ago)06MITPHPPHP ^7.1

Since Jul 4Pushed 3y agoCompare

[ Source](https://github.com/Ravaelles/php-evolver)[ Packagist](https://packagist.org/packages/ravaelles/php-evolver)[ Docs](https://github.com/phpexpertsinc/php-evolver)[ RSS](/packages/ravaelles-php-evolver/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

PHP Evolver: A Genetic Algorithm Framework
==========================================

[](#php-evolver-a-genetic-algorithm-framework)

[Genetic Algorithms](https://en.wikipedia.org/wiki/Genetic_algorithm) are a class of machine learning approaches that use the principles of natural selection, rather than the solving of mathematical formulae to find solutions to optimisation and search type problems. They are especially effective in complex situation that aren't easily "solved" and can often be used as a more-easily understood alternative to neural networks.

This framework takes care of most of the steps (loops) needed when developing and running a genetic algorithm, leaving you needing only to define the shape of your expected solution and a function to evaluate each candidate faciliating their comparison and thus the march towards an optimum.

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

[](#installation)

You can install the package via composer:

```
composer require phpexperts/php-evolver
```

Usage
-----

[](#usage)

### Framing and Finding Solutions

[](#framing-and-finding-solutions)

Firstly create a class that defines a generic solution to the problem to be solved. The class must extend this package's Solution class, which will force the implemetation of two methods: genome() which defines the shape of a valid solution and evaluate(), which will calculate a numerical value that can be used to compare solutions.

```
use PHPExperts\GAO\Solution;

class MySolution extends Solution
{
    public function genome()
    {
        return [
            ['char', 'ABC'],
            ['float', 0, 1], // upper and lower bounds
            ['integer', -100, 100],
        ];
    }

    public function evaluate($data = null)
    {
        // The smaller the fitness value, the better.
        $this->fitness = (ord($this->chromosomes[0]) + $this->chromosomes[2]) / $this->chromosomes[1];
    }
}
```

Then instantiate and run the optimiser, creating an initial population of possible solutions to start its evaluation.

```
$optimiser = new Breeder(new Population(MySolution::class, 100));
$optimiser->run();
foreach ($optimiser->results as $solution) {
    print_r($solution->summary());
}
```

### Data Manager

[](#data-manager)

Although some use cases may not require much, if any, data against which to evaluate candidate solutions, others may need astronomical amounts. This could be be the case in financial markets where a trading strategy is sought and candidates are evaluated against the evolution of prices for many different securities, or in sports trading markets where possible strategies may be evaluated against changes in odds for thousands of events.

The DataManager class offers utilities optimised to assist with htese challenges. Here's the sort of thing that it can do:

```
$dm = new DataManager();

// loads all files (assumed to be in CSV format) from given directory into an collection
$data = $dm->loadCsvDir('path/to/directory');

// PHP is really slow importing data into arrays - so once done, save the results (as json)
$dm->save('path/to/output/file', $data);

// It can be reloaded later from a json file in a tiny fraction of the time taken by the initial import
$data = $dm->load('path/to/output/file');

// to ensure our solutions works on data not seen during training, we may set aside some data (20% below) just for testing
list($trainingData, $testingData) = $dm->split($data, 0.2);
```

PHP is also rather memory hungry when constructing arrays. If you experience out of memory errors, then the following may help:

```
$dm->setMemoryLimit('1G'); // increases memory for the current process only, accepts values in M or G e.g. 512M or 2Gs
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

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

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker. I take security very seriously and will welcome and respond promptly to your input.

Credits
-------

[](#credits)

Forked from

- [Theodore R. Smith](https://github.com/hopeseekr)
- [Peter Coles](https://github.com/petercoles)
- [All Contributors](../../contributors)

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

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.2% 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 ~17 days

Total

3

Last Release

2841d ago

Major Versions

v0.9.0 → v1.0.02018-08-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b011dd390fab9e6e389b519ac8898449d28974137eb24b7df0e656c513c453f?d=identicon)[Ravaelles](/maintainers/Ravaelles)

---

Top Contributors

[![petercoles](https://avatars.githubusercontent.com/u/2947594?v=4)](https://github.com/petercoles "petercoles (30 commits)")[![hopeseekr](https://avatars.githubusercontent.com/u/1125541?v=4)](https://github.com/hopeseekr "hopeseekr (7 commits)")[![Ravaelles](https://avatars.githubusercontent.com/u/5878275?v=4)](https://github.com/Ravaelles "Ravaelles (3 commits)")[![sedatsevgili](https://avatars.githubusercontent.com/u/7056609?v=4)](https://github.com/sedatsevgili "sedatsevgili (1 commits)")

---

Tags

aigaArtifical IntelligenceGenetic Algorithm Framework

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ravaelles-php-evolver/health.svg)

```
[![Health](https://phpackages.com/badges/ravaelles-php-evolver/health.svg)](https://phpackages.com/packages/ravaelles-php-evolver)
```

###  Alternatives

[laravel/boost

Laravel Boost accelerates AI-assisted development by providing the essential context and structure that AI needs to generate high-quality, Laravel-specific code.

3.4k10.6M274](/packages/laravel-boost)

PHPackages © 2026

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