0

I did a genetic algorithm code as below...

lb = [1 1 1 1 1 1 1 1 1 1];
ub = [10 10 10 10 10 10 10 10 10 10];
intCon = 1:10;
[x,fval] = ga(FitnessFunction,10,[],[],[],[],lb,ub,[],intCon,options)

I get output "x" as a vector of size [1 10] for example as follows...

(my output eg:) x = 4     3     3     2     9     4     4     6     1     1

but i need to get a output as example,

(what i want eg:) x = 2 10 3 8 1 6 4 9 5 7

that is i should not get repeated values and my outputx should be if size [1 10] .... but in my output i get repeated values... please can someone tell me how to remove repetition... should i set any options for that,.... please do reply....

  • You would have to code such a constraint into your `FitnessFunction` so I doubt anyone will be able to advise you unless you edit your question to include its code. – Dan Apr 25 '16 at 08:46
  • What you need is a mapping function that converts your permutations of unique numbers to a single number. I did this a while ago (see figure 2 on page 4) https://arxiv.org/ftp/arxiv/papers/0810/0810.3671.pdf but this is probably a very poor solution. This looks like a better starting point to research further: http://www.2ality.com/2013/03/permutations.html otherwise maybe these http://stackoverflow.com/questions/14212030/number-to-unique-permutation-mapping-of-a-sequence-containing-duplicates or http://stackoverflow.com/questions/1506078/fast-permutation-number-permutation-mapping-algorithms – Dan Apr 25 '16 at 09:30

1 Answers1

1

If your output is based on minimizing a fitness function with genetic algorithm I have for you the fastest version of your fitness function:

min(sum(x)-a)^2

with "a" equal to the sum of n different numbers(ie from 1 to 10 a=55) It means that every time that the sum of your output is different from "a", the cost of the solution increase quadratically.

Thanks to my experience I can tell you that crossover between elite members can create a large amount of poor solutions. I suggest you to increase the factor of mutation with random numbers or mutation with switch between chromosomes.

I do not know why you actually use genetic algorithm to do that, there are many others algorithms that finds solutions in a better-faster way.

Redlion
  • 81
  • 6