function [ITER,B,x,T,flg] = RevisedSimplex(A,B,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 % simplex = 1; ITER = 0; [m,n] = size(A); x = zeros(n,1); x(B) = T(1:m,1); flg = 0; obj = c'*x; while (simplex == 1) % % determine the next s and r values. % y = T(end,2:end)'; [zmin,s] = min(c-A'*y); t = T(1:end-1,2:end)*A(:,s); r = Revisedgetr(n,s,B,T,t); if (r < 1) disp('LP has no lower bound'); simplex = 0; flg = 1; continue; end ITER = ITER + 1; x = zeros(n,1); x(B) = T(1:m,1); f = ['Iteration ', num2str(ITER), ' Obj ', num2str(c'*x), '. Smallest component in c-A^T*y: ', ... num2str(zmin), ' at s =', num2str(s), '. Component r = ', num2str(r), ' out of basis']; obj1 = c'*x; %% disp(f); % % update the revised simplex tableau. % [T,B1,flg]=RevisedSimplexTableau(B,r,s,t,zmin,T); if (flg == 1) disp('LP is degenerate'); simplex = 0; continue; end % % check for convergence. % FF = setdiff(B1,B); if (length(FF) == 0 | (abs(obj1-obj) < 1e-14 & ITER > 1)) disp('Simplex Method has converged'); simplex = 0; continue; end B = B1; obj = obj1; end