Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Introduction to Optimization

Matrix Generation

It is desireable to keep data in separate tables, then automate model building and reporting. This example illustrates a problem that has elements of 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 30-70 cotton polyester blend.

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

The data are saved in three SAS data sets. The program that follows demonstrates one way for these data to be saved. Alternatively, the full screen editor PROC FSEDIT can be used to store and edit these data can be used.

   data material;
      input descpt $char20.  cost  supply;
   datalines;
silk_material             .21   25.8
polyester_material        .6    22.0
cotton_material           .9    13.6
   ;
   
   data tie;
      input descpt $char20. 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;
      input descpt $char20.  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 program that follows 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 easily 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 increase to accommodate the new data.

   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, which is shown in Figure 1.19.

   proc lp sparsedata primalout=solution;

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

The results are shown in Figure 1.19.

_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

Figure 1.19: the solution data set

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.


Exploiting Model Structure

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.