Hello All!
I am using SAS Enterprise Guide 7.1. I am trying to run the code below for solving an MILP to identify optimal number of Depots to store supply from all the fields. When I used 1 state with 100 counties, it gave me a solution. I am using same set of counties for Depot and Field location. But just as I increased the state number to 2 or 3, my log displayed me "ERROR: Out of memory." Eventually, I will need to run the code for all states which includes 3109 counties. I am also attaching my log. Please kindly help me on how to resolve this issue. Thank you in advance!
data fdata(Rename=(County=name));
set UScounties;
if state in ("North Carolina", "South Carolina", "Virginia") then
do;
x=Long;
demand=rand('UNIFORM') * &MaxDemand;
Y=Lat;
output fdata;
keep county x demand y;
end;
run;
data pdata(Rename=(county=name));
set UScounties;
if state in ("North Carolina", "South Carolina", "Virginia") then
do;
x=Long;
y=Lat;
fixed_cost=275000;
output;
keep county x y fixed_cost;
end;
run;
/*Solving the MILP*/
proc optmodel;
set <str> Fields;
/*declares set of fields*/
set <str> Depots init {};
/*declares set of depots*/
num x{Fields union Depots};
/*creating an array of x cooordinate with all the field and depot location, union combines both field and depot*/
num y{Fields union Depots};
/*creating an array of y cooordinate with all the field and depot location*/
num demand{Fields};
num fixed_cost{Depots};
num distance {i in Fields, j in Depots}=sqrt((x[i] - x[j])^2 + (y[i]
- y[j])^2);
/* linear distance between fields and depots*/
read data fdata into Fields=[name] x y demand;
read data pdata into Depots=[name] x y fixed_cost;
var Assign {Fields, Depots} binary;
/* binary value to assign specific fields to specific depots*/
var Build {Depots} binary;
/*objective function*/
/* binary variable to determine which depots will be established*/
min cost=sum{i in Fields, j in Depots} Distance[i, j]*Assign[i, j] + sum{j in
Depots}Fixed_cost[j]*Build[j];
/*Constraints*/
con Assign_fields{i in Fields}: sum{j in Depots}Assign[i, j]=1;
/*each field assigned to one depot only*/
con Build_depot{i in Fields, j in Depots}: Assign[i, j] <=Build[j];
/* if a field is assigned to a depot, it has to be build*/
con Depot_capacity{j in Depots}: sum {i in Fields}Demand[i]*Assign[i,
j]<=&DepotCapacity*Build[j];
/*ensuring total field supply to a depot is within its capacity*/
solve obj Cost with MILP/primalin;
num varcost=sum {i in FIELDS, j in DEPOTS} distance[i, j] * Assign[i, j].sol;
num fixcost=sum {j in DEPOTS} fixed_cost[j] * Build[j].sol;
for {s in 1.._NSOL_} do;
/*clean up the solution*/
for {i in FIELDS, j in DEPOTS} Assign[i, j]=round(Assign[i, j].sol[s]);
for {j in DEPOTS} Build[j]=round(Build[j].sol[s]);
call symput('varcost', put(varcost, 6.1));
call symput('fixcost', put(fixcost, 5.1));
call symput('totalcost', put(Cost, 6.1));
/*create a data set for use by PROC SGPLOT*/
create data CostFixedCharge_Data from
[FIELD DEPOT]={i in FIELDS, j in DEPOTS: Assign[i, j]=1}
x1=x[i] y1=y[i] x2=x[j] y2=y[j] function='line' drawspace='datavalue'
linethickness=1 linecolor='black';
submit s;
endsubmit;
end;
quit;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.