-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
140 lines (115 loc) · 3.85 KB
/
Copy pathSolution.java
File metadata and controls
140 lines (115 loc) · 3.85 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import java.util.Arrays;
import java.util.Random;
import org.evosuite.ga.Chromosome;
import org.evosuite.ga.localsearch.LocalSearchObjective;
public class Solution extends Chromosome {
private double crossover_rate;
private int population;
private int elitism;
private String selection;
private boolean parent_replacement;
public int[] index;
static String[] selection_set = new String[]{"ROULETTEWHEEL", "TOURNAMENT", "TOURNAMENT", "RANK", "RANK"};
static boolean[] parent_check = new boolean[]{true, false};
static double[] cross = new double[]{0.0D, 0.2D, 0.5D, 0.75D, 0.8D, 1.0D};
static int[] pop = new int[]{4, 10, 50, 100, 200};
static int[] elite = new int[]{0, 1, 10, 50};
static int[] size;
public Solution(int[] param) {
this.index = param;
}
public Chromosome clone() {
int[] copiedArray = Arrays.copyOf(this.index, this.index.length);
Solution s = new Solution(copiedArray);
return s;
}
public boolean equals(Object o) {
Solution oprime = (Solution)o;
return Arrays.equals(this.index, oprime.index);
}
public int hashCode() {
return 0;
}
public <T extends Chromosome> int compareSecondaryObjective(T t) {
return 0;
}
public void mutate() {
int random = (new Random()).nextInt(this.index.length);
int random2 = (new Random()).nextInt(size[random]);
this.index[random] = random2;
this.setChanged(true);
}
public void crossOver(Chromosome chromosome, int i, int i1) {
Solution s = (Solution)chromosome;
int j;
if (i1 < i) {
j = i1;
i1 = i;
i = j;
}
if (i == i1) {
i1 = this.index.length;
}
for(j = i; j < i1; ++j) {
int temp = this.index[j];
this.index[j] = s.index[j];
s.index[j] = temp;
}
s.setChanged(true);
this.setChanged(true);
}
public boolean localSearch(LocalSearchObjective<? extends Chromosome> localSearchObjective) {
return false;
}
public int size() {
return 5;
}
public boolean isParent_replacement() {
this.parent_replacement = parent_check[this.index[4]];
return this.parent_replacement;
}
public double getCrossover_rate() {
this.crossover_rate = cross[this.index[0]];
return this.crossover_rate;
}
public int getPopulation() {
this.population = pop[this.index[1]];
return this.population;
}
public String getSelection() {
this.selection = selection_set[this.index[3]];
return this.selection;
}
public int getElitism() {
if (this.index[2] == 2) {
this.elitism = this.getPopulation() / 10;
if (this.getPopulation() == 4) {
this.elitism = 1;
}
} else if (this.index[2] == 3) {
this.elitism = this.getPopulation() / 2;
} else {
this.elitism = elite[this.index[2]];
}
return this.elitism;
}
public String toString() {
String s = "population: " + this.getPopulation() + " crossover rate: " + this.getCrossover_rate() + " elitism: " + this.getElitism() + " selection: " + this.getSelection() + " parent: " + this.isParent_replacement() + " fitness: " + this.getFitness();
if (this.index[3] == 1) {
s = s + " tournament size: 2";
}
if (this.index[3] == 2) {
s = s + " tournament size: 7";
}
if (this.index[3] == 3) {
s = s + " rank bias: 1.2";
}
if (this.index[3] == 4) {
s = s + " rank bias: 1.7";
}
return s;
}
static {
size = new int[]{cross.length, pop.length, elite.length, selection_set.length, parent_check.length};
}
}