<?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 using proc optmodel nonlinear constraint and binary variable to achieve the same result solver excel in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/using-proc-optmodel-nonlinear-constraint-and-binary-variable-to/m-p/835244#M3798</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;, can you help please? I cannot achieve the same result as a can in solver in excel. My result is very bad in sas actually. What method i can use to make opmization with binary variables and have nonlinar constraint? Follow the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro doit(list);&lt;/P&gt;
&lt;P&gt;*base agrupadas;&lt;BR /&gt;%let n=%sysfunc(countw(&amp;amp;list.));&lt;BR /&gt;%do i=1 %to &amp;amp;n.-1;&lt;BR /&gt;&lt;BR /&gt;%do i2=&amp;amp;i.+1 %to &amp;amp;n.;&lt;BR /&gt;&lt;BR /&gt;%let val = %scan(&amp;amp;list.,&amp;amp;i.);&lt;BR /&gt;%let val2 = %scan(&amp;amp;list.,&amp;amp;i2.);&lt;BR /&gt;proc sql;&lt;BR /&gt;create table &amp;amp;val._&amp;amp;val2. as&lt;BR /&gt;select&lt;BR /&gt;&amp;amp;val. ,&lt;BR /&gt;&amp;amp;val2. ,&lt;BR /&gt;sum(over) as over format commax15.0,&lt;BR /&gt;sum(qtd) as qtd format commax15.0&lt;BR /&gt;&lt;BR /&gt;from import2&lt;BR /&gt;group by 1,2&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;data &amp;amp;val._&amp;amp;val2.;&lt;BR /&gt;set &amp;amp;val._&amp;amp;val2.;&lt;BR /&gt;rownum=_n_;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;*otimização;&lt;BR /&gt;&lt;STRONG&gt;proc optmodel;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;set sset;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;number over {sset};&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;number qtd {sset};&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;read data &amp;amp;val._&amp;amp;val2. into sset=[rownum] over qtd;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;var x {sset} binary;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;max Objective = (sum {rownum in SSET} qtd[rownum]*x[rownum]);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;con overmax:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;100*(sum {rownum in sset} over[rownum]*x[rownum])/(sum {rownum in sset} qtd[rownum]*x[rownum]) &amp;lt;=&amp;amp;over_target.;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;solve with lso;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;print x;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;create data &amp;amp;val._&amp;amp;val2._opt from [rownum]=SSET x;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;*resultado da otimização;&lt;BR /&gt;data &amp;amp;val._&amp;amp;val2._vf;&lt;BR /&gt;merge &amp;amp;val._&amp;amp;val2. (in=a) &amp;amp;val._&amp;amp;val2._opt (in=b);&lt;BR /&gt;by rownum;&lt;BR /&gt;if a and b;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;*loop;&lt;/P&gt;
&lt;P&gt;%let n=%sysfunc(countw(&amp;amp;list.));&lt;BR /&gt;%do i=1 %to &amp;amp;n.-1;&lt;BR /&gt;&lt;BR /&gt;%do i2=&amp;amp;i.+1 %to &amp;amp;n.;&lt;BR /&gt;&lt;BR /&gt;%let val = %scan(&amp;amp;list.,&amp;amp;i.);&lt;BR /&gt;%let val2 = %scan(&amp;amp;list.,&amp;amp;i2.);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;*printa;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;%doit(&amp;amp;variaveis.);&lt;/P&gt;</description>
    <pubDate>Mon, 26 Sep 2022 18:26:36 GMT</pubDate>
    <dc:creator>LAIO</dc:creator>
    <dc:date>2022-09-26T18:26:36Z</dc:date>
    <item>
      <title>using proc optmodel nonlinear constraint and binary variable to achieve the same result solver excel</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/using-proc-optmodel-nonlinear-constraint-and-binary-variable-to/m-p/835244#M3798</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;, can you help please? I cannot achieve the same result as a can in solver in excel. My result is very bad in sas actually. What method i can use to make opmization with binary variables and have nonlinar constraint? Follow the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro doit(list);&lt;/P&gt;
