BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
arindam1984
Obsidian | Level 7

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
RobPratt
SAS Super FREQ

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.

View solution in original post

2 REPLIES 2
RobPratt
SAS Super FREQ

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.

arindam1984
Obsidian | Level 7

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Discussion stats
  • 2 replies
  • 1059 views
  • 1 like
  • 2 in conversation