Genetic Algorithm for points External To a Specific Volume

I'm using the GA to select measurement points in a three-dimensional physics problem.
I can tell GA to select only N_points inside some specified plane above my problem simply as:
X.min = -10; X.max = 10; Y.min = -10; Y.max = 10; Z.min = 0; Z.max = 2;
lb = repmat([X.min Y.min Z.min],[1 N_points]);
ub = repmat([X.max Y.max Z.max],[1 N_points]); %Lower/Upper Boundaries [X,Y,Z]
Is it possible to instead set up constraints so points are only selected outside of some cube? For clarity, a physical example would be there exists volume which a measurement device cannot enter, so the problem searches for points external to that region.
Ideally, I would select points only within a hollow-cube: External to a specific volume, but extending to reasonable limits - thereby minimising the possible search space.

 採用された回答

Matt J
Matt J 2022 年 8 月 10 日
編集済み: Matt J 2022 年 8 月 10 日

0 投票

You would have to use a non-linear constraint function for that:
function [cineq,ceq]=nonlcon(x)
x=reshape(x,3,[]); %reshape to 3xN_points
cineq(1,:)=vecnorm(x./[Xmax;Ymax;Zmax],inf)-1; %inside box of dimensions Xmax x Ymax x Zmax
cineq(2,:)=1-vecnorm(x./[Xmin;Ymin;Zmin],inf); %outside box of dimensions Xmin x Ymin x Zmin
ceq=[];
end

4 件のコメント

Matt J
Matt J 2022 年 8 月 10 日
編集済み: Matt J 2022 年 8 月 10 日
In fact, though, cineq(1,:) is unnecessary. You could and probably should use the lb, ub argument for that, as you have been.
ADSW121365
ADSW121365 2022 年 8 月 11 日
編集済み: ADSW121365 2022 年 8 月 11 日
The comment has confused me slightly, please forgive me, my initial thought is that cineq(2:) would be better suited to the existing lb,ub.
An example may help me: Take a 2 unit cube, where we wish to ignore a central unit cube.
  • In this case, the outside box has limits ranging from -1:1 in XYZ.
  • The inner box, which should be excluded from the search, then has limits ranging from -0.5:0.5 in XYZ.
For this explicit case, what would be your recommended syntax to achieve my intention?
Matt J
Matt J 2022 年 8 月 11 日
編集済み: Matt J 2022 年 8 月 11 日
That would be,
ub=ones(3,N_points); lb=-ub; %outside box
x=ga(fun,numel(ub),[],[],[],[],lb,ub,@nonlcon);
function [cineq,ceq]=nonlcon(x)
x=reshape(x,3,[]); %reshape to 3xN_points
cineq=1-vecnorm(x./0.5,inf); %inner box
ceq=[];
end
ADSW121365
ADSW121365 2022 年 8 月 11 日
Perfect I understand now, thankyou!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

リリース

R2021b

質問済み:

2022 年 8 月 10 日

コメント済み:

2022 年 8 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by