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

859 Views Asked by At

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.

1

There are 1 best solutions below

1
On BEST ANSWER

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.