I have written a uniform crossover algorithm for part of my homework but it's not working properly. It's actually returning worse results than my one point cross over. I would just like someone to point out where I am going wrong so I can fix it please :). I've been trying for ages now and this is my last resort!!
private void DoUniformCrossOver(int p1id,int p2id)
{
ArrayList<Integer> p1 = population.get(p1id).GetRep();
ArrayList<Integer> p2 = population.get(p2id).GetRep();
ArrayList<Integer> c1 = new ArrayList<Integer>();
ArrayList<Integer> c2 = new ArrayList<Integer>();
for (int i=0;i<nbits;++i)
{
double selected = CS2004.UI(1,2);
if (selected ==1)
{
c1.add(p1.get(i));
c2.add(p2.get(i));
}
else
{
c1.add(p2.get(i));
c2.add(p1.get(i));
}
}
population.add(new ScalesChrome(c1));
population.add(new ScalesChrome(c2));
}
The method takes in as paramaters the two parents, p1id and p2id. Then creates the arraylists of the representation - p1 and p2.
In the for loop, 'nbits' is the weight of the array (or the length of the array). My one-point crossover method uses it in the for loop and it works just fine.
I then generate either 1/2 to determine which gene from each parent the child will get.
The fitness of this algorithm is very very poor!! Any help at all would be greatly appreciated.
Many thanks.