Turn on suggestions

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

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 05-30-2018 12:38 PM
(1369 views)

Hi,

I have 2 data sets with location data as below.

DS1

Ofc name, Easting, Northing

DS2

Emp name,Easting, Northing

The code I have written is as follows.

proc optmodel;

set two = 1..2;

set<string> ofc;

set<string> pm;

num ofc_loc{ofc,two};

num pm_loc{pm,two};

var ofc_use{ofc} binery; /* office used */

var dec_var{pm,ofc} binery; /* decision variable */

read data DS1 into ofc=[office_name] ofc_loc[office_name,1]=easting ofc_loc[office_name,2]=northing;

read data DS2 into pm=[pm_nm] pm_loc[pm_nm,1]=eastings pm_loc[pm_nm,2]=northings;

constraint con1{p in pm}: sum{o in ofc} dec_var[p,o]=1; /* 1 office per pm */

constraint con2: sum{p in pm,o in ofc} ofc_use[o]*dec_var[p,o]=20; /* 20 ofc to use */

/*constraint con4{p in pm,o in ofc}: 0<=dec_var[p,o]<=1;*/ /* want the decision variables to be binary */

/*constraint con5{o in ofc}: 0<=ofc_use[o]<=1;*/ /* need con4 and con5 if variables are declared as integer */

min dismin = sum{p in pm,o in ofc} dec_var[p,o]*(((pm_loc[p,1]-ofc_loc[o,1])**2+(pm_loc[p,2]-ofc_loc[o,2])**2)**(0.5)); /* minimise distance */

solve;

quit;

The con2 above is becoming non linear. Due to that, the variables need to be number and not integer and also con4 and con5 are required. Ultimately the solver is unable to solve the problem and cannot find a solution. Is it possible to convert this into a linear programming problem?

Any help will be greatly appreciated.

Thanks

Arindam

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Note that the option name in the VAR statement should be BINARY, not BINERY.

To linearize con2, replace with this linear constraint:

` constraint con2: sum{p in pm,o in ofc} ofc_use[o]=20; /* 20 ofc to use */`

And then link the two sets of binary variables as follows:

```
/* if dec_var[p,o] = 1 then ofc_use[o] = 1 */
con con2a {p in pm, o in ofc}: dec_var[p,o] <= ofc_use[o];
/* if ofc_use[o] = 1 then dec_var[p,o] = 1 for some p */
con con2b {o in ofc}: ofc_use[o] <= sum {p in pm} dec_var[p,o];
```

With these changes, the SOLVE statement will invoke the MILP solver by default.

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Note that the option name in the VAR statement should be BINARY, not BINERY.

To linearize con2, replace with this linear constraint:

` constraint con2: sum{p in pm,o in ofc} ofc_use[o]=20; /* 20 ofc to use */`

And then link the two sets of binary variables as follows:

```
/* if dec_var[p,o] = 1 then ofc_use[o] = 1 */
con con2a {p in pm, o in ofc}: dec_var[p,o] <= ofc_use[o];
/* if ofc_use[o] = 1 then dec_var[p,o] = 1 for some p */
con con2b {o in ofc}: ofc_use[o] <= sum {p in pm} dec_var[p,o];
```

With these changes, the SOLVE statement will invoke the MILP solver by default.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks Rob. That was quick and accurate. Excellent. Thanks!

**SAS Innovate 2025** is scheduled for May 6-9 in Orlando, FL. Sign up to be **first to learn** about the agenda and registration!

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.