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.
This is not my area of expertise, but I am guessing that you also need to reverse the direction of flow by multiplying the matrix A by -1. The "end;" statement in your code should also be removed as this is generating an error.
This is not my area of expertise, but I am guessing that you also need to reverse the direction of flow by multiplying the matrix A by -1. The "end;" statement in your code should also be removed as this is generating an error.
Thank you so much!!!!! I got the right results after applying your suggestions! You are a lifesaver!!!
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.