## Operation Research with IML

Started ‎02-08-2017 by
Modified ‎02-09-2017 by
Views 2,536

Rick Wicklin's blog has encouraged me to solve via IML problems that appear in the book "Schaum's Outline of Operations Research".
I would like to share the problem expressed in the book and the IML approach I chose to solve it.

The attached images describe the problem and its solution following the logic and the recipe of the book. Furthermore they serve as a verifier for the solution I get running the IML code.

And here comes the code:

``````proc iml;
/* information about the variables */
LowerB = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};           /* lower bound constraints on x */
UpperB = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};           /* upper bound constraints on x */

/* define the objective function */
c = {65, 73, 63, 57,
67, 70, 65, 58,
68, 72, 69, 55,
67, 75, 70, 59,
71, 69, 75, 57,
69, 71, 66, 59} ;                /* vector for objective function c*x */
/* control vector for optimization */
ctrl = {1,                /* maximize objective */
1};               /* print some details */

/* specify linear constraints */
A = {1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,                 /* matrix of constraint coefficients */
0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,
0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0,
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0,
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0,
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1,
1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0,
0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0,
0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0,
0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1};
b = {  1,                   /* RHS of constraint eqns (column vector) */
1,
1,
1,
1,
1,
1,
1,
1,
1};
LEG = {L, L, L, L, L, L, G, G, G, G};           /* specify symbols for constraints:
'L' for less than or equal
'E' for equal
'G' for greater than or equal */

/* solve the LP problem */
CALL LPSOLVE(rc, objVal, result, dual, reducost, /* output variables */
c, A, b,      /* objective and linear constraints */
ctrl,         /* control vector */
LEG, /*range*/ , LowerB, UpperB);
print rc objVal, result[rowname={x11 x12 X13 X14 x21 x22 X23 X24 x31 x32 X33 X34 x41 x42 X43 X44 x51 x52 X53 X54 x61 x62 X63 X64}];``````

And it works giving me one of the optimal solutions.

I have managed to solve some other problems of the book with IML.

But I need some help figuring out how to blend the Travelling Salesman Problem with the networking optimisation described on page

http://support.sas.com/documentation/cdl/en/imlug/66845/HTML/default/viewer.htm#imlug_genstatexpls_s...

Use case is the best route, minimizing the travelled miles, that a bakery business should define taking into consideration the supply and shortage of bread in their network of bakery shops. The factory has all the output that needs to be distributed to their network depending on the demand and stock at each shop.

Help would be very welcome. On reply I'll share the code I've tried so far.

Bye, Arne

Great. Thanks for posting. I think @Ksharp would be interested in this.

If I might offer a small suggestion, you have several constant vectors that you typed explicitly. You can use the J function or the REPEAT function to simplify the construction of a constant vector.  For example:

``````LowerB = j(24, 1, 0); /* lower bound constraints on x */
UpperB = j(24, 1, 1); /* upper bound constraints on x */
...
b = j(nrow(A), 1, 1); /* RHS of constraint eqns (column vector) */``````

I was curious as to whether I could generate the RONAMES= vector automatically, without typing the numbers.  It turns out you can use the ROWCATC function to concatenate character matrices, and you can generate the sequence of numbers by using the EXPANDGRID function, like this:

``````rownames = "X" + strip(rowcatc(char( expandgrid(1:6, 1:4) )));
print rownames;``````
```If your OR problems were simple, you can use two functions in IML to solve it, like linear, integral programming.
Otherwise, you need the help of GA code. GA almost suited for any OR problem.
I suggest you to learn SAS/OR which can guarantee give you a solution for all the solvable OR problem.
```
Version history
Last update:
‎02-09-2017 08:58 AM
Updated by:
Contributors
Article Labels
Article Tags