<?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: Generate a dataset with optimized results for every parameters combination in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Generate-a-dataset-with-optimized-results-for-every-parameters/m-p/540192#M2603</link>
    <description>Great! Thank you a lot!!</description>
    <pubDate>Mon, 04 Mar 2019 20:00:08 GMT</pubDate>
    <dc:creator>Edoedoedo</dc:creator>
    <dc:date>2019-03-04T20:00:08Z</dc:date>
    <item>
      <title>Generate a dataset with optimized results for every parameters combination</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Generate-a-dataset-with-optimized-results-for-every-parameters/m-p/539670#M2598</link>
      <description>&lt;P&gt;Hi, I'm learning proc optmodel and I have a question. Suppose we have this problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.funcs.f;
    function f1(Q, H);
        return (
            -21.570992+
            Q*1.972536+
            H*0.719408+
            Q**2*-0.03148+
            Q*H*-0.057026+
            H**2*-0.008104+
            Q**3*0.00117+
            Q**2*H*0.000098997+
            Q*H**2*0.000642+
            H**3*0.000030146+
            Q**4*-0.000015012+
            Q**3*H*-0.000001948+
            Q**2*H**2*-0.000000285+
            Q*H**3*-0.0000024+
            H**4*0
        );
    endsub;

    function f2(Q, H);
        return (
            -11.381931+
            Q*-0.176563+
            H*0.49236+
            Q**2*0.006618+
            Q*H*0.004691+
            H**2*-0.007303+
            Q**3*0.001559+
            Q**2*H*-0.001057+
            Q*H**2*0.00014+
            H**3*0.000035108+
            Q**4*-0.000015803+
            Q**3*H*-0.000005786+
            Q**2*H**2*0.000007708+
            Q*H**3*-0.000001467+
            H**4*0
        );
    endsub;
run;

options cmplib=work.funcs;

options nonotes;
proc optmodel;
    number P = 30.440000534;
    number H = 83.698883057;

    var Q1 &amp;gt;= 0;
    var Q2 &amp;gt;= 0;
    
    impvar P1 = Q1 * H * f1(Q1, H) * 9.81 / 1000;
    impvar P2 = Q2 * H * f2(Q2, H) * 9.81 / 1000;

    minimize Q = Q1 + Q2;

    constraint P = P1 + P2;

    solve with nlp / maxiter=10000000 nthreads=32;
    
    print Q Q1 Q2 (Q1/Q*100) (Q2/Q*100) P P1 P2 ;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The input variables are P and H (given as constants in the example). The minimization objective function is Q.&lt;/P&gt;
&lt;P&gt;If I run this code, I get (in the result window) the minimum Q for that specific values of P and H.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to run the optimization for each P in range (0,50) by step 0.1 and for each H in range (50,100) by step 0.1 and output the results in one dataset like:&lt;/P&gt;
&lt;P&gt;P | H | Q&lt;/P&gt;
&lt;P&gt;0 50.0 &amp;lt;the optimal Q with these parameters&amp;gt;&lt;/P&gt;
&lt;P&gt;0 50.1&amp;nbsp;&amp;lt;the optimal Q with these parameters&amp;gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;0.1 50.0 &amp;lt;the optimal Q with these parameters&amp;gt;&lt;/P&gt;
&lt;P&gt;0.1 50.1 &amp;lt;the optimal Q with these parameters&amp;gt;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would I do that? Should I prepare a dataset with all the combinations of P and H, and then tell somehow to proc optmodel to use this dataset as input?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2019 15:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Generate-a-dataset-with-optimized-results-for-every-parameters/m-p/539670#M2598</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2019-03-01T15:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a dataset with optimized results for every parameters combination</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Generate-a-dataset-with-optimized-results-for-every-parameters/m-p/539734#M2599</link>
      <description>&lt;P&gt;Yes, an input data set with P and H values is one approach, as demonstrated in &lt;A href="http://support.sas.com/kb/42/332.html" target="_self"&gt;this SAS Usage Note&lt;/A&gt;.&amp;nbsp; Alternatively, you can use nested DO loops over P and H as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel printlevel=0;
   number P;
   number H;

   var Q1 &amp;gt;= 0;
   var Q2 &amp;gt;= 0;

   impvar P1 = Q1 * H * f1(Q1, H) * 9.81 / 1000;
   impvar P2 = Q2 * H * f2(Q2, H) * 9.81 / 1000;

   minimize Q = Q1 + Q2;

   constraint P = P1 + P2;

   set PSET = 0..50 by 0.1;
   set HSET = 50..100 by 0.1;
   num Qopt {PSET, HSET};
   do P = PSET;
      do H = HSET;
         put P= H=;
         solve;
         Qopt[P,H] = Q.sol;
      end;
   end;
   create data Qdata from [P H] Q=Qopt;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Mar 2019 18:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Generate-a-dataset-with-optimized-results-for-every-parameters/m-p/539734#M2599</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-03-01T18:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a dataset with optimized results for every parameters combination</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Generate-a-dataset-with-optimized-results-for-every-parameters/m-p/540166#M2601</link>
      <description>&lt;P&gt;Thanks a lot!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One last question: how can I output in the dataset Qdata information about the solution, like the solution status, the optimality error etc, for each combination of (P,H)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solver is nlp, with maxiter=100; I need the status because for some (P,H) the solution can be found in a few iteration, but for other (P,H) the solution is unfeasable (so the Qsol is meaningless). Hence, in the final dataset Qdata I must know about how good is Qsol, to do other things for the values where the solution was unfeasable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 19:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Generate-a-dataset-with-optimized-results-for-every-parameters/m-p/540166#M2601</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2019-03-04T19:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a dataset with optimized results for every parameters combination</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Generate-a-dataset-with-optimized-results-for-every-parameters/m-p/540174#M2602</link>
      <description>&lt;P&gt;Before the DO loops, declare new parameters:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   str solstatus {PSET, HSET};
   num opterror {PSET, HSET};
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Inside the DO loops, populate these values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;         solstatus[P,H] = _solution_status_;
         opterror[P,H] = _OROPTMODEL_NUM_['OPTIMALITY_ERROR'];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After the DO loops, include the new parameters in the CREATE DATA statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   create data Qdata from [P H] Q=Qopt solstatus opterror;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 19:34:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Generate-a-dataset-with-optimized-results-for-every-parameters/m-p/540174#M2602</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-03-04T19:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: Generate a dataset with optimized results for every parameters combination</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Generate-a-dataset-with-optimized-results-for-every-parameters/m-p/540192#M2603</link>
      <description>Great! Thank you a lot!!</description>
      <pubDate>Mon, 04 Mar 2019 20:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Generate-a-dataset-with-optimized-results-for-every-parameters/m-p/540192#M2603</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2019-03-04T20:00:08Z</dc:date>
    </item>
  </channel>
</rss>

