This repository has been archived by the owner on Dec 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneMax.java
66 lines (48 loc) · 2.44 KB
/
OneMax.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/******************************************************************************
* A Teaching GA Developed by Hal Stringer & Annie Wu, UCF
* Version 2, January 18, 2004
*******************************************************************************/
import java.io.*;
import java.util.*;
import java.text.*;
public class OneMax extends FitnessFunction{
/*******************************************************************************
* INSTANCE VARIABLES *
*******************************************************************************/
/*******************************************************************************
* STATIC VARIABLES *
*******************************************************************************/
/*******************************************************************************
* CONSTRUCTORS *
*******************************************************************************/
public OneMax(){
name = "OneMax Problem";
}
/*******************************************************************************
* MEMBER METHODS *
*******************************************************************************/
// COMPUTE A CHROMOSOME'S RAW FITNESS *************************************
public void doRawFitness(Chromo X){
X.rawFitness = 0;
for (int z=0; z<Parameters.numGenes * Parameters.geneSize; z++){
if (X.chromo.charAt(z) == '1') X.rawFitness += 1;
}
}
// PRINT OUT AN INDIVIDUAL GENE TO THE SUMMARY FILE *********************************
public void doPrintGenes(Chromo X, FileWriter output) throws java.io.IOException{
for (int i=0; i<Parameters.numGenes; i++){
Hwrite.right(X.getGeneAlpha(i),11,output);
}
output.write(" RawFitness");
output.write("\n ");
for (int i=0; i<Parameters.numGenes; i++){
Hwrite.right(X.getPosIntGeneValue(i),11,output);
}
Hwrite.right((int) X.rawFitness,13,output);
output.write("\n\n");
return;
}
/*******************************************************************************
* STATIC METHODS *
*******************************************************************************/
} // End of OneMax.java ******************************************************