<?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: Reading Data Into OPTMODEL Procedure in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790307#M3590</link>
    <description>This is brilliant Rob, thank you SO MUCH! You are what makes the SAS community great!</description>
    <pubDate>Sat, 15 Jan 2022 00:28:03 GMT</pubDate>
    <dc:creator>mdavidson</dc:creator>
    <dc:date>2022-01-15T00:28:03Z</dc:date>
    <item>
      <title>Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790256#M3586</link>
      <description>&lt;P&gt;I'm working through a problem I'm trying to solve using proc optmodel and I found an &lt;A href="https://support.sas.com/documentation/onlinedoc/or/132/optmodel.pdf" target="_self"&gt;example (see page 12 "A Transportation Problem")&lt;/A&gt;&amp;nbsp;from the SAS sample library on the optmodel procedure that is close to what I'm trying to do. I'm struggling to replace the hard-coded values in the red code below with values from&amp;nbsp; datasets (costs, supply, and demand)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
/* specify parameters */
&lt;FONT color="#FF0000"&gt;set O={'Detroit','Pittsburgh'};
set D={'Boston','New York'};
number c{O,D}=[30 20
40 10];
number a{O}=[200 100];
number b{D}=[150 150];&lt;/FONT&gt;
/* model description */
var x{O,D} &amp;gt;= 0;
min total_cost = sum{i in O, j in D}c[i,j]*x[i,j];
constraint supply{i in O}: sum{j in D}x[i,j]=a[i];
constraint demand{j in D}: sum{i in O}x[i,j]=b[j];
/* solve and output */
solve;
print x;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is the "input" table given in the example:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mdavidson_0-1642195578832.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67417i6127620E58F9EE60/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mdavidson_0-1642195578832.png" alt="mdavidson_0-1642195578832.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I have seen other optmodel examples that read values from datasets, but the key for me is I need my output in this matrix format where I can get the optimum configurations by origination and destination.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mdavidson_1-1642195795142.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67418i7153976B53888739/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mdavidson_1-1642195795142.png" alt="mdavidson_1-1642195795142.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;I'm hoping you can help me, based on my many hours of google searches looks like you're an absolute GOAT on optmodel!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 21:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790256#M3586</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2022-01-14T21:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790273#M3587</link>
      <description>&lt;P&gt;I would be glad to help.&amp;nbsp; Please share your data sets.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 22:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790273#M3587</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2022-01-14T22:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790279#M3588</link>
      <description>&lt;P&gt;Wow, thank you so much Rob. I just translated the example into 3 datasets -- here they are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data costs;
  length origination $25. destination $25. cost 8;
  input origination &amp;amp; destination &amp;amp; cost;
cards;
Detroit  Boston  30
Detroit  New York  20
Pittsburgh  Boston  40
Pittsburgh  New York  10
;

data supply;
  length origination $25. supply 8;
  input origination &amp;amp; supply;
cards;
Detroit  200
Pittsburgh  100
;

data demand;
  length destination $25. demand 8;
  input destination &amp;amp; demand;
cards;
Boston  150
New York  150
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jan 2022 22:20:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790279#M3588</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2022-01-14T22:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790293#M3589</link>
      <description>&lt;P&gt;The following reads from your three data sets, solves the problem, and creates two output data sets: one in sparse form like your costs data set, and one in dense matrix form, like you requested.&amp;nbsp; Note the use of the COMPRESS function because New York is not a valid data set variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   /* specify parameters */
   set &amp;lt;str&amp;gt; O;
   set &amp;lt;str&amp;gt; D;
   number c{O,D};
   number a{O};
   number b{D};

   /* read data */
   read data supply into O=[origination] a=supply;
   read data demand into D=[destination] b=demand;
   read data costs into [origination destination] c=cost;

   /* model description */
   var x{O,D} &amp;gt;= 0;
   min total_cost = sum{i in O, j in D}c[i,j]*x[i,j];
   constraint supply{i in O}: sum{j in D}x[i,j]=a[i];
   constraint demand{j in D}: sum{i in O}x[i,j]=b[j];

   /* solve and output */
   solve;
   print x;

   /* create data */
   create data sparse from [origination destination] x;
   create data dense from [origination]=O {j in D} &amp;lt;col(compress(j))=x[origination,j]&amp;gt;;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jan 2022 22:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790293#M3589</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2022-01-14T22:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790307#M3590</link>
      <description>This is brilliant Rob, thank you SO MUCH! You are what makes the SAS community great!</description>
      <pubDate>Sat, 15 Jan 2022 00:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790307#M3590</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2022-01-15T00:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790698#M3591</link>
      <description>&lt;P&gt;Rob -- I hate to ask again but my needs have slightly changed. In the below example I'm trying to solve a problem where I have more customer orders than I can fill for different product lines. I'd like to be able to maximize revenue and fill at least 10% of each customer's orders (where possible). I must not be understanding the array aspect of reading data into the optmodel procedure, what do I have incorrect below?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data orders_costs;
  length customer $25. product $25. revenue 8. num_orders 8.;
  input customer &amp;amp; product &amp;amp; revenue num_orders;
