Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- SAS Communities Library
- /
- Operation Research with IML

Options

- RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content

- Article History
- RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content

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.

Start reading at **1.13**

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

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

Comments

02-10-2017
01:16 PM

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content

02-10-2017
01:16 PM

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;
```

02-12-2017
05:55 AM

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content

02-12-2017
05:55 AM

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. **

Data Literacy is for **all**, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.

Article Labels

Article Tags