&lt;P&gt;*base agrupadas;&lt;BR /&gt;%let n=%sysfunc(countw(&amp;amp;list.));&lt;BR /&gt;%do i=1 %to &amp;amp;n.-1;&lt;BR /&gt;&lt;BR /&gt;%do i2=&amp;amp;i.+1 %to &amp;amp;n.;&lt;BR /&gt;&lt;BR /&gt;%let val = %scan(&amp;amp;list.,&amp;amp;i.);&lt;BR /&gt;%let val2 = %scan(&amp;amp;list.,&amp;amp;i2.);&lt;BR /&gt;proc sql;&lt;BR /&gt;create table &amp;amp;val._&amp;amp;val2. as&lt;BR /&gt;select&lt;BR /&gt;&amp;amp;val. ,&lt;BR /&gt;&amp;amp;val2. ,&lt;BR /&gt;sum(over) as over format commax15.0,&lt;BR /&gt;sum(qtd) as qtd format commax15.0&lt;BR /&gt;&lt;BR /&gt;from import2&lt;BR /&gt;group by 1,2&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;data &amp;amp;val._&amp;amp;val2.;&lt;BR /&gt;set &amp;amp;val._&amp;amp;val2.;&lt;BR /&gt;rownum=_n_;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;*otimização;&lt;BR /&gt;&lt;STRONG&gt;proc optmodel;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;set sset;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;number over {sset};&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;number qtd {sset};&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;read data &amp;amp;val._&amp;amp;val2. into sset=[rownum] over qtd;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;var x {sset} binary;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;max Objective = (sum {rownum in SSET} qtd[rownum]*x[rownum]);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;con overmax:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;100*(sum {rownum in sset} over[rownum]*x[rownum])/(sum {rownum in sset} qtd[rownum]*x[rownum]) &amp;lt;=&amp;amp;over_target.;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;solve with lso;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;print x;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;create data &amp;amp;val._&amp;amp;val2._opt from [rownum]=SSET x;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;*resultado da otimização;&lt;BR /&gt;data &amp;amp;val._&amp;amp;val2._vf;&lt;BR /&gt;merge &amp;amp;val._&amp;amp;val2. (in=a) &amp;amp;val._&amp;amp;val2._opt (in=b);&lt;BR /&gt;by rownum;&lt;BR /&gt;if a and b;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;*loop;&lt;/P&gt;
&lt;P&gt;%let n=%sysfunc(countw(&amp;amp;list.));&lt;BR /&gt;%do i=1 %to &amp;amp;n.-1;&lt;BR /&gt;&lt;BR /&gt;%do i2=&amp;amp;i.+1 %to &amp;amp;n.;&lt;BR /&gt;&lt;BR /&gt;%let val = %scan(&amp;amp;list.,&amp;amp;i.);&lt;BR /&gt;%let val2 = %scan(&amp;amp;list.,&amp;amp;i2.);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;*printa;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;%doit(&amp;amp;variaveis.);&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 18:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/using-proc-optmodel-nonlinear-constraint-and-binary-variable-to/m-p/835244#M3798</guid>
      <dc:creator>LAIO</dc:creator>
      <dc:date>2022-09-26T18:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: using proc opmodel nonlinar constrain and binary variable to achieve the same result solver exce</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/using-proc-optmodel-nonlinear-constraint-and-binary-variable-to/m-p/835250#M3799</link>
      <description>&lt;P&gt;You have not supplied everything to be able to run your code, but the NLP solver does not support integer variables.&amp;nbsp; (Edit: I see now that you have changed your code to use LSO instead of NLP.&amp;nbsp; The LSO solver, now called the black-box solver, supports integer variables but does not guarantee optimality.&amp;nbsp; Better to use MILP here.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fortunately, you can easily linearize the nonlinear constraint as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;con overmax:
   100 * sum {rownum in sset} over[rownum]*x[rownum] &amp;lt;= &amp;amp;over_target. * sum {rownum in sset} qtd[rownum]*x[rownum];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can call the MILP solver:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;solve with milp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;solve;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alternatively, if you specify the LINEARIZE option (available in SAS Viya only) without changing your original model, OPTMODEL will do this linearization for you automatically:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;solve linearize;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 18:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/using-proc-optmodel-nonlinear-constraint-and-binary-variable-to/m-p/835250#M3799</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2022-09-26T18:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: using proc opmodel nonlinar constrain and binary variable to achieve the same result solver exce</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/using-proc-optmodel-nonlinear-constraint-and-binary-variable-to/m-p/835262#M3800</link>
      <description>&lt;P&gt;great&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;! It worked. Thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Sep 2022 19:37:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/using-proc-optmodel-nonlinear-constraint-and-binary-variable-to/m-p/835262#M3800</guid>
      <dc:creator>LAIO</dc:creator>
      <dc:date>2022-09-26T19:37:52Z</dc:date>
    </item>
  </channel>
</rss>

