Number of variables (nvars) is dependent on the value of one variable when using genetic algorithm (GA)

I have two kinds of variables: x and y, and y includes y1, y2, y3, y4, ...
The total number of y's is dependent on the value of x.
For example, if x = 4, then my variables are vars=[x, y1, y2, y3, y4];
if x = 6, then my variables are vars=[x, y1, y2, y3, y4, y5, y6];
In addition, both x and y's are discrete integers, and I have both upper and lower bounds for them.
For example, the options for x is [4, 6, 8, 10];
the options for all the y's (are the same) is [4, 5, 6, 7, 8];
Could GA deal with this problem?
I was thinking to make nvars the potential maximum value.
That is to say, based on the above example, I could make nvars = 1(this is x)+10 (these are 10 y's)=11.
However, I still have issues.
For example, during the optimization process, the value of x could be 6, then there will be only 6 y's, which means the last four variables will be useless (by "useless" I mean there is no need to optimize), then I think I need to set the upper bounds to be same as the lower bounds for these four variables.
But how? Actually, I don't know the value of x when I set the lower and upper bounds, yes?
Thanks in advance!

 채택된 답변

Run the system multiple times, one for each of the discrete values of x. Take the best of the solutions.

댓글 수: 5

That's true!
Do you think I will get the same result as the first strategy (optimizing x and y's simultaneously)?
In addition, the first strategy cannot be done in Matlab GA, yes?
Thank you so much!
When you optimize with more variables than are used in the formulae then the optimization routines waste time trying to vary the unused variables hoping that they make a difference (the optimization routines cannot peak inside your function to tell that way.)
Running the cases individually will give you better answers faster than trying to run them simultaneously.
The first strategy can be done:
function result = objective(xy)
x = xy(1);
y = xy(2:end);
switch x
case 4
result = sum(y(1:2).^3);
case 6
result = sum(sin(y(1:2) + y(3:4)*2*pi));
end
end
Q1: So you mean the first strategy can be done, but is less efficient than "Running the cases individually", yes?
Q2: In order to implement the first strategy, I still need to set nvars the potential maximum value, yes?
Yes and Yes.
ga() does not care how you compute the objective function. But it cannot detect that it is working on a case in which one of the variables is unused, and will waste time trying to find values of that variable that lead to a better result. This waste of time can easily lead to it not converging in the number of iterations you give it.
Thank you so much for your answers!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2019년 1월 30일

댓글:

2019년 1월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by