<?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: PROC OPTMODEL LOOPING OBJECT FUNCTION - HELP PLS in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-LOOPING-OBJECT-FUNCTION-HELP-PLS/m-p/456726#M2235</link>
    <description>&lt;P&gt;If you want to solve a separate problem for each i in box, you can do the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc optmodel;
   set &amp;lt;str&amp;gt; box;
   var Q &amp;gt;= 0;
   number   c1{box};
   number    D{box};
   number cap1{box};
   number   r1{box};
   number   r2{box};
   number   o1{box};
   number    f{box};
   number   o2{box};
   number   c2{box};
   number   p1{box};
   number   p2{box};
   number cap2{box};
   number life{box};
   number    w{box};

   read data indata into box=[type] c1 D cap1 r1 r2 o1 f o2 c2 p1 p2 cap2 life w;
   print c1 D cap1 r1 r2 o1 f o2 c2 p1 p2 cap2 life w;

   str i_this;
   minimize Z = ((Q/2)*((c1[i_this]*r1[i_this])+(c2[i_this]*r2[i_this]*f[i_this])))
   +(D[i_this]/Q)*(((o1[i_this]*p1[i_this]) + (o2[i_this]*p2[i_this]*f[i_this]))*300 + (w[i_this]*c1[i_this]));

   con MinShelfLife:(life[i_this]-((360)/(D[i_this]/Q))) &amp;gt;= 120;
   con MaxShiftSize1: Q/cap1[i_this] &amp;lt;= 2;
   con MaxShiftSize2: Q/(f[i_this]*cap2[i_this]) &amp;lt;= 2;

   num Qsol {box};
   num Zsol {box};
   for {i in box} do;
      i_this = i;
      solve;
      print Q Z;
      Qsol[i] = Q;
      Zsol[i] = Z;
   end;
   print Qsol Zsol;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I removed the MinBatch constraint, which is redundant because of the &amp;gt;= 0 in the VAR statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, you can also solve these independent problems&amp;nbsp;concurrently by changing FOR to COFOR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a similar example, see &lt;A href="http://go.documentation.sas.com/?docsetId=ormpex&amp;amp;docsetTarget=ormpex_ex22_toc.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_self"&gt;Efficiency Analysis: How to Use Data Envelopment Analysis to Compare Efficiencies of Garages&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Apr 2018 23:51:09 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2018-04-23T23:51:09Z</dc:date>
    <item>
      <title>PROC OPTMODEL LOOPING OBJECT FUNCTION - HELP PLS</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-LOOPING-OBJECT-FUNCTION-HELP-PLS/m-p/456686#M2234</link>
      <description>&lt;P&gt;Hello. I'm really new to SAS Studio programming and I have a question about my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset consisting of numbers regarding different products. I have in total 31 products with different values of the numbers stated in [box] (c1, D, cap1) etc. The thing is that I want to loop the minimalization object function Z for all 31 products so that they don't affect each other's values of the variable Q and Z.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which it seems like they do now since I'm not doing a loop for one product at the time. But I just can't figure out how I'm going to do it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class="language-sas"&gt;proc import out=indata 
 DATAFILE='/home/phjesper0/Master/Minresultater1.xlsx'
 DBMS=XLSX replace;
 GETNAMES=YES;
 /*USEDATE=YES;*/

title 'Vanlige tall';
proc print data=indata;
run;

Proc optmodel;
   set &amp;lt;str&amp;gt; box;
   var Q{box} &amp;gt;=0;
   number   c1{box};
   number    D{box};
   number cap1{box};
   number   r1{box};
   number   r2{box};
   number   o1{box};
   number    f{box};
   number   o2{box};
   number   c2{box};
   number   p1{box};
   number   p2{box};
   number cap2{box};
   number life{box};
   number    w{box};

read data indata into box=[type] c1 D cap1 r1 r2 o1 f o2 c2 p1 p2 cap2 life w;
   print c1 D cap1 r1 r2 o1 f o2 c2 p1 p2 cap2 life w;

