<?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: Find a combination using proc optmodel in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-a-combination-using-proc-optmodel/m-p/453529#M2222</link>
    <description>&lt;P&gt;Amazing! Thank you&lt;/P&gt;</description>
    <pubDate>Thu, 12 Apr 2018 12:56:24 GMT</pubDate>
    <dc:creator>sanj5</dc:creator>
    <dc:date>2018-04-12T12:56:24Z</dc:date>
    <item>
      <title>Find a combination using proc optmodel</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-a-combination-using-proc-optmodel/m-p/453480#M2220</link>
      <description>&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;Hi,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;I am having some trouble using proc optmodel for the first time. I have the below table of 3 forecasts and the actual outturn for each month:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;Month FC1 FC2 FC3 AC &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;1 111 125 120 118&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;2 208 151 183 172&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;3 157 166 155 154&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;12 202 215 199 209&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;What I am trying to find is which combination of the 3 forecasts would have given the minimal absolute error over the whole year, subject to 3 constraints. The trouble I am having with it is loading my observations in and summing over the whole period.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;I have got it to work below for the first record by manually entering the values but any help would be appreciated. Also, is there a way to output the solution to a dataset rather than print? Thanks.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#333333" face="arial,helvetica,sans-serif" size="2"&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;&lt;BR /&gt;	
   var w1, w2, w3;&lt;BR /&gt;	
   minimize absErr = abs(((w1*111)+(w2*125)+(w3*120))-118);&lt;BR /&gt;	
   con bound1:    w1+w2+w3=1;&lt;BR /&gt;	
   con bound2:    max(w1,w2,w3)&amp;lt;= 1;&lt;BR /&gt;	
   con bound3:    min(w1,w2,w3)&amp;gt;= 0;&lt;BR /&gt;	
   solve;&lt;BR /&gt;	
   print w1 w2 w3;&lt;BR /&gt;	
quit;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 10:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-a-combination-using-proc-optmodel/m-p/453480#M2220</guid>
      <dc:creator>sanj5</dc:creator>
      <dc:date>2018-04-12T10:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Find a combination using proc optmodel</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-a-combination-using-proc-optmodel/m-p/453487#M2221</link>
      <description>&lt;P&gt;The following should work for you:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Dataset with forecasts and actuals - expand as necessary*/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; inds;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Month FC1 FC2 FC3 AC;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;1 111 125 120 118&lt;/P&gt;&lt;P&gt;2 208 151 183 172&lt;/P&gt;&lt;P&gt;3 157 166 155 154&lt;/P&gt;&lt;P&gt;4 202 215 199 209&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;optmodel&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;var&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; w1, w2, w3; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*create a set of month - the values are read from the input dataset and will adapt to the changes in that*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;num&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;gt; MONTHS;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*create number parameters running over the set of months*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;num&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; FC1{MONTHS};&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;num&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; FC2{MONTHS};&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;num&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; FC3{MONTHS};&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;num&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; AC{MONTHS};&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Read the input data into the set and the parameters */&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;read&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; inds &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;into&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; MONTHS=[Month] FC1 FC2 FC3 AC;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;print&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; FC1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*summarize the error over each month and parameterize the forecasted and actual values*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;minimize&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; absErr = sum{i in MONTHS} (abs(((w1*FC1[i])+(w2*FC2[i])+(w3*FC3[i]))-AC[i])); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;con&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; bound1: w1+w2+w3=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;con&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; bound2: max(w1,w2,w3)&amp;lt;= &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;con&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; bound3: min(w1,w2,w3)&amp;gt;= &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;solve&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;print&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; w1 w2 w3; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*create a simple output dataset with the value of the 3 variables*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; outds &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; w1 w2 w3;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 11:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-a-combination-using-proc-optmodel/m-p/453487#M2221</guid>
      <dc:creator>Berliner_Ørsted</dc:creator>
      <dc:date>2018-04-12T11:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Find a combination using proc optmodel</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-a-combination-using-proc-optmodel/m-p/453529#M2222</link>
      <description>&lt;P&gt;Amazing! Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 12:56:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-a-combination-using-proc-optmodel/m-p/453529#M2222</guid>
      <dc:creator>sanj5</dc:creator>
      <dc:date>2018-04-12T12:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Find a combination using proc optmodel</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Find-a-combination-using-proc-optmodel/m-p/453576#M2224</link>
      <description>&lt;P&gt;Without linearizing your model, the solver is unlikely to find a globally optimal solution.&amp;nbsp; You can avoid the nonlinear MAX and MIN functions by omitting the bound1 and bound2 constraints and instead enforcing these bounds in the VAR statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var w1 &amp;gt;= 0 &amp;lt;= 1, w2 &amp;gt;= 0 &amp;lt;= 1, w3 &amp;gt;= 0 &amp;lt;= 1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also linearize the absolute value in the objective by introducing Surplus and Slack variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var Surplus {MONTHS} &amp;gt;= 0;
var Slack {MONTHS} &amp;gt;= 0;
con LinearizeAbs {i in MONTHS}:
   w1*FC1[i] + w2*FC2[i] + w3*FC3[i] - AC[i] = Surplus[i] - Slack[i];
minimize absErr = sum{i in MONTHS} (Surplus[i] + Slack[i]);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See the &lt;A href="http://go.documentation.sas.com/?docsetId=ormpex&amp;amp;docsetTarget=ormpex_ex11_toc.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_self"&gt;Curve Fitting&lt;/A&gt; and &lt;A href="http://go.documentation.sas.com/?docsetId=ormpex&amp;amp;docsetTarget=ormpex_ex13_toc.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_self"&gt;Market Sharing&lt;/A&gt; examples in &lt;A href="http://go.documentation.sas.com/?docsetId=ormpex&amp;amp;docsetTarget=titlepage.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_self"&gt;SAS/OR 14.3 User's Guide: Mathematical Programming Examples&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 14:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Find-a-combination-using-proc-optmodel/m-p/453576#M2224</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2018-04-12T14:43:02Z</dc:date>
    </item>
  </channel>
</rss>