cards;
CustomerA  ProductA  300  100
CustomerA  ProductB  200  130
CustomerB  ProductA  300  0
CustomerB  ProductB  200  10
CustomerC  ProductA  300  10
CustomerC  ProductB  200  60
;

data supply;
  length product $25. supply 8;
  input product &amp;amp; supply;
cards;
ProductA  85
ProductB  180
;

data demand;
  length product $25. demand 8;
  input product &amp;amp; demand;
cards;
ProductA  110
ProductB  200
;

/*Note: optimum_orders_to_fill is hypothetical*/
data want;
  length customer $25. product $25. optimum_orders_to_fill 8. num_orders 8.;
  input customer &amp;amp; product &amp;amp; optimum_orders_to_fill num_orders;
cards;
CustomerA  ProductA  84  100
CustomerA  ProductB  120  130
CustomerB  ProductA  0  0
CustomerB  ProductB  5  10
CustomerC  ProductA  1  10
CustomerC  ProductB  55  60
;

proc optmodel;
   /* declare sets and data indexed by sets */
   set &amp;lt;str&amp;gt; O;
   set &amp;lt;str&amp;gt; D;
   number a{O};
   number b{D};
   number c{O,D};
   number n{O,D};

   /* read data */
   read data supply into O=[product] a=supply; /*supply*/
   read data orders_costs into D=[customer] b=num_orders; /*customer product demand*/
   read data orders_costs into [customer product] c=revenue; /*revenue*/
   read data orders_costs into [customer product] n=num_orders; /*customer demand*/

   /* solve variable and model description */
   /*matrix of supply and demand*/
   var x{O,D} &amp;gt;= 0;

   /*model objective*/
   max total_revenue = sum{i in O, j in D}c[i,j]*x[i,j];

   /*constraints*/
   constraint supply{i in O}: sum{j in D}x[i,j]=a[i];
   constraint demand{j in D}: sum{i in O}x[i,j]=b[j];
    /*ability to add constraint where each customer has at least 10% of their orders filled?*/

   /* solve and output */
   solve;
   print x;

   /* create data */
   create data sparse from [customer product] x;
   create data dense from [product]=O {j in D} &amp;lt;col(j)=x[product,j]&amp;gt;;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Jan 2022 15:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790698#M3591</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2022-01-18T15:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790711#M3592</link>
      <description>&lt;P&gt;You have the indices reversed in the last two READ DATA statements.&amp;nbsp; Also, you can merge them into one statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   read data orders_costs into [product customer] c=revenue n=num_orders;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This change will get you past the error, but now your problem is infeasible because total supply does not equal total demand.&amp;nbsp; To instead fill at least 10% of demand, you can modify your demand constraint as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   constraint demand{j in D}: sum{i in O}x[i,j] &amp;gt;= 0.1*b[j];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 17:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790711#M3592</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2022-01-18T17:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790746#M3593</link>
      <description>Once again, you're the best! Thank you Rob!</description>
      <pubDate>Tue, 18 Jan 2022 18:54:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790746#M3593</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2022-01-18T18:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790938#M3594</link>
      <description>&lt;P&gt;Thanks Rob -- I'm not sure if the updated demand constraint is working correctly. I'm expecting at least 10% of a customer's orders to be filled up until the supply constraint runs out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, in my data CustomerA has placed 100 orders for ProductA and CustomerC has placed 10 orders. Total supply for ProductA is 85, and demand is 110.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solver outputs the below result which is strange since in this simple example the revenue is the same for this product I would expect to see something like 84 units for CustomerA and 1 unit for CustomerC.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mdavidson_0-1642608600476.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67506i8D1EBB3F376E6374/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mdavidson_0-1642608600476.png" alt="mdavidson_0-1642608600476.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data orders_costs;
  length customer $25. product $25. revenue 8. num_orders 8.;
  input customer &amp;amp; product &amp;amp; revenue num_orders;
cards;
CustomerA  ProductA  300  100
CustomerA  ProductB  200  130
CustomerB  ProductA  300  0
CustomerB  ProductB  200  10
CustomerC  ProductA  300  10
CustomerC  ProductB  200  60
;

data supply;
  length product $25. supply 8;
  input product &amp;amp; supply;
cards;
ProductA  85
ProductB  180
;

data demand;
  length product $25. demand 8;
  input product &amp;amp; demand;
cards;
ProductA  110
ProductB  200
;

proc optmodel;
   /* declare sets and data indexed by sets */
   set &amp;lt;str&amp;gt; O;
   set &amp;lt;str&amp;gt; D;
   number a{O};
   number b{D};
   number c{O,D};
   number n{O,D};

   /* read data */
   read data supply into O=[product] a=supply; /*supply*/
   read data orders_costs into D=[customer] b=num_orders; /*customer demand*/
   read data orders_costs into [product customer] c=revenue n=num_orders; /*customer-product demand*/

   /* solve variable and model description */
   /*matrix of supply and demand*/
   var x{O,D} &amp;gt;= 0;

   /*model objective*/
   max total_revenue = sum{i in O, j in D}c[i,j]*x[i,j];

   /*constraints*/
	constraint supply{i in O}: sum{j in D}x[i,j]=a[i]; 
	constraint demand{j in D}: sum{i in O}x[i,j] &amp;gt;= 0.1*b[j];
 

   /* solve and output */
   solve;
   print x;

   /* create data */
   create data sparse from [customer product] x;
   create data dense from [product]=O {j in D} &amp;lt;col(j)=x[product,j]&amp;gt;;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 16:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/790938#M3594</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2022-01-19T16:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791042#M3595</link>
      <description>&lt;P&gt;The demand constraint I proposed makes sure that at least 10% of each customer's total demand (summed across all products) is satisfied.&amp;nbsp; Maybe you instead want the following, which forces at least 10% of each customer-product demand to be satisfied:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   constraint demand{i in O, j in D}: x[i,j] &amp;gt;= 0.1*n[i,j];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;On my machine, the resulting optimal solution, with objective value 61500, is:&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: x" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c b header" colspan="4" scope="colgroup"&gt;x&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="c headerempty" scope="col"&gt;&amp;nbsp;&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;CustomerA&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;CustomerB&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;CustomerC&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;ProductA&lt;/TH&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;75&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;ProductB&lt;/TH&gt;
&lt;TD class="r data"&gt;13&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;166&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that case, you do not need b[j] and can omit the demand data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you can implicitly enforce these constraints by omitting the explicit demand constraint declaration and changing the lower bound on x:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   var x{i in O, j in D} &amp;gt;= 0.1*n[i,j];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;On my machine, the resulting optimal solution, with objective value 61500, is:&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Optmodel: x" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c b header" colspan="4" scope="colgroup"&gt;x&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="c headerempty" scope="col"&gt;&amp;nbsp;&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;CustomerA&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;CustomerB&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;CustomerC&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;ProductA&lt;/TH&gt;
&lt;TD class="r data"&gt;84&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l rowheader" scope="row"&gt;ProductB&lt;/TH&gt;
&lt;TD class="r data"&gt;173&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 19 Jan 2022 21:59:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791042#M3595</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2022-01-19T21:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791054#M3596</link>
      <description>&lt;P&gt;Thanks again for your effort on this, would you mind posting your full optmodel code? I'm getting the same objective value but not the same matrix of customers/products.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data orders_costs;
  length customer $25. product $25. revenue 8. num_orders 8.;
  input customer &amp;amp; product &amp;amp; revenue num_orders;
cards;
CustomerA  ProductA  300  100
CustomerA  ProductB  200  130
CustomerB  ProductA  300  0
CustomerB  ProductB  200  10
CustomerC  ProductA  300  10
CustomerC  ProductB  200  60
;

data supply;
  length product $25. supply 8;
  input product &amp;amp; supply;
cards;
ProductA  85
ProductB  180
;

proc optmodel;
   /* declare sets and data indexed by sets */
   set &amp;lt;str&amp;gt; O;
   set &amp;lt;str&amp;gt; D;
   number a{O};
   number b{D};
   number c{O,D};
   number n{O,D};

   /* read data */
   read data supply into O=[product] a=supply; /*supply*/
   read data orders_costs into D=[customer] b=num_orders; /*customer demand*/
   read data orders_costs into [product customer] c=revenue n=num_orders; /*customer-product demand*/

   /* solve variable and model description */
   /*matrix of supply and demand*/
   var x{O,D} &amp;gt;= 0;

   /*model objective*/
   max total_revenue = sum{i in O, j in D}c[i,j]*x[i,j];

   /*constraints*/
	constraint supply{i in O}: sum{j in D}x[i,j]=a[i]; 
	constraint demand{i in O, j in D}: x[i,j] &amp;gt;= 0.1*n[i,j];
 

   /* solve and output */
   solve;
   print x;

   /* create data */
   create data sparse from [customer product] x;
   create data dense from [product]=O {j in D} &amp;lt;col(j)=x[product,j]&amp;gt;;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mdavidson_0-1642634484187.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67533i8B86185E2B3FDE94/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mdavidson_0-1642634484187.png" alt="mdavidson_0-1642634484187.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 23:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791054#M3596</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2022-01-19T23:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791062#M3597</link>
      <description>&lt;P&gt;The code you showed is the same as what I ran.&amp;nbsp; When there are alternative optimal solutions like in this case, different machines can yield different solutions.&amp;nbsp; The solver considers them all equally desirable if they satisfy the constraints and have the same objective value.&amp;nbsp; If you have a preference for one solution over another, that needs be captured in the optimization model.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 01:48:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791062#M3597</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2022-01-20T01:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791175#M3598</link>
      <description>&lt;P&gt;That is interesting to know about the results being different on different machines but makes sense as long as the conditions are met.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I'm still a bit confused on what I have wrong with my constraints because the solver is providing results that are greater than my customer orders. For example, CustomerB ordered 10 of Product B but the solver is giving them 161.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Rob I have to again thank you for holding my hand on this, it's clear I do not fully understand this procedure but I'm planning on reading several of your papers this weekend.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 15:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791175#M3598</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2022-01-20T15:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791178#M3599</link>
      <description>&lt;P&gt;The current model does not impose any explicit upper bound on how many units of a product get sent to a customer.&amp;nbsp; If you want to restrict to the number that were ordered, you can modify the demand constraint as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   constraint demand{i in O, j in D}: 0.1*n[i,j] &amp;lt;= x[i,j] &amp;lt;= n[i,j];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you can impose the bounds in the variable declaration:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   var x{i in O, j in D} &amp;gt;= 0.1*n[i,j] &amp;lt;= n[i,j];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With either change, CustomerB will get between 1 and 10 units of ProductB.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 15:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791178#M3599</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2022-01-20T15:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data Into OPTMODEL Procedure</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791284#M3600</link>
      <description>&lt;P&gt;Brilliant! Thank you Rob!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 21:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-Data-Into-OPTMODEL-Procedure/m-p/791284#M3600</guid>
      <dc:creator>mdavidson</dc:creator>
      <dc:date>2022-01-20T21:18:29Z</dc:date>
    </item>
  </channel>
</rss>

