简体   繁体   中英

GA Jgap: Avoid duplicates (doublettes) chromosomes where the order doesn't count

I'm implementing with JGAP a genetic algorithm to solve a problem where the chromosome is a list of Integers (i would like to keep N good-fitting solutions in the result, not just the fittest one).

Each integer must appear just once in the chromosome (I did it by setting fitness=0 to chromosomes with duplicate alleles and it's ok... )

My problem:

In my problem, the order in which the numbers appears in the chromosomes doesn't count ( 1 2 3 is the same as 2 1 3).

So at the end of the execution, i've a list of possible solutions

I used the solution reported here ( using JGAp (genetic algorithm library) and the duplicated chromosomes ) to remove duplicates chromosomes in this way:

      conf.getNaturalSelectors(false).clear();
      BestChromosomesSelector bcs = new BestChromosomesSelector(conf, 0.8d);
      bcs.setDoubletteChromosomesAllowed(false);
      conf.addNaturalSelector(bcs, false);

But it removes just identical chromosomes, it doesn't remove for example:

A B C D 
A C B D 
B A C D

Those chromosomes in my problem represents the same solution

So I end up with a list of chromosomes with the same fitness and the same meaning but with genes in different order.

How can i remove the chromosomes that represent the same solution , despite of the order in which it is represented?

Thank you, have a good day.

Simply sort the chromosomes before storing them. Since different permutations of the same set of integers will sort out into the same sequence, you can use the code you are already using to remove the duplicates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM