Inequality constraints for optimizer
Afficher commentaires plus anciens
Hello,
I want the solution (x,y) of my optimization problem to belong to a specific region of the search-space as depicted below. This region can have an arbitrary shape.

1st case: The red region is known, by knowing the equation of each red line (segment). Is it possible to create a set of inequalities?
2nd case: The red region is known, by knowing the coordinates of all points of its perimeter. Is it possible to create a set of inequalities?
Thanks in advance.
Réponse acceptée
Plus de réponses (1)
Bruno Luong
le 22 Déc 2020
Modifié(e) : Bruno Luong
le 22 Déc 2020
% Your points that define the domain
xg = randn(10,1);
yg = randn(10,1);
% The domain is concerted to the set defined by inequalities { xy : A*xy <= b }
xyg = [xg(:) yg(:)];
K = convhull(xyg);
xyh = xyg(K,:);
dxy = diff(xyh,1,1);
A = [dxy(:,2),-dxy(:,1)];
b = sum(A.*xyh(1:end-1,:),2);
% Check with grid points
close all
xi = linspace(min(xg),max(xg),30);
yi = linspace(min(yg),max(yg),30);
[X,Y] = ndgrid(xi,yi);
xy = [X(:),Y(:)]';
in = all(A*xy <= b,1); % inequalities
plot(xg,yg,'+',...
xyh(:,1),xyh(:,2),'-k',...
X(in),Y(in),'or', ...
X(~in),Y(~in),'.y');

1 commentaire
John Kioulaxidis
le 23 Déc 2020
Catégories
En savoir plus sur Direct Search dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
