Skip to content

Commit 892fe1a

Browse files
author
ali
committed
selection
1 parent 0146050 commit 892fe1a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

GeneticAlgorithm.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,24 @@ public function __construct()
3333
$this->calcFitness();
3434
$this->calcProbability();
3535

36-
var_dump($this->cumulative_probability);
36+
$new_chromosome = array();
37+
38+
for ($i=0;$i<5;$i++) {
39+
$r[$i] = mt_rand() / mt_getrandmax();
40+
41+
for ($j=0;$j<5;$j++){
42+
if ($j == 0) {
43+
if ($r[$i] < $this->cumulative_probability[0])
44+
$new_chromosome[$i] = $this->chromosome[0];
45+
}else {
46+
if ($r[$i] > $this->cumulative_probability[$j - 1] && $r[$i] < $this->cumulative_probability[$j])
47+
$new_chromosome[$i] = $this->chromosome[$j];
48+
}
49+
}
50+
}
51+
52+
53+
var_dump($new_chromosome);
3754
}
3855

3956
public function calcFx(){

0 commit comments

Comments
 (0)