Thanks for the help Rob. With the attempt to minimize number of builds based on both minimizing drivetimes and the known locations to build I came up with this. If this looks off to you let me know but it appears to work with the following data as expected (sites 1, 2, and 3 are built with the only customer assiged to site 3 being C11). proc optmodel;
set <str, str> SITEStoDEVICES;
num DriveTime {SITEStoDEVICES};
read data DTMS into SITEStoDEVICES = [destination origin] DriveTime;
set CUSTOMERS = setof {<i,j> in SITEStoDEVICES} i;
/*set SITES = setof {<i,j> in SITEStoDEVICES} j;*/
/*assignment variable*/
var V {SITEStoDEVICES} binary;
set <str> SITES;
num REQ_LOC_BY_MGMT_NUM {SITES};
read data SiteData into SITES = [site] REQ_LOC_BY_MGMT_NUM;
/* build variable*/
var Build {SITES} binary;
/* objective functions */
/* min TotalCost = sum {<i,j> in SITEStoDEVICES} DriveTime[i,j] * V[i,j];*/
/* min totalbuilds = sum {<deviceSiteId, techSiteId> in SITEStoDEVICES} Build[techSiteId];*/
min cost = sum {i in CUSTOMERS, j in SITES} V[i,j] * DriveTime[i,j];
min totalcost = cost + sum{j in SITES} Build[j];
/*min totalbuilds = sum {<deviceSiteId, techSiteId> in SITEStoDEVICES} Build[techSiteId]*DriveTime[deviceSiteId, techSiteId];*/
/*device assigned to only one site and every device is assigned*/
con Balance {i in CUSTOMERS}:
sum {<(i),j> in SITEStoDEVICES} V[i,j] = 1;
/* must build sites */
con mustbuild {techSiteId in SITES: REQ_LOC_BY_MGMT_NUM[techSiteId] = 1}:
Build[techSiteId] = 1;
/* must build sites with assigned locations */
con link {deviceSiteId in CUSTOMERS, techSiteId in SITES}:
V[deviceSiteId,techSiteId] <= Build[techSiteId];
/* do not assign customer to site more than x units away */
con distance_at_most {i in CUSTOMERS, j in SITES: DriveTime[i,j] > 1.99}:
V[i,j] = 0;
/* solve;*/
solve with milp/timetype=real;
create data outdata from [i j] DriveTime V Build[j] REQ_LOC_BY_MGMT_NUM[j];
run; data SiteData;
input site $ REQ_LOC_BY_MGMT_NUM;
datalines;
S1 0
S2 0
S3 1
S4 0
; data DTMS;
input destination : $11.
origin : $11.
REQ_LOC_BY_MGMT_NUM : best8.
DriveTime ;
datalines;
C1 S1 0 .15
C2 S1 0 .10
C3 S1 0 .11
C4 S1 0 .12
C5 S1 0 .13
C6 S1 0 2.15
C7 S1 0 2.10
C8 S1 0 2.11
C9 S1 0 2.12
C10 S1 0 2.13
C11 S1 0 1.99
C1 S2 0 2.75
C2 S2 0 2.70
C3 S2 0 2.71
C4 S2 0 2.72
C5 S2 0 2.73
C6 S2 0 .15
C7 S2 0 .10
C8 S2 0 .11
C9 S2 0 .12
C10 S2 0 .13
C11 S2 0 2.99
C1 S3 1 7.15
C2 S3 1 7.10
C3 S3 1 7.11
C4 S3 1 7.12
C5 S3 1 7.13
C6 S3 1 6.15
C7 S3 1 6.10
C8 S3 1 6.11
C9 S3 1 6.12
C10 S3 1 6.13
C11 S3 1 1.05
C1 S4 0 0.15
C2 S4 0 0.10
C3 S4 0 0.11
C4 S4 0 0.12
C5 S4 0 7.13
C6 S4 0 0.15
C7 S4 0 0.10
C8 S4 0 0.11
C9 S4 0 7.12
C10 S4 0 7.13
C11 S4 0 8.79
;
... View more