在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
%有效集 function activeset H=[2 -1; -1 4]; c=[-1 -10]'; Ae=[ ]; be=[ ]; Ai=[-3 -2; 1 0; 0 1]; bi=[-6 0 0]'; x0=[0 0]'; [x,lambda,exitflag,output]=qpact(H,c,Ae,be,Ai,bi,x0) function [x,lamk,exitflag,output]=qpact(H,c,Ae,be,Ai,bi,x0) % 初始化 epsilon=1.0e-9; err=1.0e-6; k=0; x=x0; n=length(x); kmax=1.0e3; ne=length(be); ni=length(bi); lamk=zeros(ne+ni,1); index=ones(ni,1); for i=1:ni if (Ai(i,:)*x>bi(i)+epsilon) index(i)=0; end end while (k<=kmax) %求解子问题 Aee=[]; if(ne>0), Aee=Ae; end for j=1:ni if(index(j)>0), Aee=[Aee; Ai(j,:)]; end end gk=H*x+c; [m1,n1] = size(Aee); [dk,lamk]=qsubp(H,gk,Aee,zeros(m1,1)); if(norm(dk)<=err) y=0.0; if(length(lamk)>ne) [y,jk]=min(lamk(ne+1:length(lamk))); end if(y>=0) exitflag=0; else exitflag=1; for i=1:ni if(index(i)&&(ne+sum(index(1:i)))==jk) index(i)=0; break; end end end k=k+1; else exitflag=1; %求步长 alpha=1.0; tm=1.0; for i=1:ni if((index(i)==0)&&(Ai(i,:)*dk<0)) tm1=(bi(i)-Ai(i,:)*x)/(Ai(i,:)*dk); if(tm1<tm) tm=tm1; ti=i; end end end alpha=min(alpha,tm); x=x+alpha*dk; %修正有效集 if(tm<1), index(ti)=1; end end if(exitflag==0), break; end k=k+1; end output.fval=0.5*x'*H*x+c'*x; output.iter=k; % 求解子问题 function [x,lambda]=qsubp(H,c,Ae,be) ginvH=pinv(H); [m,n]=size(Ae); if(m>0) rb=Ae*ginvH*c + be; lambda=pinv(Ae*ginvH*Ae')*rb; x=ginvH*(Ae'*lambda-c); else x=-ginvH*c; lambda=0; end
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论