How can I obtain an array of all different values with Genetic Algorithms?

3 views (last 30 days)
Hello everybody,
I am using genetic algorithms to obtain the best value of a fitness function. The fitness uses the data of an array. The dimension of the array is 50 and each element can have an integer value from 1 to 50. However, the values cannot be repeated, this means that we have an array of 50 elements and there should not be two elements with the same value. Does anybody know how can I specify tis constraint?
For now, I have this code, but in this case, the values are repeated:
for k = 1:50
lowbound(k) = 0;
upbound(k) = 50;
numstobeinteger(k) = k;
end
array_values= ga(@fitnFunc,50,[],[],[],[],lowbound,upbound,[], numstobeinteger);
Thanks in advance,
  3 Comments
Harris
Harris on 11 May 2015
Hello Geoff, I am not familiar with these kind of functions... I have never programmed genetic algorithms, so I don't know how do they internally work.
What are these functions? How are they programmed? How can I programm them so that no elements are repeated?? I define both, crossover and mutation functions?
Thanks in advance,
Harris
Harris on 11 May 2015
I have performed the following,
constraint_fun = @contr;
%options = gaoptimset('MutationFcn',@mutationadaptfeasible);
%
options = gaoptimset('PopulationSize', 2000);
50;
for k = 1:50
lowbound(k) = 1;
upbound(k) = 50;
numstobeinteger(k) = k;
end
array_values= ga(@fitnFunc,50,[],[],[],[],lowbound,upbound, constraint_fun, numstobeinteger, options);
And the constraints specified in this manner:
function [c, ceq] = contr(x)
c = 0;
for i=1:size(x,2)
for j=1:size(x,2)
if i~= j
constraint = abs(x(i)==x(j));
if constraint == true
c = 1;
end
end
end
end
ceq = [];
However, the constraints are not satisfied...

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!