Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- C= [11, 13, 17, 14; 16, 18, 14, 10; 21, 24, 13, 10];
- S= [8 5 9];
- D= [8 7 5 4];
- [m ,n]= size(C);
- if(sum(S)==sum(D))
- disp('Balanced');
- else if(sum(S)<sum(D))
- C(end+1,:)=zeros(1,n);
- S(end+1)= sum(D)- sum(S);
- s=sum(D);
- else
- C(:,end+1)=zeros(m,1);
- D(end+1)= sum(S)- sum(D);
- s=sum(C);
- end
- end
- table =C;
- table= [table , S(:)];
- mD = [D, s];
- table= [table ; mD];
- var ={'D1','D2','D3', 'D4', 'Supply' };
- disp(array2table(table, 'VariableNames', var));
- X=C;
- Ci=C;
- while any(S~=0)|| any(D~=0)
- mini = min(C(:));
- [r, c]= find(C==mini);
- y = min(S(r), D(c));
- [alloc, ind]= max(y);
- rr= r(ind);
- cc= c(ind);
- X(rr, cc)= alloc;
- S(rr)= S(rr)- alloc;
- D(cc)= D(cc)-alloc;
- C(rr, cc)= inf;
- end
- table =X;
- table= [table , S(:)];
- mD = [D, s];
- table= [table ; mD];
- var ={'D1','D2','D3', 'D4', 'Supply' };
- disp(array2table(table, 'VariableNames', var));
- Cost = Ci.*X;
- [m, n]= size(X);
- if nnz(X)==m+n-1
- disp('Non-degenerate initial BFS');
- else
- disp('degenerate initial BFS');
- end
- final = sum(Cost(:));
- disp("Total Cost is ");
- disp(final);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement