<?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 Help with constraining in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Help-with-constraining/m-p/572265#M2825</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to solve an elasticity problem in which I'm maximizing revenue such as the example presented here:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/ormpex/66104/HTML/default/viewer.htm#ormpex_ex21_sect009.htm" target="_self"&gt;&lt;FONT&gt;http://support.sas.com/documentation/cdl/en/ormpex/66104/HTML/default/viewer.htm#ormpex_ex21_sect009.htm&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;However, I'm trying to add a constraint so that the price of product A has to be the same price as the price in product B in the output. Which you'll see my attempt in the rack_rate_con constraint on the code.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Here is my current SAS Code:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Previous Prievious Price and Demand Data*/
data product_data;
   input product $  prev_demand prev_price;
   datalines;
Land      60  120
Trans     30  120
;
run;


/*Elasticity Data*/
data elasticity_data;
   input i $ j $ elasticity;
   datalines;
Land    Land   -0.85
Trans   Trans   -0.27
;
run;



proc optmodel;
/*   set &amp;lt;str&amp;gt; RAWS;*/
/*   num supply {RAWS};*/
/*   read data raw_material_data into RAWS=[raw] supply;*/

   set &amp;lt;str&amp;gt; PRODUCTS;
   num prev_demand {PRODUCTS};
   num prev_price {PRODUCTS};
/*   num percent {PRODUCTS, RAWS};*/
   read data product_data into PRODUCTS=[product] prev_demand prev_price;
      
   num elasticity {PRODUCTS, PRODUCTS} init 0;
   read data elasticity_data into [i j] elasticity;


 var Price {PRODUCTS} &amp;gt;= 0;

   var Demand {PRODUCTS} &amp;gt;= 0;

   
   max TotalRevenue 
      = sum {product in PRODUCTS} Price[product] * Demand[product];

   con Demand_con {i in PRODUCTS}:
      (Demand[i] - prev_demand[i]) / prev_demand[i] 
    = sum {j in PRODUCTS} elasticity[i,j] * (Price[j] - prev_price[j]) / 
      prev_price[j];


   con Price_index_con:
      sum {product in PRODUCTS} prev_demand[product] * Price[product]
   &amp;lt;= sum {product in PRODUCTS} prev_demand[product] * prev_price[product];

/* Attempting to add constraint to make sure the price of the two recommendations is the same*/ 
   con rack_rate_con {i in PRODUCTS}: 
     sum {PRODUCTS} Price[i] 
   = sum {j in PRODUCTS} Price[j]; 

solve with NLP / algorithm=activeset MULTISTART SEED=7888422;&lt;BR /&gt;
print Price Demand TotalRevenue; 
print Price_index_con.dual; 
print rack_rate_con.dual; &lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;I do not error out, but it's not suggesting any changes. &lt;/FONT&gt;However, &lt;FONT&gt;If I add the&amp;nbsp;FEASTOL=2 option, it starts suggesting rates that are close enough to each other, but the calculated demand is way off when enabling this option.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;If I remove the&amp;nbsp;&lt;FONT&gt;rack_rate_con&lt;/FONT&gt; constraint altogether, the calculated demand looks reasonable.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Any help is appreciated.&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jul 2019 00:02:02 GMT</pubDate>
    <dc:creator>Audron</dc:creator>
    <dc:date>2019-07-10T00:02:02Z</dc:date>
    <item>
      <title>Help with constraining</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Help-with-constraining/m-p/572265#M2825</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to solve an elasticity problem in which I'm maximizing revenue such as the example presented here:&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/ormpex/66104/HTML/default/viewer.htm#ormpex_ex21_sect009.htm" target="_self"&gt;&lt;FONT&gt;http://support.sas.com/documentation/cdl/en/ormpex/66104/HTML/default/viewer.htm#ormpex_ex21_sect009.htm&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;However, I'm trying to add a constraint so that the price of product A has to be the same price as the price in product B in the output. Which you'll see my attempt in the rack_rate_con constraint on the code.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Here is my current SAS Code:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Previous Prievious Price and Demand Data*/
data product_data;
   input product $  prev_demand prev_price;
   datalines;
Land      60  120
Trans     30  120
;
run;


/*Elasticity Data*/
data elasticity_data;
   input i $ j $ elasticity;
   datalines;
Land    Land   -0.85
Trans   Trans   -0.27
;
run;



proc optmodel;
/*   set &amp;lt;str&amp;gt; RAWS;*/
/*   num supply {RAWS};*/
/*   read data raw_material_data into RAWS=[raw] supply;*/

   set &amp;lt;str&amp;gt; PRODUCTS;
   num prev_demand {PRODUCTS};
   num prev_price {PRODUCTS};
