Gene Boundaries for Genetic Algorithm

8 views (last 30 days)
Stylianos Mavrotas
Stylianos Mavrotas on 14 Feb 2019
Answered: TADA on 14 Feb 2019
I am a bit stuck, as I am trying to set dynamic boundaries to the integers in the chromosomes, as they are made. For example, if a chromosome has the specific value [1 2 3 4 5 6], I was to ensure that the sum of the values is equal to a spefic number. How could i do that ?

Answers (1)

TADA
TADA on 14 Feb 2019
data = randi(4, 1, 400);
seq = 1:6;
% if you mean the sum of that sequence you are looking for
x = sum(seq, 2);
if any(strfind(data, seq)) && sum(seq, 2) == x
disp('great success')
end
% or if you mean the sum of the whole vector:
x = sum(data, 2);
if any(strfind(data, seq)) && sum(data, 2) == x
disp('great success')
end

Community Treasure Hunt

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

Start Hunting!