Obsidian | Level 7

## Proc optmodel - convert non linear contraint to linear

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

## Re: Proc optmodel - convert non linear contraint to linear

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

## Re: Proc optmodel - convert non linear contraint to linear

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.

Obsidian | Level 7

## Re: Proc optmodel - convert non linear contraint to linear

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

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