matlab优化工具箱的“解决”功能。如何更改求解器?

时间:2019-09-03 20:40:42

标签: matlab optimization mathematical-optimization

我想在Matlab的优化工具箱中使用不同的求解器(例如quadprogfminconfminunc)/具有solve函数的算法来求解相同的基本非线性最小化。 / p>

这是正在发生的事情: 我尝试使用optimoptions函数通过结构设置求解器和算法。它是这样的:

options = optimoptions(@fminunc, 'Algorithm', 'quasi-newton')
[S, fval, exitflag] =  solve(nonlinprob, x0,'options', options)

但是该函数显然无论如何都只使用带有内部点凸算法的quadprog求解器。似乎忽略了我设置的其他选项。我正在运行Matlab r2018b。 代码部分介绍了使用示例求解器和所选算法处理的优化问题以及Solve函数调用返回的结果

该函数将覆盖选项,但是我需要强制它以不同的方式执行。 我该怎么办?

OptimizationProblem : 

    minimize :
       4*x^2 + 2*y^2 + 4*x*y + 2*y - 1

    subject to cons1:
       x + 6*y <= 2

    subject to cons2:
       -4*x + 2*y <= 0

    variable bounds:
       -10 <= x <= 10

       -10 <= y
x0 = 
    x: -3
    y: 3

x0 = 
    x: -3
    y: 3

options = 
  fminunc options:

   Options used by current Algorithm ('quasi-newton'):
   (Other available algorithms: 'trust-region')

   Set properties:
                   Algorithm: 'quasi-newton'

   Default properties:
              CheckGradients: 0
                     Display: 'final'
    FiniteDifferenceStepSize: 'sqrt(eps)'
        FiniteDifferenceType: 'forward'
      MaxFunctionEvaluations: '100*numberOfVariables'
               MaxIterations: 400
              ObjectiveLimit: -1.0000e+20
         OptimalityTolerance: 1.0000e-06
                   OutputFcn: []
                     PlotFcn: []
    SpecifyObjectiveGradient: 0
               StepTolerance: 1.0000e-06
                    TypicalX: 'ones(numberOfVariables,1)'

   Show options not used by current Algorithm ('quasi-newton')

Your Hessian is not symmetric. Resetting H=(H+H')/2.
Warning: You have passed FMINUNC options to QUADPROG. QUADPROG will use the common options and ignore the FMINUNC options that do not apply.
To avoid this warning, convert the FMINUNC options using OPTIMOPTIONS.
The interior-point-convex algorithm does not accept an initial point.
Ignoring X0.

Minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the selected value of the optimality tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.

<stopping criteria details>
S = 
    x: 0.5000
    y: -1.0000

fval = -2.0000
exitflag = 
    OptimalSolution

1 个答案:

答案 0 :(得分:0)

会发生什么?

您使用函数solve,函数solve决定调用quadprog函数以求解方程组。但是现在quadprog收到了针对fminunc的选项!因此,quadprog当然不能管理这些选项,而是选择一些默认选项。

您需要专门选择合适的求解器(在您的情况下为fminunc):

options_fminunc     = optimoptions(@fminunc, 'Algorithm', 'quasi-newton')
[S, fval, exitflag] = fminunc(nonlinprob, x0,'options', options_fminunc)
%                        ↑
%                 should be fminunc