The code works perfectly for the first time:
Proc IML ;
*Define the routes between the nodes;
arcs = { 'AB' 'AC' 'AE' 'BC' 'BD' 'CE' 'CH' 'DE' 'DF' 'EF' 'EH' 'GF' 'GH' }; /* decision variables */
nodes = {'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H'};
*Input the constraint matrix;
A={ 1 1 -1 0 0 0 0 0 0 0 0 0 0,
-1 0 0 1 1 0 0 0 0 0 0 0 0,
0 -1 0 1 0 -1 1 0 0 0 0 0 0,
0 0 0 0 -1 0 0 1 1 0 0 0 0,
0 0 1 0 0 1 0 0 0 1 -1 0 0,
0 0 0 0 0 0 0 0 1 -1 0 1 0,
0 0 0 0 0 0 0 0 0 0 0 -1 1,
0 0 0 0 0 0 -1 0 0 0 1 0 1};
end;
print 'The constraint matrix of the direction of flows' ;
print A[r=nodes c=arcs l={'The Network Constraint Matrix'}] ;
COST = {28.259407 41.255207 67.664184 39.863161 34.92524 35.860331 41.266789 27.098869 36.723808 23.638669 29.807257 24.900754 42.253725 };
print cost [c=arcs l={'The cost/distance for each internode route'}] ;
*The supply and demand at each node;
supply = { 0 -2 12 -2 -2 0 -3 -3 };
print supply[c=nodes l={'Supply and Demand at each node'}] ;
*Force all demand and supply to even out by making all constraints equalities
operators: 'L' for <=, 'G' for >=, 'E' for =;
ops = j(8,1,'E') ;
cntl = j(1,13,.); /* control vector */
cntl[1] = 1; /* 1 for minimum; -1 for maximum */
call lpsolve(rc, value, x, dual, redcost,cost, A, supply, cntl, ops);
print value[L='Minimum Cost'];
print x[r=arcs L='Optimal Flow'];
quit;
run;
After I exchange the demand and supply, it doesn't work, which in specific, I change this line of code:
supply = { 0 2 -12 2 2 0 3 3 };
Based on the graph in description, the transportation can surely work both forward and backwards. I'm not sure whether I have made the correct modifications.