Introduction to Optimization


Matrix Generation

It is desirable to keep data in separate tables, and then to automate model building and reporting. This example illustrates a problem that has elements of both a product mix problem and a blending problem. Suppose four kinds of ties are made: all silk, all polyester, a 50-50 polyester-cotton blend, and a 70-30 cotton-polyester blend.

The data include cost and supplies of raw material, selling price, minimum contract sales, maximum demand of the finished products, and the proportions of raw materials that go into each product. The objective is to find the product mix that maximizes profit.

The data are saved in three SAS data sets. The following program demonstrates one way for these data to be saved:

data material;
   format descpt $20.;
   input descpt $ cost supply;
   datalines;
silk_material             .21   25.8
polyester_material        .6    22.0
cotton_material           .9    13.6
;

data tie;
   format descpt $20.;
   input descpt $ price contract demand;
   datalines;
all_silk                  6.70    6.0    7.00
all_polyester             3.55   10.0   14.00
poly_cotton_blend         4.31   13.0   16.00
cotton_poly_blend         4.81    6.0    8.50
;

data manfg;
   format descpt $20.;
   input descpt $ silk poly cotton;
   datalines;
all_silk                   100     0      0
all_polyester                0   100      0
poly_cotton_blend            0    50     50
cotton_poly_blend            0    30     70
;

The following program takes the raw data from the three data sets and builds a linear program model in the data set called model. Although it is designed for the three-resource, four-product problem described here, it can be extended to include more resources and products. The model-building DATA step remains essentially the same; all that changes are the dimensions of loops and arrays. Of course, the data tables must expand to accommodate the new data. Note that data-driven model creation as outlined here is far easier and more direct with the algebraic modeling capabilities of PROC OPTMODEL, the foremost of the newer SAS/OR mathematical programming procedures.

data model;
   array  raw_mat {3} $ 20 ;
   array  raw_comp {3} silk poly cotton;
   length _type_ $ 8  _col_ $ 20  _row_ $ 20 _coef_ 8 ;
   keep   _type_      _col_       _row_      _coef_ ;

   /* define the objective, lower, and upper bound rows */

   _row_='profit'; _type_='max';     output;
   _row_='lower';  _type_='lowerbd'; output;
   _row_='upper';  _type_='upperbd'; output;
   _type_=' ';

   /* the object and upper rows for the raw materials */

   do i=1 to 3;
      set material;
      raw_mat[i]=descpt;  _col_=descpt;
      _row_='profit';    _coef_=-cost;  output;
      _row_='upper';     _coef_=supply; output;
   end;

   /* the object, upper, and lower rows for the products */

   do i=1 to 4;
      set tie;
      _col_=descpt;
      _row_='profit'; _coef_=price;    output;
      _row_='lower';  _coef_=contract; output;
      _row_='upper';  _coef_=demand;   output;
   end;

   /* the coefficient matrix for manufacturing */

   _type_='eq';
   do i=1 to 4;          /* loop for each raw material */
      set manfg;
      do j=1 to 3;       /* loop for each product      */

         _col_=descpt;   /* % of material in product   */
         _row_  = raw_mat[j];
         _coef_ = raw_comp[j]/100;
         output;

         _col_  = raw_mat[j];  _coef_ = -1;
         output;

         /* the right-hand side */

         if i=1 then do;
            _col_='_RHS_';
            _coef_=0;
            output;
         end;
      end;
      _type_='  ';
   end;
   stop;
run;

The model is solved using PROC LP, which saves the solution in the PRIMALOUT data set named solution. PROC PRINT displays the solution, shown in FigureĀ 2.6.

proc lp sparsedata primalout=solution;

proc print;
      id _var_;
      var _lbound_--_r_cost_;
run;

Figure 2.6: Solution Data Set

The LP Procedure

Constraint Summary
Row Constraint Name Type S/S Col Rhs Activity Dual Activity
1 profit OBJECTVE . 0 168.708 .
2 silk_material EQ . 0 0 0.21
3 polyester_material EQ . 0 0 3.55
4 cotton_material EQ . 0 0 5.07

_VAR_ _LBOUND_ _VALUE_ _UBOUND_ _PRICE_ _R_COST_
all_polyester 10 11.800 14.0 3.55 0.000
all_silk 6 7.000 7.0 6.70 6.490
cotton_material 0 13.600 13.6 -0.90 4.170
cotton_poly_blend 6 8.500 8.5 4.81 0.196
polyester_material 0 22.000 22.0 -0.60 2.950
poly_cotton_blend 13 15.300 16.0 4.31 0.000
silk_material 0 7.000 25.8 -0.21 0.000
PHASE_1_OBJECTIVE 0 0.000 0.0 0.00 0.000
profit 0 168.708 1.7977E308 0.00 0.000



The solution shows that 11.8 units of polyester ties, 7 units of silk ties, 8.5 units of the cotton-polyester blend, and 15.3 units of the polyester-cotton blend should be produced. It also shows the amounts of raw materials that go into this product mix to generate a total profit of 168.708.