function [minTcost,b,c]=vogel(A,sup,dem)
%input:transportationcostA,vectorsupply
%sup,vectordemanddem
%output:minimumtransportationcostminTcost,
%basicmatrixb,costmatrixc,
b=zeros(size(A));
ctemp=A;
[m,n]=size(A);
c=zeros(m,n);
while length(find(dem==0))<length(dem)|| length(find(sup==0))<length(sup)
prow=sort(ctemp,1);
prow=prow(2,:)-prow(1,:);%rowpenalty
pcol=sort(ctemp,2);
pcol=pcol(:,2)-pcol(:,1);%columnpenalty
[rmax,rind]=max(prow);
[cmax,cind]=max(pcol);
disp('columnpenalty')
disp(prow);
disp('rowpenalty');
disp(pcol);
%valueforallocatedcell
if rmax>cmax
[~,mind]=min(ctemp(:,rind));
[amt,dem,sup,ctemp]=
chkdemandsupply(dem,sup,rind,mind,ctemp);
x=sprintf('x(%d,%d)=%d',mind,rind,amt);
disp(x);
b(mind,rind)=1;
c(mind,rind)=amt;
disp(c);
end
if cmax>=rmax
[~,mind]=min(ctemp(cind,:));
[amt,dem,sup,ctemp]=chkdemandsupply(dem,sup,mind,cind,ctemp);
x=sprintf('x(%d,%d)=%d',cind,mind,amt);
disp(x);
b(cind,mind)=1;
c(cind,mind)=amt;
disp(c);
minTcost=sum(sum(c.*A));
end
end
function [y,dem,sup,ctemp]=chkdemandsupply(dem,sup,ded,sud,ctem)
tempd=dem;
temps=sup;
if tempd(ded)>temps(sud)
temps(sud)=0;
tempd(ded)=dem(ded)-sup(sud);
disp('sup');
disp(temps);
disp('dem');
disp(tempd);
y=sup(sud);
ctem(sud,:)=inf;
end
if tempd(ded)<temps(sud)
tempd(ded)=0;
temps(sud)=sup(sud)-dem(ded);
disp('sup');
disp(temps);
disp('dem');
disp(tempd);
y=dem(ded);
ctem(:,ded)=inf;
end
if tempd(ded)==temps(sud)
tempd(ded)=0;
temps(sud)=0;
disp('sup');
disp(temps);
disp('dem');
disp(tempd);
y=dem(ded);
ctem(:,ded)=inf;
ctem(sud,:)=inf;
end
dem=tempd;
sup=temps;
ctemp=ctem;

 

 

Example

Solve the following transportation problem by Vogel’s Approximation Method in MATLAB.

In the Command Window,
>> A=[6 2 4 3 ; 3 8 5 7 ; 5 7 8 2 ]
>> sup=[500; 200; 400]
>> dem=[200 350 120 430]
>> [ minTcost ] = vogel (A, sup , dem)
0 350 120 30
200 0 0 0
0 0 0 400

minTcost =
2670