PHP Classes

PHP Genetic GPS: General Problem Solving using Genetic Algorithms

Recommend this page to a friend!
  Info   View files Example   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 437 This week: 1All time: 6,267 This week: 560Up
Version License PHP version Categories
genetic-gps 1.0.0GNU Lesser Genera...5.4Algorithms, PHP 5, Artificial intelli...
Description 

Author

This package can be used for general problem solving using Genetic Algorithms.

The main class can take several parameters and callback functions that implement several aspects involved in the execution of a genetic algorithm, so it can be adapted to any problem that can be solved using genetic algorithms.

The parameters can be the population size, an object to access the population elements, generations, mutation rate, elitism rate, callback functions to define values of fitness, mutation, selection, crossover, elitism, etc..

An example is provided for a word guess application that takes letters to guess what is the correct word.

Picture of Nima Ghaedsharafi
Name: Nima Ghaedsharafi <contact>
Classes: 1 package by
Country: Iran Iran
Age: 30
All time rank: 343370 in Iran Iran
Week rank: 416 Up4 in Iran Iran Up

Example

<?php

$text
= "Nima";
   
$size = 100;
$text = strtolower($text);
$type = array_combine(range(ord('a'), ord('z')), range('a', 'z'));

$cmp_func = function ($word1, $word2)
{
    if(
$word1->fitness > $word2->fitness)
        return
1;
    else if(
$word1->fitness < $word2->fitness )
        return -
1;
    else
        return
0;
};


$population = new Population($size, strlen($text), $type, $cmp_func);
$newPopulation = new Population($size, strlen($text), $type, $cmp_func);
$population->makePopulation();

$ga = new GeneticAlgorithm([
       
'justFind' => true,
       
'population_size' => $size,
       
'population' => $population,
       
'newPopulation' => $newPopulation,
       
'generation' => 60,
       
'mutation_rate' => 10,
       
'elitism_rate' => 25,
       
'debug' => true,
       
'length' => $population->length,
       
'fitness_function' => function($built) use( $text ) { return Letters::fitness($built, $text); },
       
'mutation_function' => function($population, $rate) { return Letters::mutation($population, $rate); },
       
'selection_function' => function($population) { return Letters::selection($population); },
       
'crossover_function' => function($mom, $dad){ return Letters::crossover($mom, $dad); },
       
'elitism_function' => function($newPopulation, $population, $rate){ return Letters::elitism($newPopulation, $population, $rate); },
    ]);

$ga->circo();
echo
$ga;

?>


  Files folder image Files  
File Role Description
Accessible without login Plain text file index.php Example Executeable file
Plain text file gac.php Class Example script
Plain text file gau.php Class Class source
Plain text file geneticAlgorithm.php Class Class source
Plain text file genome.php Class Class source
Plain text file ipopulation.php Class Class source
Plain text file letters.php Class Example script
Accessible without login Plain text file population.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:437
This week:1
All time:6,267
This week:560Up