Main Content

制約付き非線形最適化の解法,問題ベース

この例では、問題ベースのアプローチを使用して非線形制約付き非線形目的関数の最小値を求める方法を説明します。同様の問題の解法を示すビデオについては、Problem-Based Nonlinear Programmingを参照してください。

問題ベースのアプローチを使用して非線形目的関数の最小値を求めるには、まず目的関数をファイルまたは無名関数として記述します。この例の目的関数は次のとおりです。

f ( x , y ) = e x ( 4 x 2 + 2 y 2 + 4 x y + 2 y - 1 ) .

typeobjfunx
function f = objfunx(x,y) f = exp(x).*(4*x.^2 + 2*y.^2 + 4*x.*y + 2*y - 1); end

最適化問題の変数xおよびyを作成します。

x = optimvar('x'); y = optimvar('y');

最適化変数の式として目的関数を作成します。

obj = objfunx(x,y);

objを目的関数として使用して最適化問題を作成します。

prob = optimproblem('Objective',obj);

次のように指定して、傾いた楕円に解がある非線形制約を作成します。

x y 2 + ( x + 2 ) 2 + ( y - 2 ) 2 2 2 .

最適化変数の不等式として制約を作成します。

TiltEllipse = x.*y/2 + (x+2).^2 + (y-2).^2/2 <= 2;

制約を問題に含めます。

prob.Constraints.constr = TiltEllipse;

初期点をx = –3,y = 3として表す構造体を作成します。

x0.x = -3; x0.y = 3;

問題を確認します。

show(prob)
OptimizationProblem : Solve for: x, y minimize : (exp(x) .* (((((4 .* x.^2) + (2 .* y.^2)) + ((4 .* x) .* y)) + (2 .* y)) - 1)) subject to constr: ((((x .* y) ./ 2) + (x + 2).^2) + ((y - 2).^2 ./ 2)) <= 2

問題を解きます。

[sol,fval] = solve(prob,x0)
Solving problem using fmincon. Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
sol =struct with fields:x: -5.2813 y: 4.6815
fval = 0.3299

異なる開始点を試します。

x0.x = -1; x0.y = 1; [sol2,fval2] = solve(prob,x0)
Solving problem using fmincon. Feasible point with lower objective function value found. Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
sol2 =struct with fields:x: -0.8210 y: 0.6696
fval2 = 0.7626

楕円、目的関数の等高線、2 つの解をプロットします。

f = @objfunx; g = @(x,y) x.*y/2+(x+2).^2+(y-2).^2/2-2; rnge = [-5.5 -0.25 -0.25 7]; fimplicit(g,'k-') axis(rnge); holdonfcontour(f,rnge,'LevelList',logspace(-1,1)) plot(sol.x,sol.y,'ro','LineWidth',2) plot(sol2.x,sol2.y,'ko','LineWidth',2) legend('Constraint','f Contours','Global Solution','Local Solution','Location','northeast'); holdoff

Figure contains an axes object. The axes object contains 4 objects of type implicitfunctionline, functioncontour, line. These objects represent Constraint, f Contours, Global Solution, Local Solution.

これらの解は非線形制約の境界上にあります。この等高線図は、これらが唯一の局所的最小値であることを示しています。プロットは、[–2,3/2] の近くに停留点があり、[–2,0] および [–1,4] の近くに局所的最大値があることも示しています。

fcn2optimexprを使用した目的関数の変換

一部の目的関数またはソフトウェア バージョンでは、fcn2optimexprを使用して、非線形関数を最適化式に変換しなければなりません。詳細は、最適化変数および式でサポートされる演算非線形関数から最適化式への変換を参照してください。fcn2optimexprの呼び出しで変数xおよびyを渡し、それぞれのobjfunx入力に対応する最適化変数を示します。

obj = fcn2optimexpr(@objfunx,x,y);

前と同様に、objを目的関数として使用して最適化問題を作成します。

prob = optimproblem('Objective',obj);

解法プロセスの残りの部分は同じです。

Copyright 2018–2020 The MathWorks, Inc.

参考

関連するトピック