필터 지우기
필터 지우기

How to limit optimization variables to a certain area?

조회 수: 1 (최근 30일)
Keqiao Wu
Keqiao Wu 2021년 6월 16일
답변: Walter Roberson 2021년 6월 16일
Helllo everyone,
I want to limit my optimization variable S in a certain area, and the coordinate data of the area boundary points are saved in 'bound_points', so I use inPoly to judge whether S is within the boundary, but there are some errors occured when I run the code. What should I do to limit the optimization variables within the boundary?
S = optimvar('S', [2 1]);
cons_eq=inPoly(S(1:2,1)',bound_points)==1;
prob.Constraints.constr=cons_eq;
ERROR:
Operator '&' is not supported for operands oftype 'optim.problemddef.OptimizationEquality'.
Error in InPoly(line 20)
if ~isempty(find(poly(:,1)==p(i,1)& poly(:,2)==p(i,2)))

답변 (1개)

Walter Roberson
Walter Roberson 2021년 6월 16일
S = optimvar('S', [2 1]);
At that point, S is an optimization variable
cons_eq=inPoly(S(1:2,1)',bound_points)==1;
At that point, the optimization variable is being passed to inPoly() with the expectation that it will be processed in a way that is compatible with creating an optimization constraint that can be stored.
But inPoly is expecting numeric values, not optimization variables, so it fails.
In some cases fcn2optimexpr could be used to convert a function to an optimization constraint, but when you look at https://www.mathworks.com/help/optim/ug/supported-operations-on-optimization-variables-expressions.html I do not see any comparison operators being supported there
You might need to convert the problem based optimization into a solver based optimization and then attach nonlinear constraints to that.
... Or find a way to convert the inPoly tests into constraints. That might not be bad for simple polygons, but could be messy for an arbitrary area such as a map of a country.

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by