<?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: Using two conditions for a Proc Optmodel constraint in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Using-two-conditions-for-a-Proc-Optmodel-constraint/m-p/834610#M3797</link>
    <description>&lt;P&gt;The final four constraint declarations have the effect of setting many variables to 0.&amp;nbsp; The presolver will remove these explicit constraints and the corresponding variables, but a much more efficient approach is to modify the index sets to avoid creating the variables in the first place.&amp;nbsp; Please see this documentation example:&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_030/casmopt/casmopt_optmodel_examples07.htm" target="_blank"&gt;SAS Help Center: Sparse Modeling&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Making similar changes in your code will reduce the memory needed to store the data and generate the problem, thereby freeing up more memory to be used by the solver.&amp;nbsp; Please let me know if this does not resolve your out-of-memory issue.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Sep 2022 02:18:01 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2022-09-22T02:18:01Z</dc:date>
    <item>
      <title>Using two conditions for a Proc Optmodel constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Using-two-conditions-for-a-Proc-Optmodel-constraint/m-p/834498#M3796</link>
      <description>&lt;P&gt;Hello All! I am using SAS Enterprise Guide. I have a optimization code where I have many constraints and decision variables. It is a facility location problem using multimodal (truck and rail) and I have created routes using location j and k. I have two constraints right now where I am putting conditions if j and k does not have rail access, it can not ship using rail. I tried to combine the two constraints (freight_depot and freight_bioref) into one but it only considered the first condition before the constraint and not the one I join using AND. Is there anyway I can use the AND operator to join two conditions before a constraint, so that I can make the two constraints into one. I don't have all my constraints here. Just put some of them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how I want to write them together-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Con freight {&amp;lt;j,k&amp;gt; in ROUTES2: (s[j]=0 and l[k] =0)}:&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;sum{&amp;lt;f,'1'&amp;gt; in tr} Amount2[j,k,f,'1'] = 0;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, my code is very memory intensive as it deals with inputs of 2000 rows and millions of constraints and decision variables. Is there any way I can solve the out of memory issue? Right now, after reaching an error gap of 8%, I am going out of memory.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for all of your help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;, any help from you would be greatly appreciated. Thank you again!&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel ;
	*****DECLARE SETS AND PARAMETERS*******;
	set &amp;lt;str&amp;gt; Fields;
	set &amp;lt;str&amp;gt; Depots init {};
	set &amp;lt;str&amp;gt; Bioref; 
	set &amp;lt;str&amp;gt; Feedstock;
	set &amp;lt;str&amp;gt; Price;
	set Mode = {'0', '1'};
	set &amp;lt;num&amp;gt; Capacity;
	set &amp;lt;str,str,str&amp;gt; TRIPLES;
    set DOUBLES = setof {&amp;lt;i,f,p&amp;gt; in TRIPLES} &amp;lt;i,f&amp;gt;;
	set &amp;lt;str,str,str&amp;gt; ROUTES;
	set &amp;lt;str,str&amp;gt; ROUTES2;
	set &amp;lt;str,str&amp;gt; ROUTES3;
	set &amp;lt;str,str&amp;gt; tr;

	*Parameters for fields;
	num sifp{Fields,Feedstock,Price} init 0; *Available biomass in field i of feedstock f at price p;
	num maif{Fields,Feedstock} init 0; *binary assignment of type f from field i;
	num gp {Price} init 0; *Farmgate price including grower payment and harvest and collection cost;
	num fsb {Feedstock}init 0; *field site storage in bales;
	num dmloss {Feedstock}init 0; *dry matter loss from bales;
	num aifp{i in Fields,f in Feedstock,p in Price} = round(sifp[i,f,p]*(1-dmloss[f])); *available biomass in the fields after considering the dry matter loss;

	*Transportation parameters;
	num x{Fields union Depots}; *union combines both field and depot;
	num y{Fields union Depots};
	num s{Depots};
	num l{Bioref};

	*Calculating distances between fields and depots;
	num a{i in Fields, j in Depots}= (sin((y[j]-y[i])*&amp;amp;C/2))**2+cos(y[i]*&amp;amp;C)*cos(y[j]*&amp;amp;C)*(sin((x[j]-x[i])*&amp;amp;C/2))**2;
	num sij{i in Fields, j in Depots} = ifn(x[i]=x[j] and y[i]=y[j],0,2*atan2(sqrt(a[i,j]),sqrt(1-a[i,j]))*3957.143);*converted the distance to miles;
	num dij{i in Fields, j in Depots} = round(sij[i,j],0.01);

    *Calculating distances between depots and biorefineries;
	num b{j in Depots, k in Bioref}= (sin((y[k]-y[j])*&amp;amp;C/2))**2+cos(y[j]*&amp;amp;C)*cos(y[k]*&amp;amp;C)*(sin((x[k]-x[j])*&amp;amp;C/2))**2;
	num sjk{j in Depots, k in Bioref} = ifn(x[j]=x[k] and y[j]=y[k],0,2*atan2(sqrt(b[j,k]),sqrt(1-b[j,k]))*3957.143);*converted the distance to miles;
	num djk{j in Depots, k in Bioref} = round(sjk[j,k],0.01);

	*Transportation costs;
	num vfb {Feedstock}; *variable cost of transporting bales of feedstock f;
	num cfb {Feedstock}; *fixed/constant cost of transporting bales of feedstock f;
    num vfp {Feedstock, Mode}; *variable cost of transporting pellets of feedstock f using mode t;
	num cfp {Feedstock, Mode}; *fixed/constant cost of transporting pellets of feedstock f using mode t;
	num tijf {i in Fields, j in Depots, f in Feedstock}= ifn (dij[i,j] = 0, 0, cfb[f] + vfb[f]*1.2*dij[i,j]); *Transportation cost for bales;
	num tjkf_pellets {j in Depots, k in Bioref, f in Feedstock, t in Mode}= ifn (djk[j,k] = 0, 0, cfp[f,t] + vfp[f,t]*1.2*djk[j,k]); *Transportation cost for pellets;

	*Parameters for Depots;
	num qh{Feedstock}init 0; *Handling and queuing of bales at depot: $1.21 for CS and $1.34 for SW;
	num pf{Feedstock}init 0; *preprocessing cost at depot: $22.65-3.18=$19.47 for CS and $22.05-3.18=$18.77 for SW;
	num ds{Feedstock}init 0; *depot storage in pellet form;
	num U = 0.9; *depot utilization factor;


	num max_distance1 = 200;
	num max_distance2 = 1300;
	num max_distance3 = 400;
	num min_distance = 300;

	*quality parameters;
	num Ash{Feedstock};
	num Moisture{Feedstock};
	num Carb{Feedstock};
	num Ash_dock{Feedstock};
	num Moist_dock{Feedstock};
	num Ash_diff{f in Feedstock} = ifn(&amp;amp;Max_Ash&amp;gt;=Ash[f],0, Ash[f] - &amp;amp;Max_Ash);
	num Moist_diff{f in Feedstock} = ifn(&amp;amp;Min_moisture&amp;lt;=Moisture[f],0, &amp;amp;Min_moisture-Moisture[f]);

	read data out.fields_&amp;amp;year into Fields = [fips] x y;
	read data out.INLdepots_&amp;amp;year into Depots = [fips] x y s=site;
    read data out.INLdepots_&amp;amp;year into Bioref = [fips] x y l=site;
	read data out.Price into Price = [name] gp = Pr ; *gp= grower payment;
	read data out.feedstockpropertiesbales_MS into Feedstock=[Feed] vfb=TranspCostVar cfb=TranspCostFixed fsb=StorageCost 
															qh=HandlingQueuingCost dmloss=BiomassLoss;
	read data out.feedstockpropertiespellets_MS into Feedstock=[Feed] ds=StorageCost pf=ProcessingCost;
	read data out.Supplymod_&amp;amp;year into TRIPLES=[fips Feed Price] sifp=Supply; *same as line commented below;
	read data out.Supplymin_&amp;amp;year into [fips Feed] maif=MinAssign; *minimum assignment (binary);
	read data out.quality_MS into Feedstock = [feed] Ash Moisture carb Ash_dock Moist_dock;
	read data out.transport into tr=[Feed Mode] vfp=TranspCostVar cfp=TranspCostFixed;


	ROUTES = {&amp;lt;i,f&amp;gt; in DOUBLES, j in DEPOTS: dij[i,j] &amp;lt; max_distance1};
    ROUTES2 = {j in DEPOTS, k in BIOREF:  djk[j,k] &amp;lt;max_distance2};


	*****DECLARE MODEL ELEMENTS*******;
	******DECISION VARIABLES*****;

	var Build {DEPOTS} binary; *binary value to build depots with specific capacity;
    var CapacityChunks {DEPOTS} &amp;gt;= 0; *integer value to determine depot capacity;
	var Build2 {Bioref} binary; *binary value to build biorefineries with fixed capacity of 725000 dry tons;
	var CapacityBioRef {Bioref} &amp;gt;= 0; *to determine biorefinery capacity;
	var AnyPurchased {TRIPLES} binary;
	var AmountPurchased {TRIPLES} &amp;gt;= 0;
	var AmountShipped {ROUTES} &amp;gt;= 0;
	var Amount2{ROUTES2,tr} &amp;gt;= 0;


    impvar BuildingCost {j in DEPOTS} =
      132717 * Build[j] + 2.297 * 25000 * CapacityChunks[j];

    impvar VariableCost = sum{&amp;lt;i,f,p&amp;gt; in TRIPLES} 0.977*gp[p] * AmountPurchased[i,f,p] + 
	  sum{&amp;lt;i,f,j&amp;gt; in ROUTES} (fsb[f]+ tijf[i,j,f]+ qh[f]+ ds[f]+ pf[f]) * AmountShipped[i,f,j] 
        + sum{&amp;lt;j,k&amp;gt; in ROUTES2, &amp;lt;f,t&amp;gt; in tr} 
          (tjkf_pellets[j,k,f,t]+(Ash_dock[f]*Ash_diff[f]) 
              + (Moist_dock[f]*Moist_diff[f])) * Amount2[j,k,f,t];

    impvar FixedCost = sum {j in Depots} BuildingCost[j];

	*****OBJECTIVE FUNCTION******;

	max Supply = sum{&amp;lt;j,k&amp;gt; in ROUTES2,&amp;lt;f,t&amp;gt; in tr} Amount2[j,k,f,t];

	*****CONSTRAINTS******;

	*Flow balance between field-depot and depot-biorefinery;
	Con Depot_avail {j in Depots,f in Feedstock}:
		sum {&amp;lt;i,(f),(j)&amp;gt; in ROUTES} AmountShipped[i,f,j]  
           = sum{&amp;lt;(j),k&amp;gt; in ROUTES2, &amp;lt;(f),t&amp;gt; in tr} Amount2[j,k,f,t];

	*Depot locations which have do not freight access;
	Con freight_depot {j in Depots: s[j]=0}:
		sum{&amp;lt;f,'1'&amp;gt; in tr} Amount2[j,k,f,'1'] = 0;

	*Biorefinery Locations which have do not freight access;
	Con freight_bioref {k in Bioref: l[k]=0}:
		sum{&amp;lt;j,(k)&amp;gt; in ROUTES2,&amp;lt;f,'1'&amp;gt; in tr} Amount2[j,k,f,'1'] = 0;

	Con rail_minimum {&amp;lt;j,k&amp;gt; in ROUTES2: djk[j,k]&amp;lt;= min_distance}:
		sum{&amp;lt;f,'1'&amp;gt; in tr} Amount2[j,k,f,'1'] = 0;
