Can genetic algorithm be nested?

5 次查看(过去 30 天)
alaa zarif
alaa zarif 2019-6-27
评论: Stephan 2019-7-1
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 ??

回答(1 个)

Stephan
Stephan 2019-6-28
编辑:Stephan 2019-6-28
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 个评论
alaa zarif
alaa zarif 2019-7-1
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 2019-7-1
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by