/
index.php
48 lines (27 loc) · 1 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* Created by PhpStorm.
* User: User
* Date: 24-Dec-15
* Time: 23:04
*/
include_once "includes/masterpage/header.php"; ?>
<h1>This is my title</h1>
<?php
$ga = new GeneticAlgorithm(25, 0.95, 0.01, 3);
$population = $ga->initPopulation(30);
$ga->evalPopulation($population);
$generation = 1;
while($ga->isTerminationConditionMet($population) == false){
echo "Generation: $generation ";
echo "Average fitness: ".$population->getPopulationFitness()/$population->size()." ";
echo "Fittest Individual: ".$population->getFittestIndividual(0)->getFitness()."<br>";
$population = $ga->crossoverUniform($population, GeneticAlgorithm::TOURNAMENT,5);
$population = $ga->mutate($population);
$ga->evalPopulation($population);
$generation++;
}
echo "Found solution is $generation generations.<br>Best solutions: ".$population->getFittestIndividual(0);
?>
<p>Test</p>
<?php include_once "includes/masterpage/footer.php "; ?>