<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error: Ran out of memory in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/630157#M3000</link>
    <description>&lt;P&gt;Two additional suggestions:&lt;/P&gt;
&lt;P&gt;1. Consider heuristically reducing the allowed field-to-depot assignments based on a distance threshold.&amp;nbsp; &lt;A href="https://go.documentation.sas.com/?docsetId=ormpug&amp;amp;docsetTarget=ormpug_optmodel_examples07.htm&amp;amp;docsetVersion=15.1&amp;amp;locale=en" target="_self"&gt;This documentation example&lt;/A&gt; shows how to do that efficiently, by omitting variables from the formulation.&lt;/P&gt;
&lt;P&gt;2. Use a Benders decomposition approach, as shown in &lt;A href="https://communities.sas.com/t5/Mathematical-Optimization/How-much-memory-is-needed-Or-how-to-reduce-memory-requirements/m-p/309150/highlight/true#M1493" target="_self"&gt;this SAS Communities thread&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 06 Mar 2020 16:53:45 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2020-03-06T16:53:45Z</dc:date>
    <item>
      <title>Error: Ran out of memory</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/629895#M2977</link>
      <description>&lt;P&gt;Hello Everyone! I am trying to run my code to solve an MILP with optmodel procedure. I am using SAS enterprise Guide 7.1. I was trying to locate optimal number of Depots for storing supplies from fields. My two location sets for Depot and Field are the same, using the county centroids. When I used one state (North Carolina) which has 100 counties, the code ran fine and gave me results. But just when I increased the number of states, my log showed me the error of "Ran out of memory". I am attaching my code here and also attaching the log. What can I do to resolve this issue? Thank you in advance!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*creating macro variables*/

%let NumFields  = 50;
%let NumDepots      = 10;
%let DepotCapacity  = 25000;
%let MaxDemand     = 1000;
%let xmax          = 200;
%let ymax          = 100;
%let seed          = 423;



data fdata(Rename=(County=name));
	set UScounties;

	if state in ("North Carolina", "South Carolina", "Virgina") then
		do;
			x=Long;
			demand=rand('UNIFORM') * &amp;amp;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", "Virgina") then
		do;
			x=Long;
			y=Lat;
			fixed_cost=275000;
			output;
			keep county x y fixed_cost;
		end;
run;


/*Solving the MILP*/
proc optmodel;
	set &amp;lt;str&amp;gt; Fields;

	/*declares set of fields*/
	set &amp;lt;str&amp;gt; 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] &amp;lt;=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]&amp;lt;=&amp;amp;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;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Mar 2020 18:02:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/629895#M2977</guid>
      <dc:creator>thossain</dc:creator>
      <dc:date>2020-03-05T18:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Ran out of memory</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/629909#M2978</link>
      <description>&lt;P&gt;Can you please attach the UScounties data set or provide code to generate it?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 18:29:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/629909#M2978</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2020-03-05T18:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Ran out of memory</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/629931#M2987</link>
      <description>&lt;P&gt;Thank you so much for your reply. Although I am using the county names now as [name] but later I will use the unique FIPS code as there are duplicate county names within the US. I am attaching the US Counites dataset here.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 19:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/629931#M2987</guid>
      <dc:creator>thossain</dc:creator>
      <dc:date>2020-03-05T19:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Ran out of memory</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/629990#M2996</link>
      <description>&lt;P&gt;One suggestion is to omit the Build_depot constraints, which are not strictly necessary.&amp;nbsp; They tighten the formulation but also make it bigger, requiring more memory.&amp;nbsp; The logical implication "if Assign[i,j] = 1 then Build[j]" is already enforced via the Depot_capacity constraints.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might also try increasing the MEMSIZE option value, as described &lt;A href="https://go.documentation.sas.com/?docsetId=ormpug&amp;amp;docsetTarget=ormpug_concepts_sect002.htm&amp;amp;docsetVersion=15.1&amp;amp;locale=en" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note also that Virgina should instead be Virginia.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Mar 2020 02:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/629990#M2996</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2020-03-06T02:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Ran out of memory</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/630157#M3000</link>
      <description>&lt;P&gt;Two additional suggestions:&lt;/P&gt;
&lt;P&gt;1. Consider heuristically reducing the allowed field-to-depot assignments based on a distance threshold.&amp;nbsp; &lt;A href="https://go.documentation.sas.com/?docsetId=ormpug&amp;amp;docsetTarget=ormpug_optmodel_examples07.htm&amp;amp;docsetVersion=15.1&amp;amp;locale=en" target="_self"&gt;This documentation example&lt;/A&gt; shows how to do that efficiently, by omitting variables from the formulation.&lt;/P&gt;
&lt;P&gt;2. Use a Benders decomposition approach, as shown in &lt;A href="https://communities.sas.com/t5/Mathematical-Optimization/How-much-memory-is-needed-Or-how-to-reduce-memory-requirements/m-p/309150/highlight/true#M1493" target="_self"&gt;this SAS Communities thread&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Mar 2020 16:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/630157#M3000</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2020-03-06T16:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Error: Ran out of memory</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/632490#M3059</link>
      <description>&lt;P&gt;Thank you so much for all your great suggestions!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 16:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Error-Ran-out-of-memory/m-p/632490#M3059</guid>
      <dc:creator>thossain</dc:creator>
      <dc:date>2020-03-16T16:43:19Z</dc:date>
    </item>
  </channel>
</rss>

