| 1 |
/*** |
| 2 |
!Test |
| 3 |
expected: |
| 4 |
- !Result |
| 5 |
solution: !Solution |
| 6 |
inside: [40, 0, 0] |
| 7 |
objective: 37200 |
| 8 |
outside: [60, 200, 300] |
| 9 |
***/ |
| 10 |
|
| 11 |
% RUNS OM minizinc_cpx |
| 12 |
|
| 13 |
%% Product example from the OPL book! |
| 14 |
%% product_int.mzn |
| 15 |
%% Ralph Becket June 26 2007 |
| 16 |
%% |
| 17 |
%% This is a version of product.mzn changed to use FD integers rather than |
| 18 |
%% LP floats (everything has been scaled up by 10). |
| 19 |
|
| 20 |
%enum Products = {kluski, capellini, fettucine}; |
| 21 |
int: NumProducts = 3; |
| 22 |
set of int: Products = 1..NumProducts; |
| 23 |
int: kluski = 0; |
| 24 |
int: capellini = 1; |
| 25 |
int: fettucine = 2; |
| 26 |
|
| 27 |
%enum Resources = {flour, eggs}; |
| 28 |
int: NumResources = 2; |
| 29 |
set of int: Resources = 1..NumResources; |
| 30 |
int: flour = 0; |
| 31 |
int: eggs = 1; |
| 32 |
|
| 33 |
array[Products] of int: demand = [100, 200, 300]; |
| 34 |
array[Products] of int: insideCost = [60, 80, 30]; |
| 35 |
array[Products] of int: outsideCost = [80, 90, 40]; |
| 36 |
array[Products, Resources] of int: consumption = |
| 37 |
[|5, 2 |
| 38 |
|4, 4 |
| 39 |
|3, 6 |
| 40 |
|]; |
| 41 |
|
| 42 |
array[Resources] of int: capacity = [200, 400]; |
| 43 |
|
| 44 |
% Original specification: |
| 45 |
% |
| 46 |
% array[Products] of var int: inside; |
| 47 |
% array[Products] of var int: outside; |
| 48 |
% |
| 49 |
% Preprocessed one restricting the domains to relevant finite ranges: |
| 50 |
|
| 51 |
array[Products] of var 0..max(capacity): inside; % from constraints 1 and 2 |
| 52 |
array[Products] of var 0..max(demand): outside; % from constraints 1 and 3 |
| 53 |
|
| 54 |
constraint |
| 55 |
forall (p in Products) ( |
| 56 |
inside[p] >= 0 |
| 57 |
/\ outside[p] >= 0 |
| 58 |
); |
| 59 |
|
| 60 |
constraint |
| 61 |
forall(r in Resources) ( |
| 62 |
sum (p in Products) ( |
| 63 |
consumption[p, r] * inside[p] |
| 64 |
) |
| 65 |
<= |
| 66 |
capacity[r] |
| 67 |
); |
| 68 |
|
| 69 |
constraint |
| 70 |
forall(p in Products) ( |
| 71 |
inside[p] + outside[p] >= demand[p] |
| 72 |
); |
| 73 |
|
| 74 |
solve minimize |
| 75 |
sum (p in Products) ( |
| 76 |
insideCost[p]*inside[p] + outsideCost[p]*outside[p] |
| 77 |
); |
| 78 |
|
| 79 |
output [ |
| 80 |
"production planning (FD version)\n", |
| 81 |
" \tkluski\t\tfettucine\tcapellini\n", |
| 82 |
"make inside: \t", |
| 83 |
show(inside[1]), "\t\t", |
| 84 |
show(inside[2]), "\t\t", |
| 85 |
show(inside[3]), "\n", |
| 86 |
"make outside: \t", |
| 87 |
show(outside[1]), "\t\t", |
| 88 |
show(outside[2]), "\t\t", |
| 89 |
show(outside[3]), "\n" |
| 90 |
]; |