PHP Classes

Simple Genetic Algorithm: Implement genetic algorithm to optimize population

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 53%Total: 253 All time: 7,887 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: 383264 in Indonesia Indonesia
Week rank: 206 Up5 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 (10)  
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 (10)  /  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 (10)  /  interface  
File Role Description
  Plain text file GeneticAlgorithm.php Class Class source

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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:253
This week:0
All time:7,887
This week:560Up
 User Ratings  
 
 All time
Utility:66%StarStarStarStar
Consistency:50%StarStarStar
Documentation:50%StarStarStar
Examples:50%StarStarStar
Tests:50%StarStarStar
Videos:-
Overall:53%StarStarStar
Rank:2234