Uploaded by Nikhil Markan

Simplex_Method_OT

advertisement
clc
clear all
format short
A=[3,-1, 2, 1 0 0 7;-2 4 0 0 1 0 12; -4 3 8 0 0 1 10]
C=[-1,3,-2,0,0,0]
BV=[4 5 6]
%initial_bases
Numberofrows=size(A,1);
Solutioncolumn=size(A,2);
count=1
for t=1:10
for i=1:Solutioncolumn-1
zjcj(i)=sum(C(BV)*A(:,i))-C(i);
end
[pivot_value, pivot_col]=min(zjcj)
if pivot_value >= 0
y=zeros(Solutioncolumn,1);
y(BV)=A(:,Solutioncolumn)
optimal_value=C*y(1:Solutioncolumn-1,1)
no_of_iterations=count
return
else
for i=1:Numberofrows
if(A(i,pivot_col)>0)
m(i)=A(i,Solutioncolumn)./A(i,pivot_col);
else
m(i)=inf;
end
end
[leaving_value, pivot_row]=min(m)
for i=1:size(A,1)
if i==pivot_row
BV(i)=pivot_col;
end
end
A(pivot_row,:)=A(pivot_row,:)/A(pivot_row,pivot_col);
for i=1:Numberofrows
if i~=pivot_row
A(i,:)=A(i,:)-(A(i,pivot_col).*A(pivot_row,:));
end
end
count=count+1;
end
end
Download