Main Content

使用可行性模式获得解

此示例说明如何使用 fmincon 'interior-point' 算法的可行性模式来获得一个可行点。为了利用自动微分,该示例使用了基于问题的方法。该示例摘自 Moré 的问题 9 [1]

问题设立

该问题有一个五维优化变量 x 以及五个二次约束。第一个 x 分量的下界为 0,其余四个分量的上界为 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'

求解器收敛于一个不可行点。

使用可行性模式求解

再次尝试求解此问题,这次指定 EnableFeasibilityModeSubproblemAlgorithm 选项。通常,如果您需要使用可行性模式,最好的方法是将 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.9069e-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: 8.8818e-16
                stepsize: 1.7082e-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'

现在,约束违反值已相当小。求解器只需两次迭代就得到了这一改进的解。

参考资料

[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.

另请参阅

|

相关主题