Skip to content

Commit 724ae12

Browse files
author
ali
committed
3 function finished
no bug
1 parent 8ca25be commit 724ae12

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

GeneticAlgorithm.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ public function __construct()
3838
echo "init chromosome is:".json_encode($this->chromosome);
3939

4040
while (is_null($finish_point) && $this->iteration < $this->population) {
41-
42-
for ($i = 0; $i < 5; $i++){
43-
if ($this->chromosome[$i][0] + 2 * $this->chromosome[$i][1] + 3 * $this->chromosome[$i][2] == 10) {
44-
$finish_point = $i;
45-
}
46-
}
47-
4841
$this->selection();
4942

5043
echo "<br>$this->iteration => selection chromosome is:" . json_encode($this->chromosome);
@@ -58,6 +51,14 @@ public function __construct()
5851
echo "<br>$this->iteration => mutation chromosome is:" . json_encode($this->chromosome);
5952

6053
$this->iteration++;
54+
55+
for ($i = 0; $i < 5; $i++){
56+
if ($this->chromosome[$i][0] + 2 * $this->chromosome[$i][1] + 3 * $this->chromosome[$i][2] == 10) {
57+
$finish_point = $i;
58+
$this->calcFx();
59+
$this->calcFitness();
60+
}
61+
}
6162
}
6263

6364
echo "<br>when finish chromosome is:".json_encode($this->chromosome);

0 commit comments

Comments
 (0)