开发者

Uniform crossover giving worse results than one-point crossover?

开发者 https://www.devze.com 2023-02-18 22:57 出处:网络
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 p

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.


Well, first of all what kind of information are you encoding and what are you trying to evolve?

Depending on the problem you are trying to solve, some kinds of cross-over strategies will prevent you from ever finding good solutions.

A simple example: if the solution you are looking for has inherent symmetry (e.g. a white/black cellular automata majority classifier), single point cross-over will never give you very good results because it's breaking any symmetry that the genetic algorithm may have stumbled upon (e.g. so in the case of the majority classifier, it will be very good at classifying black or white but not both, so it will never get better than a given - pretty low - fitness).


(As you didn't respond to my comment, I'll repeat it as answer)

You're comparing a double with a constant which is problematic for floating points numbers, using int selected will probably do better, or in case you need to use a double, try using something like:

if (selected < 1.5)
0

精彩评论

暂无评论...
验证码 换一张
取 消