実行可能性モードを使用した解の取得
この例では、fmincon
'interior-point'
アルゴリズムの実行可能性モードを使用して、実行可能点を取得する方法を示します。自動微分を活用できるように、問題ベースのアプローチを使用します。この例は、Moré [1] の問題 9 からの引用です。
問題の設定
この問題では、5 次元最適化変数 x
と共に 5 つの 2 次制約を使用します。最初の x
要素は下限が 0、残りの 4 つの要素は上限が 0 です。
x = optimvar("x",5,"LowerBound",[0;-Inf;-Inf;-Inf;-Inf],"UpperBound",[Inf;0;0;0;0]);
この問題は航空機産業に由来するものなので、x
の要素に航空学の用語を使用しており、一部のパラメーターには指定された値が設定されます。
elevator = 0.1; % If elevator were 0, then [0 0 0 0 0] would be a solution
aileron = 0.0;
rudderdf = 0.0;
rollrate = x(1);
pitchrat = x(2);
yawrate = x(3);
attckang = x(4);
sslipang = x(5);
最適化問題および制約を作成します。
prob = optimproblem; prob.Constraints.eq1 = (-3.933*rollrate + 0.107*pitchrat + ... 0.126*yawrate - 9.99*sslipang - 45.83*aileron - 7.64*rudderdf - ... 0.727*pitchrat*yawrate + 8.39*yawrate*attckang - ... 684.4*attckang*sslipang + 63.5*pitchrat*attckang) == 0; prob.Constraints.eq2 = (-0.987*pitchrat - 22.95*attckang - ... 28.37*elevator + 0.949*rollrate*yawrate + 0.173*rollrate*sslipang) == 0; prob.Constraints.eq3 = (0.002*rollrate - 0.235*yawrate + ... 5.67*sslipang - 0.921*aileron - 6.51*rudderdf - ... 0.716*rollrate*pitchrat - 1.578*rollrate*attckang + ... 1.132*pitchrat*attckang) == 0; prob.Constraints.eq4 = (pitchrat - attckang - ... 1.168*elevator - rollrate*sslipang) == 0; prob.Constraints.eq5 = (-yawrate - 0.196*sslipang - ... 0.0071*aileron + rollrate*attckang) == 0;
この問題には目的関数がないため、prob.Objective
は指定しません。
実行可能性モードを使用しない解の試行
既定のソルバーとパラメーターを使用して、問題を解くことを試みます。開始点は [0 0 0 0 0]'
です。
x0.x = zeros(5,1); [sol,~,exitflag,output] = solve(prob,x0)
Solving problem using fmincon. Solver stopped prematurely. fmincon stopped because it exceeded the iteration limit, options.MaxIterations = 1.000000e+03.
sol = struct with fields:
x: [5x1 double]
exitflag = SolverLimitExceeded
output = struct with fields:
iterations: 1000
funcCount: 1003
constrviolation: 11.1712
stepsize: 8.2265e-05
algorithm: 'interior-point'
firstorderopt: 0
cgiterations: 0
message: 'Solver stopped prematurely....'
bestfeasible: []
objectivederivative: "closed-form"
constraintderivative: "closed-form"
solver: 'fmincon'
ソルバーが途中で停止します。反復制限および関数の評価制限を増やし、再度実行します。
options = optimoptions("fmincon","MaxIterations",1e4,"MaxFunctionEvaluations",1e4); [sol,~,exitflag,output] = solve(prob,x0,"Options",options)
Solving problem using fmincon. Converged to an infeasible point. fmincon stopped because the size of the current step is less than the value of the step size tolerance but constraints are not satisfied to within the value of the constraint tolerance. Consider enabling the interior point method feasibility mode.
sol = struct with fields:
x: [5x1 double]
exitflag = NoFeasiblePointFound
output = struct with fields:
iterations: 4089
funcCount: 4092
constrviolation: 5.0899
stepsize: 5.9783e-11
algorithm: 'interior-point'
firstorderopt: 0
cgiterations: 0
message: 'Converged to an infeasible point....'
bestfeasible: []
objectivederivative: "closed-form"
constraintderivative: "closed-form"
solver: 'fmincon'
ソルバーが実行不可能点に収束します。
実行可能性モードを使用した求解
再試行して問題を解きます。今回は EnableFeasibilityMode
オプションおよび SubproblemAlgorithm
オプションを指定します。一般に、実行可能性モードを使用する必要がある場合は、SubproblemAlgorithm
オプションを 'cg'
に設定することをお勧めします。
options = optimoptions(options,"EnableFeasibilityMode",true,... "SubproblemAlgorithm","cg"); [sol,~,exitflag,output] = solve(prob,x0,"Options",options)
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: [5x1 double]
exitflag = OptimalSolution
output = struct with fields:
iterations: 138
funcCount: 139
constrviolation: 2.9070e-04
stepsize: 0.0057
algorithm: 'interior-point'
firstorderopt: 0
cgiterations: 0
message: 'Local minimum found that satisfies the constraints....'
bestfeasible: []
objectivederivative: "closed-form"
constraintderivative: "closed-form"
solver: 'fmincon'
今回、ソルバーは実行可能解に到達したことを報告します。ただし、output.constrviolation
の制約違反があまり小さくありません。制約の許容誤差を厳しくして、もう一度問題を解きます。解法プロセスを高速化するため、返された実行可能解から開始します。
options.ConstraintTolerance = 1e-8;
[sol,~,exitflag,output] = solve(prob,sol,"Options",options)
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: [5x1 double]
exitflag = OptimalSolution
output = struct with fields:
iterations: 2
funcCount: 3
constrviolation: 2.1164e-16
stepsize: 1.7083e-08
algorithm: 'interior-point'
firstorderopt: 0
cgiterations: 0
message: 'Local minimum found that satisfies the constraints....'
bestfeasible: [1x1 struct]
objectivederivative: "closed-form"
constraintderivative: "closed-form"
solver: 'fmincon'
制約違反がかなり小さくなりました。このように解が改善されるまでに、ソルバーは 2 回しか反復を行っていません。
参考文献
[1] Moré, J. J. "A collection of nonlinear model problems." Proceedings of the AMS-SIAM Summer Seminar on the Computational Solution of Nonlinear Systems of Equations, Colorado, 1988. Argonne National Laboratory MCS-P60-0289, 1989.