minimize Z = sum {i in box} (((Q[i]/2)*((c1[i]*r1[i])+(c2[i]*r2[i]*f[i])))
+(D[i]/Q[i])*(((o1[i]*p1[i]) + (o2[i]*p2[i]*f[i]))*300 + (w[i]*c1[i])));

con MinShelfLife{i in box}:(life[i]-((360)/(D[i]/Q[i]))) &amp;gt;= 120;
con MaxShiftSize1{i in box}: Q[i]/cap1[i] &amp;lt;= 2;
con MaxShiftSize2{i in box}: Q[i]/(f[i]*cap2[i]) &amp;lt;= 2;
con MinBatch{i in box}: Q[i] &amp;gt;= 0;
solve;
print Z Q;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 20:28:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-LOOPING-OBJECT-FUNCTION-HELP-PLS/m-p/456686#M2234</guid>
      <dc:creator>jesperph</dc:creator>
      <dc:date>2018-04-23T20:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: PROC OPTMODEL LOOPING OBJECT FUNCTION - HELP PLS</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-LOOPING-OBJECT-FUNCTION-HELP-PLS/m-p/456726#M2235</link>
      <description>&lt;P&gt;If you want to solve a separate problem for each i in box, you can do the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc optmodel;
   set &amp;lt;str&amp;gt; box;
   var Q &amp;gt;= 0;
   number   c1{box};
   number    D{box};
   number cap1{box};
   number   r1{box};
   number   r2{box};
   number   o1{box};
   number    f{box};
   number   o2{box};
   number   c2{box};
   number   p1{box};
   number   p2{box};
   number cap2{box};
   number life{box};
   number    w{box};

   read data indata into box=[type] c1 D cap1 r1 r2 o1 f o2 c2 p1 p2 cap2 life w;
   print c1 D cap1 r1 r2 o1 f o2 c2 p1 p2 cap2 life w;

   str i_this;
   minimize Z = ((Q/2)*((c1[i_this]*r1[i_this])+(c2[i_this]*r2[i_this]*f[i_this])))
   +(D[i_this]/Q)*(((o1[i_this]*p1[i_this]) + (o2[i_this]*p2[i_this]*f[i_this]))*300 + (w[i_this]*c1[i_this]));

   con MinShelfLife:(life[i_this]-((360)/(D[i_this]/Q))) &amp;gt;= 120;
   con MaxShiftSize1: Q/cap1[i_this] &amp;lt;= 2;
   con MaxShiftSize2: Q/(f[i_this]*cap2[i_this]) &amp;lt;= 2;

   num Qsol {box};
   num Zsol {box};
   for {i in box} do;
      i_this = i;
      solve;
      print Q Z;
      Qsol[i] = Q;
      Zsol[i] = Z;
   end;
   print Qsol Zsol;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I removed the MinBatch constraint, which is redundant because of the &amp;gt;= 0 in the VAR statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, you can also solve these independent problems&amp;nbsp;concurrently by changing FOR to COFOR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a similar example, see &lt;A href="http://go.documentation.sas.com/?docsetId=ormpex&amp;amp;docsetTarget=ormpex_ex22_toc.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_self"&gt;Efficiency Analysis: How to Use Data Envelopment Analysis to Compare Efficiencies of Garages&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 23:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-LOOPING-OBJECT-FUNCTION-HELP-PLS/m-p/456726#M2235</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2018-04-23T23:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC OPTMODEL LOOPING OBJECT FUNCTION - HELP PLS</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-LOOPING-OBJECT-FUNCTION-HELP-PLS/m-p/457189#M2237</link>
      <description>Thank you so much sir!&lt;BR /&gt;Worked well.&lt;BR /&gt;&lt;BR /&gt;That was quick and super helpful &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;- Jesper</description>
      <pubDate>Wed, 25 Apr 2018 09:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-LOOPING-OBJECT-FUNCTION-HELP-PLS/m-p/457189#M2237</guid>
      <dc:creator>jesperph</dc:creator>
      <dc:date>2018-04-25T09:06:15Z</dc:date>
    </item>
  </channel>
</rss>

