PHP Classes

PHP Genetic GPS: General Problem Solving using Genetic Algorithms

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 52%Total: 438 All time: 6,268 This week: 129Up
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

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 (8)  
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

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:438
This week:0
All time:6,268
This week:129Up
 User Ratings  
 
 All time
Utility:75%StarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:-
Examples:66%StarStarStarStar
Tests:-
Videos:-
Overall:52%StarStarStar
Rank:2429