Clear Filters
Clear Filters

certain number of variables for genetic algorithm to change

5 views (last 30 days)
Hello! I'm trying to use genetic algorithm toolbox in order to find minimum of fitness function. My function F depends on the vector of input variables (integers ranging from 0 to 1) X = [some values that GA will change in order to find minimum of fitness funciton].
The question is "how can I make GA set only certain number of variables in X vector (for example only three 1s X = [0 0 0 1 0 1 0 1 0 0])?" I tried to use while loop inside the function, but when I call a GA using
[X,fval] = ga(@F,6,[],[],[],[],[0 0 0 0 0 0],[1 1 1 1 1 1],[],IntCon)
it seems like it is a infinite looop.
Could anybody help me with that?
Here's the while loop that I tried to use inside my function:
while sum(nonzeros(X))<=3
%some code
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!