Debian Codegraph @

tests/spec/examples/product_lp.mzn

raw
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_lp.mzn
15 %% Ralph Becket June 26 2007
16 %%
17 %% This is a version of product.mzn changed to use LP integers rather than
18 %% LP floats (everything has been scaled up by 10).
19
20 % This isn't needed, as "lp" is a built-in annotation in the G12
21 % implementation (although it's not listed as such in the Zinc spec).
22 %annotation lp;
23
24 %enum Products = {kluski, capellini, fettucine};
25 int: NumProducts = 3;
26 set of int: Products = 1..NumProducts;
27 int: kluski = 0;
28 int: capellini = 1;
29 int: fettucine = 2;
30
31 %enum Resources = {flour, eggs};
32 int: NumResources = 2;
33 set of int: Resources = 1..NumResources;
34 int: flour = 0;
35 int: eggs = 1;
36
37 array[Products] of int: demand = [100, 200, 300];
38 array[Products] of int: insideCost = [60, 80, 30];
39 array[Products] of int: outsideCost = [80, 90, 40];
40 array[Products, Resources] of int: consumption =
41 [| 5, 2
42 | 4, 4
43 | 3, 6
44 |];
45
46 array[Resources] of int: capacity = [200, 400];
47
48 array[Products] of var int: inside;
49 array[Products] of var int: outside;
50
51 constraint
52 forall (p in Products) (
53 inside[p] >= 0
54 /\ outside[p] >= 0
55 );
56
57 constraint
58 forall(r in Resources) (
59 sum (p in Products) (
60 consumption[p, r] * inside[p]
61 )
62 <=
63 capacity[r]
64 );
65
66 constraint
67 forall(p in Products) (
68 inside[p] + outside[p] >= demand[p]
69 );
70
71 solve minimize
72 sum (p in Products) (
73 insideCost[p]*inside[p] + outsideCost[p]*outside[p]
74 );
75
76 output [
77 "production planning (LP version of integer model)\n",
78 " \tkluski\t\tfettucine\tcapellini\n",
79 "make inside: \t",
80 show(inside[1]), "\t\t",
81 show(inside[2]), "\t\t",
82 show(inside[3]), "\n",
83 "make outside: \t",
84 show(outside[1]), "\t\t",
85 show(outside[2]), "\t\t",
86 show(outside[3]), "\n"
87 ];