Food Manufacture 2: Limiting the Number of Ingredients and Adding Extra Conditions

PROC OPTMODEL Statements and Output

For completeness, all statements are shown. Statements that are new or changed from Chapter 1 are indicated.

proc optmodel;
   set <str> OILS;
   num hardness {OILS};
   read data hardness_data into OILS=[oil] hardness;

   set PERIODS;
   num cost {OILS, PERIODS};
   read data cost_data into PERIODS=[_N_] {oil in OILS}
      <cost[oil,_N_]=col(oil)>;

   var Buy {OILS, PERIODS} >= 0;
   var Use {OILS, PERIODS} >= 0;
   impvar Manufacture {period in PERIODS} = sum {oil in OILS} Use[oil,period];

   num last_period = max {period in PERIODS} period;
   var Store {OILS, PERIODS union {0}} >= 0 <= &store_ub;
   for {oil in OILS} do;
      fix Store[oil,0]           = &init_storage;
      fix Store[oil,last_period] = &init_storage;
   end;

   set VEG = {oil in OILS: substr(oil,1,3) = 'veg'};
   set NONVEG = OILS diff VEG;

   impvar Revenue =
      sum {period in PERIODS} &revenue_per_ton * Manufacture[period];
   impvar RawCost =
      sum {oil in OILS, period in PERIODS} cost[oil,period] * Buy[oil,period];
   impvar StorageCost =
      sum {oil in OILS, period in PERIODS}
         &storage_cost_per_ton * Store[oil,period];
   max Profit = Revenue - RawCost - StorageCost;

   con Veg_ub_con {period in PERIODS}:
      sum {oil in VEG} Use[oil,period] <= &veg_ub;

   con Nonveg_ub_con {period in PERIODS}:
      sum {oil in NONVEG} Use[oil,period] <= &nonveg_ub;

   con Flow_balance_con {oil in OILS, period in PERIODS}:
      Store[oil,period-1] + Buy[oil,period]
         = Use[oil,period] + Store[oil,period];

   con Hardness_ub_con {period in PERIODS}:
      sum {oil in OILS} hardness[oil] * Use[oil,period]
      >= &hardness_lb * Manufacture[period];

   con Hardness_lb_con {period in PERIODS}:
      sum {oil in OILS} hardness[oil] * Use[oil,period]
      <= &hardness_ub * Manufacture[period];

The remaining statements are new in this example. The BINARY option in the following VAR statement declares IsUsed to be a binary variable:

   var IsUsed {OILS, PERIODS} binary;

The .ub variable suffix imposes an upper bound on the Use variable, in preparation for the subsequent Link constraint. The validity of this upper bound follows from the Veg_ub_con and Nonveg_ub_con constraints.

   for {period in PERIODS} do;
      for {oil in VEG}    Use[oil,period].ub = &veg_ub;
      for {oil in NONVEG} Use[oil,period].ub = &nonveg_ub;
   end;

The following Link constraint enforces the rule that sans-serif upper U sans-serif s sans-serif e sans-serif left-bracket sans-serif o sans-serif i sans-serif l sans-serif comma sans-serif p sans-serif e sans-serif r sans-serif i sans-serif o sans-serif d sans-serif right-bracket greater-than 0 implies that sans-serif upper I sans-serif s sans-serif upper U sans-serif s sans-serif e sans-serif d sans-serif left-bracket sans-serif o sans-serif i sans-serif l sans-serif comma sans-serif p sans-serif e sans-serif r sans-serif i sans-serif o sans-serif d sans-serif right-bracket equals 1:

   con Link {oil in OILS, period in PERIODS}:
      Use[oil,period] <= Use[oil,period].ub * IsUsed[oil,period];

The following Logical1, Logical2, and Logical3 constraints correspond directly to the three extra conditions in the problem statement:

   con Logical1 {period in PERIODS}:
      sum {oil in OILS} IsUsed[oil,period] <= &max_num_oils_used;

   con Logical2 {oil in OILS, period in PERIODS}:
      Use[oil,period] >= &min_oil_used_threshold * IsUsed[oil,period];

   con Logical3 {oil in {'veg1','veg2'}, period in PERIODS}:
      IsUsed[oil,period] <= IsUsed['oil3',period];

   num hardness_sol {period in PERIODS} =
      (sum {oil in OILS} hardness[oil] * Use[oil,period].sol)
         / Manufacture[period].sol;

Because PROC OPTMODEL automatically recognizes that this model is a mixed integer linear programming problem, the following SOLVE statement calls the MILP solver, as shown in Figure 1:

   solve;

Figure 1: Summaries from Mixed Integer Linear Programming Solver

The OPTMODEL Procedure

Problem Summary
Objective SenseMaximization
Objective FunctionProfit
Objective TypeLinear
  
Number of Variables125
Bounded Above0
Bounded Below30
Bounded Below and Above85
Free0
Fixed10
Binary30
Integer0
  
Number of Constraints132
Linear LE (<=)66
Linear EQ (=)30
Linear GE (>=)36
Linear Range0
  
Constraint Coefficients384

Solution Summary
SolverMILP
AlgorithmBranch and Cut
Objective FunctionProfit
Solution StatusOptimal
Objective Value100278.7037
  
Relative Gap0
Absolute Gap0
Primal Infeasibility1.705303E-13
Bound Infeasibility1.136868E-13
Integer Infeasibility7.21645E-16
  
Best Bound100278.7037
Nodes419
Solutions Found11
Iterations4971
Presolve Time0.69
Solution Time0.83


The following PRINT statement creates the output shown in Figure 2:

   print Buy Use Store IsUsed Manufacture hardness_sol Logical1.body;

The .body constraint suffix accesses the left-hand side value of the Logical1 constraint. For each period, the solution uses no more than three oils, as shown in Figure 2. The following CREATE DATA statements create multiple output data sets, as in Chapter 1:

   create data sol_data1 from [oil period] Buy Use Store IsUsed;
   create data sol_data2 from [period] Manufacture;
quit;

Figure 2: Output from Mixed Integer Linear Programming Solver

[1][2]BuyUseStoreIsUsed
oil10  500.00 
oil110.000.000500.000
oil120.00-0.000500.000
oil130.000.000500.000
oil14-0.000.000500.000
oil150.000.000500.000
oil160.000.000500.000
oil20  500.00 
oil210.000.000500.000
oil220.000.000500.000
oil230.0040.000460.001
oil240.00230.000230.001
oil250.00230.0000.001
oil26730.00230.000500.001
oil30  500.00 
oil310.00250.000250.001
oil320.00250.000-0.001
oil33770.00210.000560.001
oil340.0020.000540.001
oil350.0020.000520.001
oil360.0020.000500.001
veg10  500.00 
veg110.0085.185414.811
veg120.0085.185329.631
veg130.000.000329.630
veg14-0.00155.000174.631
veg15-0.00155.00019.631
veg16480.370.000500.000
veg20  500.00 
veg210.00114.815385.191
veg220.00114.815270.371
veg230.00200.00070.371
veg240.000.00070.370
veg250.000.00070.370
veg26629.63200.000500.001

[1]Manufacturehardness_solLogical1.BODY
14506.00003
24506.00003
34505.41783
44056.00003
54056.00003
64505.08003


Note that the maximum profit of £100,279 is smaller than in Chapter 1. This result is expected because this model contains additional constraints.

Last updated: April 13, 2020