mpcqpsolver
(要删除)使用KWIK算法解决二次编程问题
mpcqpsolver
will be removed in a future release. UsempcActiveSetSolver
instead. For more information, seeCompatibility Considerations。
Syntax
Description
Examples
Solve Quadratic Programming Problem Using Active-Set Solver
找到值x最小化
subject to the constraints
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];
DefineAeq
andbeq
to 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 thatH
is 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
Check Active Inequality Constraints for QP Solution
找到值x最小化
subject to the constraints
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];
DefineAeq
andbeq
to 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 thatH
is 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
Linv
—逆矩阵的下三角Cholesky decomposition of Hessian matrix
n-经过-nmatrix
逆矩阵的下三角Cholesky decomposition of Hessian matrix, specified as ann-经过-n矩阵,哪里n> 0is the number of optimization variables. For a given Hessian matrix,H,Linv
can 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.
f
—Multiplier of objective function linear term
column vector
Multiplier of objective function linear term, specified as a column vector of lengthn。
A
—Linear inequality constraint coefficients
m-经过-nmatrix|[]
Linear inequality constraint coefficients, specified as anm-经过-n矩阵,哪里mis the number of inequality constraints.
如果your problem has no inequality constraints, use[]
。
b
—Right-hand side of inequality constraints
column vector of lengthm
Right-hand side of inequality constraints, specified as a column vector of lengthm。
如果your problem has no inequality constraints, use零(0,1)
。
Aeq
—Linear equality constraint coefficients
q-经过-nmatrix|[]
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[]
。
beq
—Right-hand side of equality constraints
column vector of lengthq
Right-hand side of equality constraints, specified as a column vector of lengthq。
如果your problem has no equality constraints, use零(0,1)
。
iA0
—Initial active inequalities
logical vector of lengthm
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, use
false(0,1)
。For a冷启动,
false(m,1)
。For awarm start, set
iA0(i) == true
to start the algorithm with theith inequality constraint active. Use the optional output argumentiA
from a previous solution to specifyiA0
in this way. If bothiA0(i)
andiA0(j)
aretrue
, then rowsiandjofA
should be linearly independent. Otherwise, the solution can fail withstatus = -2
。
options
—Option set formpcqpsolver
structure
Option set formpcqpsolver
, specified as a structure created usingmpcqpsolverOptions
。
Output Arguments
x
— Optimal solution to the QP problem
column vector
Optimal solution to the QP problem, returned as a column vector of lengthn。mpcqpsolver
always returns a value forx
。To determine whether the solution is optimal or feasible, check the solutionstatus
。
status
— Solution validity indicator
positive integer |0
|-1
|-2
解决方案有效性指标,根据以下内容返回为整数:
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 cannot be satisfied. |
-2 |
An unrecoverable numerical error occurred. |
iA
— Active inequalities
logical vector of lengthm
主动不平等现象是不平等的相等部分,作为长度的逻辑向量返回m。如果iA(i) == true
, then thei对于解决方案,不平等是有效的x
。
UseiA
towarm starta subsequentmpcqpsolver
solution.
lambda
— Lagrange multipliers
structure
Lagrange multipliers, returned as a structure with the following fields:
Field | Description |
---|---|
Ineqlin |
不平等约束的乘数,作为长度向量返回n。当解决方案是最优的,the elements ofIneqlin are 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 calculating
Linv
, use:[L, p] = chol(H,'lower');
如果p= 0, thenHis positive definite. Otherwise,pis a positive integer.
mpcqpsolver
提供对模型预测控制Toolbox™软件使用的QP求解器的访问。使用此命令在您自己的自定义MPC应用程序中解决QP问题。
Algorithms
mpcqpsolver
solves 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
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
You can use
mpcqpsolver
as a general-purpose QP solver that supports code generation. Create the functionmyCode
that usesmpcqpsolver
。function[out1,out2] = myCode(in1,in2)%#codegen。。。[x,status] = mpcqpsolver(Linv,f,A,b,Aeq,Beq,iA0,options);。。。
Generate C code withMATLAB®Coder™。
func ='myCode'; cfg = coder.config('mex');% or 'lib', 'dll'codegen('-config',CFG,Func,'-o',func);
For code generation, use the same precision for all real inputs, including options. Configure the precision as
'double'
or'single'
usingmpcqpsolverOptions
。
Version History
Introduced in R2015bR2020a:mpcqpsolver
will be removed
从R2020a开始警告
mpcqpsolver
will be removed in a future release. UsempcActiveSetSolver
instead. There are differences between these functions that require updates to your code.
The following differences require updates to your code:
For
mpcActiveSetSolver
, you define inequality constraints in the formAx≤b。以前,为mpcqpsolver
, you defined inequality constraints in the formAx≥bFor
mpcActiveSetSolver
, you specify solver options with a structure created using thempcActiveSetOptions
功能。以前,为mpcqpsolver
, you created an option structure using thempcqpsolverOptions
功能。These option structures contain the same options, though some option names have changed.By default, you pass the Hessian matrix to
mpcActiveSetSolver
。Previously, you passed the inverse of lower-triangular Cholesky decomposition (Linv
)Hessian Matrixmpcqpsolver
。To continue to useLinv
, set theUseHessianAsInput
field of the structure returned bympcActiveSetSolver
tofalse
。When your QP problem has either no inequality constraints or no equality constraints, the corresponding
A
orAeq
input argument tompcActiveSetSolver
must bezeros(0,n)
, wheren
is the number of decision variables. Previously, formpcqpsolver
, you specified these input arguments as[]
。
This table shows some typical usages ofmpcqpsolver
and how to update your code to usempcActiveSetSolver
instead.
Not Recommended | Recommended |
---|---|
opt = mpcqpsolverOptions; [x,status] = mpcqpsolver(Linv,f,A,b,... Aeq,beq,iA0,opt); |
opt = mpcActiveSetOptions; opt.UseHessianAsInput = false; [x,status] = mpcActiveSetSolver(Linv,f,... -A,-b,Aeq,beq,iA0,opt); Alternatively, you can use the Hessian matrix, opt = mpcActiveSetOptions; [x,status] = mpcActiveSetSolver(H,f,... -A,-b,Aeq,beq,iA0,opt); |
opt = mpcqpsolverOptions('single'); [x,status] = mpcqpsolver(Linv,f,A,b,... Aeq,beq,iA0,opt); |
opt = mpcActiveSetOptions('single'); opt.UseHessianAsInput = false; [x,status] = mpcActiveSetSolver(Linv,f,... -A,-b,Aeq,beq,iA0,opt); |
opt = mpcqpsolverOptions; opt.MaxIter = 300; opt.FeasibilityTol = 1e-5; [x,status] = mpcqpsolver(Linv,f,A,b,... Aeq,beq,iA0,opt); |
opt = mpcActiveSetOptions; opt.UseHessianAsInput = false; opt.MaxIterations = 300; opt.ContraintTolerance = 1e-5; [x,status] = mpcActiveSetSolver(Linv,f,... -A,-b,Aeq,beq,iA0,opt); |
[x,status] = mpcqpsolver(Linv,f,[],... zeros(0,1),Aeq,beq,iA0,opt); |
n =长度(f);opt.usehessianasinput = false;[x,status] = mpcActiveSetSolver(Linv,f,... zeros(0,n),zeros(0,1),Aeq,beq,iA0,opt); |
[x,status] = mpcqpsolver(Linv,f,A,b,... [],zeros(0,1),iA0,opt); |
n =长度(f);opt.usehessianasinput = false;[x,status] = mpcactivesetsolver(linv,f,... -a,-b,zeros(0,n),零(0,1),ia0,opt); |
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- 丹麦(English)
- Deutschland(德语)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(德语)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)