Can genetic algorithm be nested?
7 views (last 30 days)
Show older comments
i want to have a code that does double optimization
i want the ga to first assume a vector q of 1s and 0s, then for each member in the population before calculating the fitness i want it to assume another vector which is the coefficients of q or if possible, only the elements that are assumed to be 1 in vector q. is a double optimization in the genetic algorithm possible ??
can i put a line that calls the ga toolbox in the fitness function for example ??
0 Comments
Answers (1)
Stephan
on 28 Jun 2019
Edited: Stephan
on 28 Jun 2019
It should be possible in one single call of ga. In this case nvars would be 2*numel(q) and you have to set the correct bounds and intcon correctly.
Then in the first half set of variables ga assumes 0/1 for q and the second half set is used for the assumed coefficients that are multiplied by the assumed q-values. Since some of them are 0 the multiplication with a coefficient would still be zero.
See this example:
function myfitness = myFitness(x)
q = x(1):x(numel(x)/2);
coeffs = x((numel(x)/2)+1):x(end);
q_coeffs = coeffs.*q;
% Caculate your fitness value
myfitness = q_coeffs * something - m*c^2; % Your fitness calculation...
end
What would happen for this example:
ga assumes:
x(1) = 1
x(2) = 0
x(3) = 1
x(4) = 0.1
x(5) = 0.5
x(6) = 0.25
q_coeffs = [0.1*1, 0.5*0, 0.25*1] = [0.1 0 0.25]
2 Comments
Stephan
on 1 Jul 2019
The problem is, that you need to know the number of vars before starting ga. But i doubt that it takes less time to start ga twice. 128 decision variables is not a big optimization problem. I would try this way, since it is easy to program and to understand. If you program it in a vectorized manner, this part should run quickly.
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!