PHPackages                             petercoles/gao - 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. [Framework](/categories/framework)
4. /
5. petercoles/gao

ActiveLibrary[Framework](/categories/framework)

petercoles/gao
==============

PHP framework for performing Genetic Algorithm Optimisation

0.1.0(7y ago)0105MITPHPPHP ^7.1

Since Jul 4Pushed 7y ago1 watchersCompare

[ Source](https://github.com/petercoles/genetic-algorithm-optimiser)[ Packagist](https://packagist.org/packages/petercoles/gao)[ Docs](https://github.com/petercoles/laraGAO)[ RSS](/packages/petercoles-gao/feed)WikiDiscussions master Synced 2w ago

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

Genetic Algorithm Optimiser
===========================

[](#genetic-algorithm-optimiser)

[Genetic Alorithms](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 petercoles/gao
```

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 PeterColes\GAO\Solution;

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

    public function evaluate($data = null)
    {
        $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 Optimiser(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)

- [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

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

2918d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2947594?v=4)[Peter Coles](/maintainers/petercoles)[@petercoles](https://github.com/petercoles)

---

Top Contributors

[![petercoles](https://avatars.githubusercontent.com/u/2947594?v=4)](https://github.com/petercoles "petercoles (30 commits)")

---

Tags

aiArtifical IntelligenceGAOGenetic Algorithm Optimisation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/petercoles-gao/health.svg)

```
[![Health](https://phpackages.com/badges/petercoles-gao/health.svg)](https://phpackages.com/packages/petercoles-gao)
```

###  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.5k17.6M518](/packages/laravel-boost)[laravel/ai

The official AI SDK for Laravel.

1.0k2.1M163](/packages/laravel-ai)[php-mcp/laravel

Laravel SDK for building Model Context Protocol (MCP) servers - Seamlessly integrate MCP tools, resources, and prompts into Laravel applications

472122.4k2](/packages/php-mcp-laravel)[modelflow-ai/symfony-bundle

An integration of modelflow-ai via a bundle into the Symfony Framework.

1520.6k](/packages/modelflow-ai-symfony-bundle)

PHPackages © 2026

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