Skip to content

Commit d2db23b

Browse files
author
ali
committed
mutation started
1 parent 6e1a430 commit d2db23b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

GeneticAlgorithm.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class GeneticAlgorithm
2121
public $probability = array();
2222
public $cumulative_probability = array();
2323
public $crossover_rate = 0.25;
24+
public $mutation_rate = 0.1;
2425
public $population = 200;
2526

2627
public $total_fitness = 0;
@@ -83,4 +84,12 @@ public function crossOver() {
8384
$iteration = 0;
8485
var_export($this->chromosome(1));
8586
}
87+
88+
public function mutation(){
89+
$mutation_count = round((3 * 5) * $this->mutation_rate, 0, PHP_ROUND_HALF_DOWN);
90+
for ($i=0;$i<$mutation_count;$i++){
91+
$position = rand(1,(3 * 5));
92+
$chossed_chrom = round($position / 3 , 0 , PHP_ROUND_HALF_UP) - 1;
93+
}
94+
}
8695
}

0 commit comments

Comments
 (0)