clear all
echo on
%set product := WM, WB, PM; 
%set resource := steel, molding, assembly, wrench_demd, plier_demd;
%
%param profit :=
profit=[
130                  %WM
100                  %PM
10                   %WB
];
f=-profit;
profit=[profit; zeros(5,1)];    % add slack obj coefficients

usage=[
1.5	1	0             % steel
1	1	0             % molding
0.3	0.5	0             % assembly
1	0	1             % wrench_demand
0	1	0 ];          % plier_demand
A=usage;
usage=[usage eye(5)];
m=5;n=8;
N=1:8;

avail =[ 
27 
21 
9
15
9];
b=avail;
[x,fval,exitf,output,lambda]=linprog(f,A,b,[],[],zeros(3,1),[])
B=[1:3 5 6];  N=setdiff(N,B);
A_B=usage(:,B);    % opt. basic columns
A_N=usage(:,N);    % opt. nonbasic columns
disp(' ')
x_B=A_B\avail      % opt. basic variables
xopt=zeros(n,1);
xopt(B)=x_B;
y=(profit(B)'/A_B)'         % shadow prices 
Ab=[usage avail];      % original [A b]
Abbar=A_B\Ab                 % current [A b]
cbar=profit-usage'*y         %  neg dual feasibility (pricing out/red. costs)
disp('checking costs ranges (basis)')
for i=1:length(B),
	echo off
	disp(' ')
	disp(['basic variable B(i)  ', num2str(B(i))])
	[cbar(N)'; (Abbar(i,N)) ; cbar(N)'./ (Abbar(i,N)) ]
end
echo off
