PHP Classes

File: StandaloneExample.php

Recommend this page to a friend!
  Classes of Sasan Nobakht   PHP Genetic Algorithm Methods   StandaloneExample.php   Download  
File: StandaloneExample.php
Role: Example script
Content type: text/plain
Description: Standalone Example
Class: PHP Genetic Algorithm Methods
Implements crossover, mutation and inversion
Author: By
Last change: Role
Date: 6 years ago
Size: 1,133 bytes
 

Contents

Class file image Download
<?php
set_time_limit
(0);
ini_set('memory_limit', '1024M'); // or you could use 1G

require_once 'Genetic.class.php';
$Genetic = new GeneticAlgorithm (
    array(
       
'Goal' => 'AI',

       
'PopulationSize' => 200, // Size of Population In Each Generation
       
'MaxIteration' => 400,
       
'GenerationGap' => 100, // Percent of Checking Fitness Function on Population
       
'Age' => 6,
       
'Strategy' => 'M,L',
       
'Elitism' => true,

       
'MinAcceptableFitness' => 0,
       
'CodingType' => 'Binary',

       
'CrossOverRate' => 100, // Percent
       
'MutationRate' => 100, // Percent
       
'InversionRate' => 100, // Percent

       
'CrossOverTechnique' => 1,
       
'MutationTechnique' => 1,

       
'SingleCrossOverPoint' => 3,
       
'TwoCrossOverPoint1' => 2,
       
'TwoCrossOverPoint2' => 4,
       
'UniformCrossOverRatio' => 50, // Percent
       
'RingCrossOverCuttingPoint' => 3,
       
'RingCrossOverCuttingByRandom' => false
   
)
);

$Genetic->Run();

echo
"<pre>";
print_r(array_reverse($Genetic->Generations));
echo
"</pre>";