this repo has no description
1% RUNS ON mzn20_fd
2% RUNS ON mzn-fzn_fd
3% RUNS ON mzn20_mip
4%-----------------------------------------------------------------------------
5% Warehouse allocation
6% (Problem 034 in CSPLib)
7% vim: ft=zinc ts=2 sw=2 et tw=0
8%
9% Guido Tack, tack@gecode.org
10% 2007-02-22
11%
12% Ported from the Gecode example
13%-----------------------------------------------------------------------------
14% A company needs to construct warehouses to supply stores with goods. Each
15% warehouse possibly to be constructed has a certain capacity defining how many
16% stores it can supply. Constructing a warehouse incurs a fixed cost. Costs
17% for transportation from warehouses to stores depend on the locations of
18% warehouses and stores.
19%
20% Determine which warehouses should be constructed and which warehouse should
21% supply which store such that overall cost (transportation cost plus
22% construction cost) is smallest.
23%-----------------------------------------------------------------------------
24
25include "globals.mzn";
26
27%-----------------------------------------------------------------------------
28% Instance
29
30n_suppliers = 5;
31n_stores = 10;
32building_cost = 30;
33
34capacity = [1,4,2,1,3];
35
36cost_matrix =
37 [|20, 24, 11, 25, 30
38 |28, 27, 82, 83, 74
39 |74, 97, 71, 96, 70
40 | 2, 55, 73, 69, 61
41 |46, 96, 59, 83, 4
42 |42, 22, 29, 67, 59
43 | 1, 5, 73, 59, 56
44 |10, 73, 13, 43, 96
45 |93, 35, 63, 85, 46
46 |47, 65, 55, 71, 95|];
47
48%-----------------------------------------------------------------------------
49% Model
50
51int: n_suppliers;
52int: n_stores;
53int: building_cost;
54array[1..n_suppliers] of int: capacity;
55array[1..n_stores,1..n_suppliers] of int: cost_matrix;
56
57int: MaxCost = max(i in 1..n_stores, j in 1..n_suppliers)(cost_matrix[i,j]);
58int: MaxTotal = (n_suppliers * building_cost)
59 + sum(i in 1..n_stores, j in 1..n_suppliers)(cost_matrix[i,j]);
60
61array[1..n_stores] of var 1..n_suppliers: supplier;
62array[1..n_suppliers] of var bool: open;
63array[1..n_stores] of var 1..MaxCost: cost;
64var 1..MaxTotal: Total;
65
66constraint
67 sum (i in 1..n_suppliers) (building_cost * bool2int(open[i])) +
68 sum (i in 1..n_stores) (cost[i])
69 = Total;
70
71constraint
72 forall (i in 1..n_stores) (
73 cost_matrix[i,supplier[i]] = cost[i]
74 );
75
76constraint
77 forall (i in 1..n_suppliers) (
78 let {
79 var int: use
80 } in
81 count(supplier,i,use) /\ use <= capacity[i]
82 );
83
84constraint
85 forall (i in 1..n_suppliers) (
86 (exists (j in 1..n_stores) (supplier[j] == i)) == open[i]
87 );
88
89solve
90 :: int_search(
91 supplier ++ cost ++ [bool2int(open[i]) | i in 1..n_suppliers],
92 first_fail,
93 indomain_split,
94 complete
95 )
96 minimize Total;
97
98output
99 [ "warehouses:" ]
100 ++
101 [ "\nTotal = ", show(Total) ]
102 ++
103 [ "\nsupplier = [\n" ]
104 ++
105 [ "\t" ++ show(supplier[i]) ++
106 if i = n_stores then "\n]"
107 elseif i mod 5 = 0 then ",\n"
108 else ","
109 endif
110 | i in 1..n_stores
111 ]
112 ++
113 [ "\ncost = [\n" ]
114 ++
115 [ "\t" ++ show(cost[i]) ++
116 if i = n_stores then "\n]"
117 elseif i mod 5 = 0 then ",\n"
118 else ","
119 endif
120 | i in 1..n_stores
121 ]
122 ++
123 [ "\nopen = [\n" ]
124 ++
125 [ "\t" ++ show(open[i]) ++
126 if i = n_suppliers then "\n]\n"
127 elseif i mod 5 = 0 then ",\n"
128 else ","
129 endif
130 | i in 1..n_suppliers
131 ]
132
133%-----------------------------------------------------------------------------
134%-----------------------------------------------------------------------------