フィルターのクリア

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 Center および File ExchangeGet 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