Can genetic algorithm be nested?

7 views (last 30 days)
alaa zarif
alaa zarif on 27 Jun 2019
Commented: Stephan on 1 Jul 2019
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 ??

Answers (1)

Stephan
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
alaa zarif
alaa zarif on 1 Jul 2019
isnt there another way to assume coefficients for the values in q assumed to be 1 only ?? as like that i will have many unneccessary variables
in my problem i have a 64 variables to be assigned 0s and 1s, if i double them the code will consume so much time
Stephan
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!