PHP Classes

Simple Genetic Algorithm: Implement genetic algorithm to optimize population

Recommend this page to a friend!
  Info   View files Example   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 253 All time: 7,885 This week: 560Up
Version License PHP version Categories
simple-genetic 1.0.3MIT/X Consortium ...5.5Algorithms, PHP 5, Artificial intelli...
Description 

Author

This class implements a genetic algorithm to optimize a population of chromosomes.

It provides a base class that implements several steps of a genetic algorithm like initializing the population, selection, fitness function, cross-over, mutation and get the best sequence.

The class can be extended by specialized sub-classes that override the population initialization or other steps to customize the genetic algorithm to solve specific optimization problems.

Picture of ryan silalahi
Name: ryan silalahi <contact>
Classes: 2 packages by
Country: Indonesia Indonesia
Age: ???
All time rank: 383064 in Indonesia Indonesia
Week rank: 270 Up6 in Indonesia Indonesia Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

/*
    this example show how we use SimpleGeneticAlgorithm
*/

require __DIR__ . '/../vendor/autoload.php'; // composer autoload

$ga = new \SimpleGeneticAlgorithm\SimpleGeneticAlgorithm(array(
   
   
//'population' => 20,
    //'selection' => 90, // 90%
   
'mutation' => 25, // 25%
   
    //'seed' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890\'.,',
   
'goal' => 'Astari Ghaniarti',
   
   
//'max_iteration' => 50000,
   
'delay' => 50, // ms, if debug is false, then delay forced to 0
   
'debug' => true,
   
//'fitness_in_percent' => false, // usefull if chromosome more than 10 chars
));


//var_dump($ga->run());
$ga->run(); // just run because debug is true


Details

SimpleGeneticAlgorithm

simple genetic algorithm in php, this package i create just for example how we can implement Genetic Algorithm in PHP if you inteserted just email me at mr.ryansilalahi@gmail.com :-)

see interface/GeneticAlgorithm.php

Installation

you can download this with composer (packagist) <pre><code>composer require ryanhs/simple-genetic-algorithm</code></pre>

Example

in example dir you can see:

  • example1.php
  • example2.php
  • example3.php

example 1

<pre><code> require '/vendor/autoload.php'; // composer autoload

$ga = new \SimpleGeneticAlgorithm\SimpleGeneticAlgorithm(array(

'mutation' => 25, // 25%
'goal' => 'Astari Ghaniarti',

'delay' => 50, // ms, if debug is false, then delay forced to 0
'debug' => true,

));

$ga->run(); // just run because debug is true </code></pre>

License

MIT License

		

  Files folder image Files  
File Role Description
Files folder imageexample (4 files)
Files folder imageinterface (1 file)
Files folder imagetest (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data
Plain text file SimpleGeneticAlgorithm.php Class Class source

  Files folder image Files  /  example  
File Role Description
  Accessible without login Plain text file example1.php Example Example script
  Accessible without login Plain text file example2.php Example Example script
  Accessible without login Plain text file example3.php Example Example script
  Accessible without login Plain text file example4.php Example Example script

  Files folder image Files  /  interface  
File Role Description
  Plain text file GeneticAlgorithm.php Class Class source

  Files folder image Files  /  test  
File Role Description
  Accessible without login Plain text file Test.php Test Unit test script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:253
This week:0
All time:7,885
This week:560Up