このページは機械翻訳を使用して翻訳されました。元の英語を参照するには、ここをクリックします。
surrogateopt
形式と他のソルバー形式の間で非線形制約を変換する
制約フォームを変換する理由
非線形不等式制約を持つ問題に対して surrogateopt
を含むさまざまなソルバーを試すには、surrogateopt
に必要な形式と他のソルバーに必要な形式の間で変換する必要があります。
surrogateopt
構造形式から他のソルバーに変換する
surrogateopt
の目的関数 objconstr(x)
は構造体を返します。Fval
フィールドには、目的関数の値 (スカラー) が含まれます。Ineq
フィールドには制約関数値のベクトルが含まれます。ソルバーは、Ineq
フィールド内のすべての値が 0 以下になるようにします。正の値は制約違反を示します。
他のソルバーは、目的関数が構造体ではなくスカラー値を返すことを期待します。他のソルバーも、非線形制約関数が c(x)
を含む構造体ではなく、 c(x)
と ceq(x)
の 2 つの出力を返すことを期待しています。
surrogateopt
関数 objconstr(x)
を他のソルバーで使用できるように変換するには:
目的関数を
@(x)objconstr(x).Fval
に設定します。非線形制約関数を
@(x)deal(objconstr(x).Ineq,[])
に設定します。
以下に例を示します。
function ff = objconstr(x) ff.Fval = norm(x)^2; ff.Ineq = norm(x - [5,8])^2 - 25; end
objconstr
を使用して制約付き最小化問題を解くには、surrogateopt
を呼び出します。
lb = [-10,-20]; ub = [20,10]; sol = surrogateopt(@objconstr,lb,ub)
surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'. sol = 2.3504 3.7598
fmincon
を使用して同じ問題を解決するには、目的と制約を別々の関数に分割します。deal
関数を使用して、非線形等式制約を []
として含めます。
objfcn = @(x)objconstr(x).Fval; nlcon = @(x)deal(objconstr(x).Ineq,[]);
目的関数 objfcn
と非線形制約関数 nlcon
を使用して fmincon
を呼び出します。
[solf,fvalf,eflag,output] = ...
fmincon(objfcn,[0,0],[],[],[],[],lb,ub,nlcon)
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. solf = 2.3500 3.7600 fvalf = 19.6602 eflag = 1 output = struct with fields: iterations: 7 funcCount: 24 constrviolation: 0 stepsize: 2.0397e-05 algorithm: 'interior-point' firstorderopt: 4.8151e-06 cgiterations: 0 message: '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.↵↵<stopping criteria details>↵↵Optimization completed: The relative first-order optimality measure, 6.403047e-07,↵is less than options.OptimalityTolerance = 1.000000e-06, and the relative maximum constraint↵violation, 0.000000e+00, is less than options.ConstraintTolerance = 1.000000e-06.' bestfeasible: [1×1 struct]
同じ変換を使用して、patternsearch
または ga
を使用して問題を解決することもできます。
他のソルバーからsurrogateopt
構造形式に変換する
他のソルバーの形式で記述された問題がある場合は、 packfcn
関数を使用して、目的関数と非線形制約を surrogateopt
の構造形式に変換します。目的関数が関数ハンドル @obj
であり、非線形制約関数が @nlconst
である場合、 surrogateopt
には目的関数 objconstr
を使用します。
objconstr = packfcn(@obj,@nlconst);
この例では、目的関数は Rosenbrock 関数です。
ros = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
解が点[1/3,1/3]を中心とする半径1/3の円盤の内側にあるように制限する制約関数を指定します。
function [c,ceq] = circlecon(x)
c = (x(1)-1/3)^2 + (x(2)-1/3)^2 - (1/3)^2;
ceq = [];
各コンポーネントに -2 と 2 の境界を設定します。
lb = [-2,-2]; ub = [2,2];
[0,0]から始めてpatternsearch
を使用して問題を解きます。
x0 = [0,0]; x = patternsearch(ros,x0,[],[],[],[],lb,ub,@circlecon)
Optimization finished: mesh size less than options.MeshTolerance and constraint violation is less than options.ConstraintTolerance. x = 0.6523 0.4258
surrogateopt
による解決のために問題を変換します。
objconstr = packfcn(ros,@circlecon); xs = surrogateopt(objconstr,lb,ub)
surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'. xs = 0.6543 0.4286