In tutorial 1, the optimal solution is defined as the maximum number of "1s" or "trues" in a chromosome / genome. To do this, it defines the fitness value using the following codes in the MaxOnes.java file.
int sum=0; for(int x=0; x
The best genome will be 11111 when the size of genome is 5. Alternatively, I want the best genome be 10101. To do this, I replace the above code with the followings:int sum=0;
for(int x=0; x
if ((ind2.genome[x]==true) && ((x+1)%2!=0)) sum++;
else if ((ind2.genome[x]==true) && ((x+1)%2!=0)) sum++;
else if ((ind2.genome[x]==true) && ((x+1)%2!=0)) sum++;
This increases the fitness value by 1 if the gene value is true at odd position or if the gene value is false at even position. The result is an alternating 1s and 0s string. Next, I will try to understand the entire evolutionary process in ECJ and how to define a representation and evolving operators.

沒有留言:
張貼留言