/**/
	Con truck_maximum {&amp;lt;j,k&amp;gt; in ROUTES2: djk[j,k] &amp;gt; max_distance3 }:
		sum{&amp;lt;f,'0'&amp;gt; in tr} Amount2[j,k,f,'0'] = 0;

  

	*****SOLVE*******;
	solve obj Supply with milp / maxtime=&amp;amp;MaxRunTime relobjgap=0.03; * To force the code to stop after maxtime;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 14:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Using-two-conditions-for-a-Proc-Optmodel-constraint/m-p/834498#M3796</guid>
      <dc:creator>thossain</dc:creator>
      <dc:date>2022-09-21T14:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using two conditions for a Proc Optmodel constraint</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Using-two-conditions-for-a-Proc-Optmodel-constraint/m-p/834610#M3797</link>
      <description>&lt;P&gt;The final four constraint declarations have the effect of setting many variables to 0.&amp;nbsp; The presolver will remove these explicit constraints and the corresponding variables, but a much more efficient approach is to modify the index sets to avoid creating the variables in the first place.&amp;nbsp; Please see this documentation example:&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_030/casmopt/casmopt_optmodel_examples07.htm" target="_blank"&gt;SAS Help Center: Sparse Modeling&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Making similar changes in your code will reduce the memory needed to store the data and generate the problem, thereby freeing up more memory to be used by the solver.&amp;nbsp; Please let me know if this does not resolve your out-of-memory issue.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 02:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Using-two-conditions-for-a-Proc-Optmodel-constraint/m-p/834610#M3797</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2022-09-22T02:18:01Z</dc:date>
    </item>
  </channel>
</rss>

