PHP code example of phpexperts / php-evolver

1. Go to this page and download the library: Download phpexperts/php-evolver library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpexperts / php-evolver example snippets

bash
composer 
 php
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];
    }
}
 php
$optimiser = new Breeder(new Population(MySolution::class, 100));
$optimiser->run();
foreach ($optimiser->results as $solution) {
    print_r($solution->summary());
}