BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
InfinityShu
Calcite | Level 5

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
IanWakeling
Barite | Level 11

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.

View solution in original post

2 REPLIES 2
IanWakeling
Barite | Level 11

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.

InfinityShu
Calcite | Level 5

Thank you so much!!!!! I got the right results after applying your suggestions! You are a lifesaver!!! 

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 436 views
  • 0 likes
  • 2 in conversation