LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
ReduceQP.m
1function [R,fr,Air,bir,y1,Q,Es,Status,Flag]=ReduceQP(H,f,Ae,be,Ai,bi,lb,ub,tol)
2% [Hr,fr,Air,bir,fvr,y1,Q,,Es,Status,Flag]=ReduceQP(H,f,Ae,be,Ai,bi,tol)
3% Given the following general Convex QP problem :
4% min 0.5*x'*H*x + f'*x , such that Ae*x=be; Ai*x<=bi; lb<=x<=ub
5% x
6% with H'=H>=0 and [Ae;H] full column rank
7% ReduceQP computes a reduced strictly convex QP problem
8% without any equality constraints :
9% min 0.5*y2'*Hr*y2 + fr'*y2 , such that Air*y2<=bir;
10% y2
11% and y1 such that the solution of the original problem is x=Q*[y1;y2]
12% where y2 is the solution of the reduced problem of size (n-p).
13%
14% Note [p,n]=size(Ae), Q=[Q1,Q2] such that Hr=Q2'*H*Q2>0, Ae*Q2=0;
15% Q1 is nxp and Q2 is nx(n-p)
16%
17%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18n=length(f);Flag=1;Status='OK';
19if nargin<9, tol=16*n*eps;end
20if nargin<8, ub=inf(n,1);end
21if nargin<7, lb=-inf(n,1);end
22if nargin<6, Ai=[];bi=[];end
23if nargin<4, error('ReduceQP requires at least 4 parameters');end
24[E,Error]=ExtendedFactorization(H,tol);Es=E;
25if ~Error
26 p=length(be);
27 %Null space decomposition
28 [R,Q,e]=RightQR(Ae);
29 ref=abs(R(1,1))*tol;r=1;
30 while r<p&&abs(R(r+1,r+1))>ref;r=r+1;end
31 L1=1:r;L2=r+1:n;
32 y1=R(L1,L1)\be(e(L1));%particular solution of equality constraints
33 if r<p%check rank deficiency
34 err=be-Ae*Q(:,L1)*y1;
35 if norm(err)<tol*norm(be)%however feasible
36 Status='Rank deficient Feasible Equality Constraints';
37 Flag=2;
38 else
39 Flag=-1;
40 Status='Infeasible Equality constraints';
41 Air=[];bir=[];R=[];fr=[];y1=[];Q=[];Es=[];return;
42 end
43 end
44 E2=E*Q(:,L2);%reduced hessian factorization
45 [R,~,er]=LeftQR(E2);
46 ref=abs(R(1,1))*tol;r=1;
47 while r<n-p&&abs(R(r+1,r+1))>ref;r=r+1;end
48 if r<n-p
49 Flag=-3;
50 Status='Reduce Hessian is singular';
51 Air=[];bir=[];R=[];fr=[];y1=[];Q=[];Es=[];return;
52 end
53 Eye=eye(n);%Full Identity matrix
54 R(:,er)=R;
55 E1=E*Q(:,L1);
56 fr=E2'*E1*y1+Q(:,L2)'*f;%reduced linear term
57 %add bounds if any
58 Lu=isfinite(ub);Ll=isfinite(lb);
59 Ai=[Ai;Eye(Lu,:);-Eye(Ll,:)];bi=[bi;ub(Lu);-lb(Ll)];
60 if ~isempty(Ai)
61 Ai=Ai*Q;
62 Air=Ai(:,L2);bir=bi-Ai(:,L1)*y1;
63 else
64 Air=[];bir=[];
65 end
66else
67 Flag=-4;
68 Status='The QP problem is not convex';
69 Air=[];bir=[];R=[];fr=[];y1=[];Q=[];Es=[];return;
70end
71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%