Skip to content

Commit 8ca25be

Browse files
author
ali
committed
3 function finished
1 parent 36a06d2 commit 8ca25be

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

GeneticAlgorithm.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ 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+
4148
$this->selection();
4249

4350
echo "<br>$this->iteration => selection chromosome is:" . json_encode($this->chromosome);
@@ -51,12 +58,6 @@ public function __construct()
5158
echo "<br>$this->iteration => mutation chromosome is:" . json_encode($this->chromosome);
5259

5360
$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-
}
59-
}
6061
}
6162

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

0 commit comments

Comments
 (0)