Using GA can I put a condition on Population?
1 回表示 (過去 30 日間)
古いコメントを表示
I am using GA, with nvars=32 and IntCon=1:32, so 32 integers
lb=[zeros(1,16),zeros(1,16)];
ub=[60*ones(1,16),4*ones(1,16)]
I want the first 16 elements be ascending and the last 16 elements no matter the order, and both of them respect the lb and ub.
Is there any way to obligate the population be between 0-60 with ascending order for the first 16 elements? (this 16 elements represent time so I can't have one value greater than the next value).
0 件のコメント
回答 (2 件)
Alan Weiss
2022 年 5 月 4 日
Sure, that is a simple linear inequality constraint. Probably easiest to represent using the problem-based formulation, but do what you like. In solver-based:
A = zeros(15,32);
for i = 1:15
A(i,i) = 1;
A(i,i+1) = -1; % means x(i) - x(i+1) <= 0
end
end
b = zeros(15,1);
You can use sparse matrices and MATLAB constructs to make this matrix, but this is fast enough.
Alan Weiss
MATLAB mathematical toolbox documentation
0 件のコメント
Rim Abdallah
2022 年 5 月 5 日
2 件のコメント
Alan Weiss
2022 年 5 月 5 日
Please check your answer against the linear constraint. What do you get when you run
A*x'
When I tried this against your reported x I get a vector whose first value is 27 (=36 - 9). A*x' should consist entirely of nonpositive numbers. So clearly the linear constraints are not being satisfied.
Did you get a positive exit flag from the optimization? I guess not. The solution is infeasible.
Alan Weiss
MATLAB mathematical toolbox documentation
参考
カテゴリ
Help Center および File Exchange で Genetic Algorithm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!