Skip to content

Commit 38d7bb8

Browse files
author
ali
committed
mutation finished
1 parent d2db23b commit 38d7bb8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

GeneticAlgorithm.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,15 @@ public function crossOver() {
8686
}
8787

8888
public function mutation(){
89+
8990
$mutation_count = round((3 * 5) * $this->mutation_rate, 0, PHP_ROUND_HALF_DOWN);
91+
9092
for ($i=0;$i<$mutation_count;$i++){
9193
$position = rand(1,(3 * 5));
92-
$chossed_chrom = round($position / 3 , 0 , PHP_ROUND_HALF_UP) - 1;
94+
$chosen_chromosome = round($position / 3 , 0 , PHP_ROUND_HALF_UP) - 1;
95+
$chosen_gen = (3 * 5) - ($chosen_chromosome * 3);
96+
97+
$this->chromosome[$chosen_chromosome][$chosen_gen] = rand(0,10);
9398
}
9499
}
95100
}

0 commit comments

Comments
 (0)