examples/food.mod
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 05 Dec 2010 17:35:23 +0100
changeset 2 4c8956a7bdf4
permissions -rw-r--r--
Set up CMAKE build environment
alpar@1
     1
/* Food Manufacture 1, section 12.1 in
alpar@1
     2
 * Williams, "Model Building in Mathematical Programming"
alpar@1
     3
 *
alpar@1
     4
 * Sebastian Nowozin <nowozin@gmail.com>
alpar@1
     5
 */
alpar@1
     6
alpar@1
     7
set oils;
alpar@1
     8
set month;
alpar@1
     9
alpar@1
    10
/* Buying prices of the raw oils in the next six month. */
alpar@1
    11
param buyingprices{month,oils};
alpar@1
    12
alpar@1
    13
/* Actual amount bought in each month. */
alpar@1
    14
var buys{month,oils} >= 0;
alpar@1
    15
alpar@1
    16
/* Stock for each oil. */
alpar@1
    17
var stock{month,oils} >= 0;
alpar@1
    18
alpar@1
    19
/* Price of the produced product */
alpar@1
    20
param productprice >= 0;
alpar@1
    21
param storagecost;
alpar@1
    22
alpar@1
    23
param oilhardness{oils} >= 0;
alpar@1
    24
alpar@1
    25
/* Actual amount of output oil produced in each month */
alpar@1
    26
var production{m in month} >= 0;
alpar@1
    27
var useoil{m in month, o in oils} >= 0;
alpar@1
    28
alpar@1
    29
maximize totalprofit:
alpar@1
    30
    sum{m in month} productprice*production[m]
alpar@1
    31
    - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
alpar@1
    32
    - sum{m in month, o in oils} storagecost*stock[m,o];
alpar@1
    33
alpar@1
    34
/* Constraints */
alpar@1
    35
alpar@1
    36
/* 1. Starting stock */
alpar@1
    37
s.t. startstock{o in oils}:
alpar@1
    38
    stock[1,o] = 500;
alpar@1
    39
s.t. endstock{o in oils}:
alpar@1
    40
    stock[6,o] + buys[6,o] - useoil[6,o] >= 500;
alpar@1
    41
alpar@1
    42
/* 2. Stock constraints */
alpar@1
    43
s.t. stocklimit{m in month, o in oils}:
alpar@1
    44
    stock[m,o] <= 1000;
alpar@1
    45
alpar@1
    46
s.t. production1{m in month, o in oils}:
alpar@1
    47
    useoil[m,o] <= stock[m,o] + buys[m,o];
alpar@1
    48
s.t. production2{m1 in month, m2 in month, o in oils : m2 = m1+1}:
alpar@1
    49
    stock[m2,o] = stock[m1,o] + buys[m1,o] - useoil[m1,o];
alpar@1
    50
alpar@1
    51
s.t. production3a{m in month}:
alpar@1
    52
    sum{o in oils} oilhardness[o]*useoil[m,o] >= 3*production[m];
alpar@1
    53
s.t. production3b{m in month}:
alpar@1
    54
    sum{o in oils} oilhardness[o]*useoil[m,o] <= 6*production[m];
alpar@1
    55
alpar@1
    56
s.t. production4{m in month}:
alpar@1
    57
    production[m] = sum{o in oils} useoil[m,o];
alpar@1
    58
alpar@1
    59
/* 3. Refining constraints */
alpar@1
    60
s.t. refine1{m in month}:
alpar@1
    61
    useoil[m,"VEG1"]+useoil[m,"VEG2"] <= 200;
alpar@1
    62
s.t. refine2{m in month}:
alpar@1
    63
    useoil[m,"OIL1"]+useoil[m,"OIL2"]+useoil[m,"OIL3"] <= 250;
alpar@1
    64
alpar@1
    65
solve;
alpar@1
    66
alpar@1
    67
for {m in month} {
alpar@1
    68
    printf "Month %d\n", m;
alpar@1
    69
    printf "PRODUCE %4.2f tons, hardness %4.2f\n", production[m],
alpar@1
    70
        (sum{o in oils} oilhardness[o]*useoil[m,o]) / (sum{o in oils} useoil[m,o]);
alpar@1
    71
alpar@1
    72
    printf "\tVEG1\tVEG2\tOIL1\tOIL2\tOIL3\n";
alpar@1
    73
    printf "STOCK";
alpar@1
    74
    printf "%d", m;
alpar@1
    75
    for {o in oils} {
alpar@1
    76
        printf "\t%4.2f", stock[m,o];
alpar@1
    77
    }
alpar@1
    78
    printf "\nBUY";
alpar@1
    79
    for {o in oils} {
alpar@1
    80
        printf "\t%4.2f", buys[m,o];
alpar@1
    81
    }
alpar@1
    82
    printf "\nUSE";
alpar@1
    83
    printf "%d", m;
alpar@1
    84
    for {o in oils} {
alpar@1
    85
        printf "\t%4.2f", useoil[m,o];
alpar@1
    86
    }
alpar@1
    87
    printf "\n";
alpar@1
    88
    printf "\n";
alpar@1
    89
}
alpar@1
    90
printf "Total profit: %4.2f\n",
alpar@1
    91
    (sum{m in month} productprice*production[m]
alpar@1
    92
    - sum{m in month, o in oils} buyingprices[m,o]*buys[m,o]
alpar@1
    93
    - sum{m in month, o in oils} storagecost*stock[m,o]);
alpar@1
    94
printf "      turnover: %4.2f\n",
alpar@1
    95
    sum{m in month} productprice*production[m];
alpar@1
    96
printf "      buying costs: %4.2f\n",
alpar@1
    97
    sum{m in month, o in oils} buyingprices[m,o]*buys[m,o];
alpar@1
    98
printf "      storage costs: %4.2f\n",
alpar@1
    99
    sum{m in month, o in oils} storagecost*stock[m,o];
alpar@1
   100
alpar@1
   101
alpar@1
   102
data;
alpar@1
   103
alpar@1
   104
param : oils : oilhardness :=
alpar@1
   105
    VEG1    8.8
alpar@1
   106
    VEG2    6.1
alpar@1
   107
    OIL1    2.0
alpar@1
   108
    OIL2    4.2
alpar@1
   109
    OIL3    5.0 ;
alpar@1
   110
alpar@1
   111
set month := 1 2 3 4 5 6;
alpar@1
   112
alpar@1
   113
param buyingprices
alpar@1
   114
alpar@1
   115
:           VEG1    VEG2    OIL1    OIL2    OIL3    :=
alpar@1
   116
alpar@1
   117
1           110     120     130     110     115
alpar@1
   118
2           130     130     110     90      115
alpar@1
   119
3           110     140     130     100     95
alpar@1
   120
4           120     110     120     120     125
alpar@1
   121
5           100     120     150     110     105
alpar@1
   122
6           90      100     140     80      135 ;
alpar@1
   123
alpar@1
   124
param productprice := 150;
alpar@1
   125
param storagecost := 5;
alpar@1
   126
alpar@1
   127
end;