/*   num percent {PRODUCTS, RAWS};*/
   read data product_data into PRODUCTS=[product] prev_demand prev_price;
      
   num elasticity {PRODUCTS, PRODUCTS} init 0;
   read data elasticity_data into [i j] elasticity;


 var Price {PRODUCTS} &amp;gt;= 0;

   var Demand {PRODUCTS} &amp;gt;= 0;

   
   max TotalRevenue 
      = sum {product in PRODUCTS} Price[product] * Demand[product];

   con Demand_con {i in PRODUCTS}:
      (Demand[i] - prev_demand[i]) / prev_demand[i] 
    = sum {j in PRODUCTS} elasticity[i,j] * (Price[j] - prev_price[j]) / 
      prev_price[j];


   con Price_index_con:
      sum {product in PRODUCTS} prev_demand[product] * Price[product]
   &amp;lt;= sum {product in PRODUCTS} prev_demand[product] * prev_price[product];

/* Attempting to add constraint to make sure the price of the two recommendations is the same*/ 
   con rack_rate_con {i in PRODUCTS}: 
     sum {PRODUCTS} Price[i] 
   = sum {j in PRODUCTS} Price[j]; 

solve with NLP / algorithm=activeset MULTISTART SEED=7888422;&lt;BR /&gt;
print Price Demand TotalRevenue; 
print Price_index_con.dual; 
print rack_rate_con.dual; &lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;I do not error out, but it's not suggesting any changes. &lt;/FONT&gt;However, &lt;FONT&gt;If I add the&amp;nbsp;FEASTOL=2 option, it starts suggesting rates that are close enough to each other, but the calculated demand is way off when enabling this option.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;If I remove the&amp;nbsp;&lt;FONT&gt;rack_rate_con&lt;/FONT&gt; constraint altogether, the calculated demand looks reasonable.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Any help is appreciated.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 00:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Help-with-constraining/m-p/572265#M2825</guid>
      <dc:creator>Audron</dc:creator>
      <dc:date>2019-07-10T00:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Help with constraining</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Help-with-constraining/m-p/572271#M2826</link>
      <description>&lt;P&gt;The EXPAND statement shows the following model:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Var Price[Land] &amp;gt;= 0                                                                           
Var Price[Trans] &amp;gt;= 0                                                                          
Var Demand[Land] &amp;gt;= 0                                                                          
Var Demand[Trans] &amp;gt;= 0                                                                         
Maximize TotalRevenue=Price[Land]*Demand[Land] + Price[Trans]*Demand[Trans]                    
Constraint Demand_con[Land]: 0.0166666667*Demand[Land] + 0.0070833333*Price[Land] = 1.85       
Constraint Demand_con[Trans]: 0.0333333333*Demand[Trans] + 0.00225*Price[Trans] = 1.27         
Constraint Price_index_con: 60*Price[Land] + 30*Price[Trans] &amp;lt;= 10800                          
Constraint rack_rate_con[Land]: Price[Land] - Price[Trans] = 0                                 
Constraint rack_rate_con[Trans]: Price[Trans] - Price[Land] = 0                                
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This does seem to do what you want, but notice that the last two constraints are duplicates.&amp;nbsp; A simpler approach to ensure that both products have the same price is to not index the Price variable by product.&amp;nbsp; For example, the variable declaration would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   var Price &amp;gt;= 0;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Both approaches yield optimal objective value 10800.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 01:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Help-with-constraining/m-p/572271#M2826</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2019-07-10T01:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Help with constraining</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Help-with-constraining/m-p/572298#M2827</link>
      <description>&lt;P&gt;I think I got it to work, and here is my new code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Previous Prievious Price and Demand Data*/
data product_data;
   input product $  prev_demand prev_price;
   datalines;
Land      60  120
Trans     30  120
;
run;


/*Elasticity Data*/
data elasticity_data;
   input i $ elasticity;
   datalines;
Land    -0.85
Trans    -0.27
;
run;



proc optmodel;
   set &amp;lt;str&amp;gt; PRODUCTS;
 
   num prev_demand {PRODUCTS};
   num prev_price {PRODUCTS};
   read data product_data into PRODUCTS=[product] prev_demand prev_price;
   num elasticity {PRODUCTS};
   read data elasticity_data into [i] elasticity;

   var Price &amp;gt;= 0;
   var Demand {PRODUCTS} &amp;gt;= 0;


   max TotalRevenue = sum {product in PRODUCTS} Price * Demand[product];

   con Demand_con {i in PRODUCTS}:
      (Demand[i] - prev_demand[i]) / prev_demand[i]  = sum {PRODUCTS} elasticity[i] * (Price - prev_price[i]) / prev_price[i];



   solve with NLP / algorithm=activeset MULTISTART SEED=7888422;
   print Price Demand TotalRevenue; 
   print Demand_con.dual;
   expand;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 07:05:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Help-with-constraining/m-p/572298#M2827</guid>
      <dc:creator>Audron</dc:creator>
      <dc:date>2019-07-10T07:05:38Z</dc:date>
    </item>
  </channel>
</rss>

