File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,9 @@ class GeneticAlgorithm
18
18
public $ chromosome = array ();
19
19
public $ fx = array ();
20
20
public $ fitness = array ();
21
+ public $ probability = array ();
22
+ public $ cumulative_probability = array ();
23
+
21
24
public $ total_fitness = 0 ;
22
25
23
26
public function __construct ()
@@ -28,8 +31,9 @@ public function __construct()
28
31
$ this ->calcFx ();
29
32
30
33
$ this ->calcFitness ();
34
+ $ this ->calcProbability ();
31
35
32
- var_dump ($ this ->fitness );
36
+ var_dump ($ this ->cumulative_probability );
33
37
}
34
38
35
39
public function calcFx (){
@@ -43,4 +47,13 @@ public function calcFitness(){
43
47
$ this ->total_fitness += $ this ->fitness [$ i ];
44
48
}
45
49
}
50
+
51
+ public function calcProbability (){
52
+ $ sum = 0 ;
53
+ for ($ i =0 ;$ i <5 ;$ i ++) {
54
+ $ this ->probability [$ i ] = $ this ->fitness [$ i ] / $ this ->total_fitness ;
55
+ $ sum += $ this ->probability [$ i ];
56
+ $ this ->cumulative_probability [$ i ] = $ sum ;
57
+ }
58
+ }
46
59
}
You can’t perform that action at this time.
0 commit comments