function [ITER,B,T,flg] = BLPRevisedSimplex(A,B,L,U,l,u,c,T) % % This is the Simplex Method using the Revised Simplex Tableau. % We assume the Tableau T has been initialized on input. % Written by Ming Gu for Math 170 % March 2007 % % flg = 0: convergence % flg = 1: LP unbounded below % flg = 2: LP degenerate % simplex = 1; ITER = 0; [m,n] = size(A); x = zeros(n,1); x(L) = l(L); x(U) = u(U); x(B) = T(1:m,2:m+1)*(b -A(:,L)*x(L) - A(:,U)*x(U)); flg = 0; obj = c'*x; ctol = 1e-13; while (simplex == 1) % % determine the next s and r values. % y = T(end,2:end)'; x(L) = l(L); x(U) = u(U); x(B) = T(1:m,2:m+1)*(b -A(:,L)*x(L) - A(:,U)*x(U)); t0 = x(B); % % first look for positive components in c(U)'-y'*A(:,U) % sflg = 1; if (length(U) > 0) ff = ['In U branch ITER = ',num2str(ITER)]; disp(ff); [Y,I] = sort(c(U)'-y'*A(:,U)); mask = find(Y > ctol); if (length(mask) >= 1) % % found positive components. try obj reduction. % for sk = length(mask):-1:1 % % loop over all possible s choices to reduce % chance of non-convergence due to degeneracy. % s = U(I(sk)); zmin = Y(sk); t = T(1:end-1,2:end)*A(:,s); [r,BUcase] = BURevisedgetr(n,s,B,T,t,t0,l,u); ff = ['sk = ',num2str(sk), ' BUcase = ', num2str(BUcase)]; disf(ff); if (BUcase < 0) disp('Failure in BURevisedgetr'); simplex = 0; flg = 1; continue; end Unew = setdiff(U,s); Lnew = L; Bnew = B; if (BUcase == 0) Lnew = [Lnew;s]; sflg = 0; break; end if (BUcase == 1) Unew = [Unew;B(r)]; [Tnew,Bnew,flg] = RevisedSimplexTableau(B,r,s,t,zmin,T); end if (BUcase == 2) Lnew = [Lnew;B(r)]; [Tnew,Bnew,flg] = RevisedSimplexTableau(B,r,s,t,zmin,T); end xnew = zeros(n,1); xnew(Lnew) = l(Lnew); xnew(Unew) = u(Unew); xnew(Bnew) = Tnew(1:m,2:m+1)*(b -A(:,Lnew)*xnew(Lnew) - A(:,Unew)*x(Unew)); objnew = c'*xnew; if (flg == 0 & objnew-obj < -ctol) % % success. update the revised simplex tableau. % sflg = 0; B = Bnew; L = Lnew; U = Unew; T = Tnew; obj = objnew; ITER = ITER + 1; f = ['Iteration ', num2str(ITER), ' Obj ', num2str(obj)]; disp(f); break; end end end if (sflg == 1 & length(L) > 0) disp('In L branch'); [Y,I] = sort(c(L)'-y'*A(:,L)); mask = find(Y <-ctol); if (length(mask) >= 1) % % found positive components. try obj reduction. % sflg = 1; for sk = 1:length(mask) % % loop over all possible s choices to reduce % chance of non-convergence due to degeneracy. % s = L(I(sk)); zmin = Y(sk); t = T(1:end-1,2:end)*A(:,s); [r,BLcase] = BLRevisedgetr(n,s,B,T,t,t0,l,u); if (BLcase < 0) disp('Failure in BLRevisedgetr'); simplex = 0; flg = 1; continue; end Lnew = setdiff(L,s); Unew = U; Bnew = B; if (BLcase == 0) Unew = [Unew;s]; sflg = 0; break; end if (BLcase == 1) Unew = [Unew;B(r)]; [Tnew,Bnew,flg] = RevisedSimplexTableau(B,r,s,t,zmin,T); end if (BLcase == 2) Lnew = [Lnew;B(r)]; [Tnew,Bnew,flg] = RevisedSimplexTableau(B,r,s,t,zmin,T); end xnew = zeros(n,1); xnew(Lnew) = l(Lnew); xnew(Unew) = u(Unew); xnew(Bnew) = Tnew(1:m,2:m+1)*(b -A(:,Lnew)*xnew(Lnew) - A(:,Unew)*x(Unew)); objnew = c'*xnew; if (flg == 0 & objnew-obj < -ctol) % % success. update the revised simplex tableau. % sflg = 0; B = Bnew; L = Lnew; U = Unew; T = Tnew; obj = objnew; ITER = ITER + 1; f = ['Iteration ', num2str(ITER), ' Obj ', num2str(obj)]; disp(f); break; end end end if (sflg == 1) % % none of the s choices was good enough to avoid degeneracy. Give up. % disp('LP is degenerate'); simplex = 0; flg = 2; %%% disp(T(1:end-1,1)); continue; end end