主要内容

mpcqpsolver

(要删除)使用KWIK算法解决二次编程问题

mpcqpsolverwill be removed in a future release. UsempcActiveSetSolverinstead. For more information, seeCompatibility Considerations

Description

example

[x,status] = mpcqpsolver(Linv,f,A,b,Aeq,beq,iA0,options)finds an optimal solution,x, to a quadratic programming problem by minimizing the objective function:

J = 1 2 x H x + f x

subject to inequality constraints A x b , and equality constraints A e q x = b e q statusindicates the validity ofx

example

[x,status,iA,lambda] = mpcqpsolver(Linv,f,A,b,Aeq,beq,iA0,options)also returns the active inequalities,iA,在解决方案和拉格朗日乘数,lambda, for the solution.

Examples

collapse all

找到值x最小化

f ( x ) = 0 5 x 1 2 + x 2 2 - x 1 x 2 - 2 x 1 - 6 x 2 ,

subject to the constraints

x 1 0 x 2 0 x 1 + x 2 2 - x 1 + 2 x 2 2 2 x 1 + x 2 3

Specify the Hessian and linear multiplier vector for the objective function.

H = [1 -1; -1 2]; f = [-2; -6];

Specify the inequality constraint parameters.

A = [1 0; 0 1; -1 -1; 1 -2; -2 -1]; b = [0; 0; -2; -2; -3];

DefineAeqandbeqto indicate that there are no equality constraints.

Aeq = []; beq = zeros(0,1);

Find the lower-triangular Cholesky decomposition ofH

[L,p] = chol(H,'lower'); Linv = inv(L);

It is good practice to verify thatHis positive definite by checking ifp = 0

p
p = 0

Create a default option set formpcActiveSetSolver

opt = mpcqpsolverOptions;

To cold start the solver, define all inequality constraints as inactive.

iA0 = false(size(b));

Solve the QP problem.

[x,status] = mpcqpsolver(linv,f,a,b,aeq,beq,ia0,opt);

Examine the solution,x

x
x =2×10.6667 1.3333

找到值x最小化

f ( x ) = 3 x 1 2 + 0 5 x 2 2 - 2 x 1 x 2 - 3 x 1 + 4 x 2 ,

subject to the constraints

x 1 0 x 1 + x 2 5 x 1 + 2 x 2 7

Specify the Hessian and linear multiplier vector for the objective function.

h = [6 -2;-2 1];f = [-3;4];

Specify the inequality constraint parameters.

A = [1 0; -1 -1; -1 -2]; b = [0; -5; -7];

DefineAeqandbeqto indicate that there are no equality constraints.

Aeq = []; beq = zeros(0,1);

Find the lower-triangular Cholesky decomposition ofH

[L,p] = chol(H,'lower'); Linv = inv(L);

Verify thatHis positive definite by checking ifp = 0

p
p = 0

Create a default option set formpcqpsolver

opt = mpcqpsolverOptions;

To cold start the solver, define all inequality constraints as inactive.

iA0 = false(size(b));

Solve the QP problem.

[X,状态,IA,lambda] = mpcqpsolver(linv,f,a,a,b,aeq,beq,ia0,opt);

Check the active inequality constraints. An active inequality constraint is at equality for the optimal solution.

iA
iA =3x1 logical array1 0 0

There is a single active inequality constraint.

View the Lagrange multiplier for this constraint.

lambda.ineqlin(1)
ans = 5.0000

Input Arguments

collapse all

逆矩阵的下三角Cholesky decomposition of Hessian matrix, specified as ann-经过-n矩阵,哪里n> 0is the number of optimization variables. For a given Hessian matrix,H,Linvcan be computed as follows:

[L,p] = chol(H,'lower'); Linv = inv(L);

His ann-经过-n矩阵,必须是对称和积极的。如果p= 0, thenHis positive definite.

Note

The KWIK algorithm requires the computation ofLinv而不是使用Hdirectly, as in theQuadprog(优化工具箱)command.

Multiplier of objective function linear term, specified as a column vector of lengthn

Linear inequality constraint coefficients, specified as anm-经过-n矩阵,哪里mis the number of inequality constraints.

如果your problem has no inequality constraints, use[]

Right-hand side of inequality constraints, specified as a column vector of lengthm

如果your problem has no inequality constraints, use零(0,1)

Linear equality constraint coefficients, specified as aq-经过-n矩阵,哪里qis the number of equality constraints, andq<=n。Equality constraints must be linearly independent withrank(Aeq) =q

如果your problem has no equality constraints, use[]

Right-hand side of equality constraints, specified as a column vector of lengthq

如果your problem has no equality constraints, use零(0,1)

Initial active inequalities, where the equal portion of the inequality is true, specified as a logical vector of lengthmaccording to the following:

  • 如果your problem has no inequality constraints, usefalse(0,1)

  • For a冷启动,false(m,1)

  • For awarm start, setiA0(i) == trueto start the algorithm with theith inequality constraint active. Use the optional output argumentiAfrom a previous solution to specifyiA0in this way. If bothiA0(i)andiA0(j)aretrue, then rowsiandjofAshould be linearly independent. Otherwise, the solution can fail withstatus = -2

Option set formpcqpsolver, specified as a structure created usingmpcqpsolverOptions

Output Arguments

collapse all

Optimal solution to the QP problem, returned as a column vector of lengthnmpcqpsolveralways returns a value forx。To determine whether the solution is optimal or feasible, check the solutionstatus

解决方案有效性指标,根据以下内容返回为整数:

Value Description
> 0 x是最佳的。status表示优化过程中执行的迭代次数。
0 The maximum number of iterations was reached. The solution,x, may be suboptimal or infeasible.
-1 The problem appears to be infeasible, that is, the constraint A x b cannot be satisfied.
-2 An unrecoverable numerical error occurred.

主动不平等现象是不平等的相等部分,作为长度的逻辑向量返回m。如果iA(i) == true, then thei对于解决方案,不平等是有效的x

UseiAtowarm starta subsequentmpcqpsolversolution.

Lagrange multipliers, returned as a structure with the following fields:

Field Description
Ineqlin 不平等约束的乘数,作为长度向量返回n。当解决方案是最优的,the elements ofIneqlinare nonnegative.
eqlin Multipliers of the equality constraints, returned as a vector of lengthq。最佳解决方案中没有符号限制。

尖端

  • The KWIK algorithm requires that the Hessian matrix,H, be positive definite. When calculatingLinv, use:

    [L, p] = chol(H,'lower');

    如果p= 0, thenHis positive definite. Otherwise,pis a positive integer.

  • mpcqpsolver提供对模型预测控制Toolbox™软件使用的QP求解器的访问。使用此命令在您自己的自定义MPC应用程序中解决QP问题。

Algorithms

mpcqpsolversolves the QP problem using an active-set method, the KWIK algorithm, based on[1]。For more information, seeQP Solvers

参考

[1]Schmid, C., and L.T. Biegler. ‘Quadratic Programming Methods for Reduced Hessian SQP’.Computers & Chemical Engineering18, no. 9 (September 1994): 817–32.https://doi.org/10.1016/0098-1354(94)E0001-4

Extended Capabilities

Version History

Introduced in R2015b

expand all

从R2020a开始警告