A Simple and Effective Decomposition for the Multidimensional Binpacking Constraint Stefano Gualandi1 and Michele Lombardi2 1
2
Universit` a di Pavia, Dipartimento di Matematica Universit` a di Bologna, Dipartimento di Informatica: Scienza ed Ingegneria
[email protected],
[email protected]
Abstract. The multibin packing constraint captures a fundamental substructure of many assignment problems, where a set of items, each with a fixed number of dimensions, must be assigned to a number of bins with limited capacities. In this work we propose a simple decomposition for multibin packing that uses a bin packing constraint for each dimension, a set of all different constraints automatically derived from a conflict graph, plus two alternative symmetry breaking approaches. Despite its simplicity, the proposed decomposition is very effective on a number of instances recently proposed in the literature.
1
Introduction
Given a set I = {1, . . . , n} of items and a set K = {1, . . . , k} of dimensions, where each item i has a weight wi,l for every dimension l, and given a set B = {1, . . . , m} of bins j with a capacity cj,l for every dimension l, the multibin packing constraint states that every item must be packed into a single bin while the sum of weights for each bin and for each dimension cannot exceed the corresponding bin capacity. In particular, we extend the formulation of the bin packing constraint from [10] by using the following signature: multibin packing([yj,l ], [xi ], [wi,l ])
(1)
where xi = j if item i is assigned to bin j and yj,l is a load variable ranging in [0, cj,l ] that represents the total weight packed on bin j for dimension l. Indeed, the semantic of constraint (1) is equivalent to the following relations:
wi,l = yj,l ≤ cj,l
∀j ∈ B, ∀l ∈ K.
(2)
i∈I:xi =j
The case of a single dimension k = 1 reduces (1) to the well-known bin packing constraint. Therefore, a natural decomposition of (1) is to use a single bin packing for each dimension as follows: bin packing([y1,l , . . . , ym,l ], [xi ], [wi,l ]) C. Schulte (Ed.): CP 2013, LNCS 8124, pp. 356–364, 2013. c Springer-Verlag Berlin Heidelberg 2013
∀l ∈ K.
(3)
Effective Decomposition for the Multidimensional Binpacking Constraint
357
This decomposition is used for instance in [6] to formulate the Machine Reassignment problem proposed in the Roadef Google Challenge 20121 . In the Machine Reassignment problem, each item represents an application to be (re)assigned to a server, and each dimension represents a resource consumed by an application, such as, for instance, CPU time, memory, and bandwidth. Since every server has a limited capacity for each resource, the multibin packing constraint captures a fundamental substructure of the Machine Reassignment problem. In [2], the authors propose a constraint based on Multivalued Decisions Diagrams (MDD) for multidimensional bin packing problems and they show that the approach is very effective on a set of randomly generated instances. The MDD approach definitely outperforms a basic CP model based on decomposition (3) and solved with a basic first-unassigned min-value branching strategy. In several cases, the model with the MDD constraint outperforms a Mixed Integer Programming approach as well. In particular, the MDD approach is attractive for hard instances on the transition phases from infeasible to feasible, likely due to the ability of MDD to handle symmetries. While their approach is very interesting, it is hard to embed into existing CP solvers. The first filtering algorithm for the bin packing constraint was presented by Shaw in [10], where the author combined the algorithm for the Knapsack constraint introduced in [11] with a well-known lower bound on the minimum bin packing problem (e.g., see Chapter 10 in [5]). Shaw’s algorithm is implemented in several CP solvers, it is listed in the global constraint catalog [1], and it is useful for several industrial applications (e.g., see [9]). The contribution of this paper is to propose a simple decomposition for the multibin packing constraint that, in addition to constraints (3), uses a collection of all different constraints automatically derived from a conflict graph, and that posts symmetry breaking constraints. The benefits of the all different constraints are twofold: they perform additional filtering and they help the branching to identify “most-conflicting” variables. We show experimentally that our approach is very effective on the instances recently presented in [2]. Since the proposed multibin packing decomposition is based on existing constraints, it can be easily implemented in any existing CP solver. The outline of the paper is as follows: Section 2 introduces the problem decomposition, while Section 3 presents two alternative symmetry breaking strategies. Section 4 reports computational results and concludes the paper.
2
Constraint Decomposition
The multibin packing constraint naturally decomposes into k independent bin packing constraints. However, this basic decomposition does not account for the different dimensions of each item: while two items may fit in the same bin while considering a given dimension l1 , they may be in conflict while considering a different dimension l2 , since the sum of their weights might exceed the 1
http://challenge.roadef.org/2012/en/, last visited April, 24-th, 2013.
358
S. Gualandi and M. Lombardi
bin capacity for l2 . However, the interdependencies among the item dimensions across the bins can be exploited systematically via a conflict graph. Given an instance of the multibin packing constraint, we build an undirected conflict graph G = (V, E) by looking for pairs of conflicting items. The conflict graph G is constructed as follows. First, for each item i in I, we add a vertex to V : we have a one-to-one mapping between items and vertices of G. Second, we add an edge {i1 , i2 } to E for each pair of items with i1 , i2 ∈ I and i1 < i2 , and such that the following relation holds: ∀j ∈ B.
∃l ∈ K :
wi1 ,l + wi2 ,l > cj,l
(4)
Indeed, two items i1 and i2 are in conflict if for each bin there exists at least a dimension l such that the sum of the two item weights exceed the bin capacity for dimension l. We show next how we use the conflict graph. Recall that a clique is complete subgraph of G, and that a clique is maximal if it is not a subset of any other clique. Given a subset of items J ⊆ I, we denote by xJ the subset of the [xi ] variables corresponding to the items in J. Proposition 1. Given an instance of multibin packing, the cardinality ω(G) of the maximum clique, denoted by C ∗ , of the conflict graph gives a lower bound on the number of bins necessary in any feasible assignment of items to bins. Clearly, every pair of items corresponding to vertices in C ∗ must be assigned to different bins, therefore we need at least ω(G) bins to have a feasible assignment. However, we do not really need a maximum clique in order to detect infeasibility, as shown next. Proposition 2. Given an instance of multibin packing, if the conflict graph G contains a clique C of cardinality strictly greater than the number of available bins, that is |C| > m, then the multibin packing constraint cannot hold. Therefore, to declare infeasibility of a given instance of multibin packing, we are interested in a finding clique of cardinality equal to m + 1. Despite finding a clique of a given size is an NP-complete problem [3], we have that m n and that the conflict graph is sparse (otherwise the multibin packing instance would be likely infeasible). In practice, exact algorithms (e.g., see [7]) are extremely efficient in checking if a clique of size m + 1 exists in the multibin packing instances taken from the literature. For easy instances, the set of edges E may even be empty. It is possible to exploit the cliques in G for more than pure consistency checking. Specifically, since for any clique C with 1 < |C| ≤ m, it is possible to post an all different constraint on the item variables corresponding to the vertices in the clique. More formally: Proposition 3. Given an instance of multibin packing, every subset J ⊂ I of items corresponding to vertices of any (maximal) clique C of G, with 1 < |C| ≤ m, must be assigned to different bins, that is the corresponding subset of item variables xJ must take a different value: all different([xJ ]) must hold.
Effective Decomposition for the Multidimensional Binpacking Constraint
359
The proposition holds for any clique, but it is better to consider maximal cliques only, since they are fewer in number. While the number of maximal cliques of G is, in theory, exponential in the number of vertices, in many practical cases their number is definitely reasonable. In addition, we are not forced to list every maximal cliques, and it is easy to devise heuristics that limit the number of cliques considered. For instance, it is possible to look for every vertex i of G a maximal clique that contains vertex i. Simple greedy heuristics for finding maximal cliques have worst-case time complexity of O(n2 ).
3
Symmetry Breaking
In case the bins have identical capacities for every dimension, that is whenever cjl = cl for all j in B, and in case there is not other special constraint nor costs on the assignment of items to bins, then the multibin packing constraint admits several symmetric assignments, since every possible permutation of bin assignment gives equivalent solutions. For instance, given a feasible assignment, if we exchange all the items assigned to the first bin with all the items assigned to the second bin, we get another feasible solution. This kind of situation seems to occur quite often in practice. 3.1
Symmetry Breaking by Variable Fixing
In order to partially break symmetries, we can again exploit the conflict graph G. In practice, we can take the largest clique C with cardinality smaller than or equal to m (otherwise the constraint is infeasible) and we can fix every item variable corresponding to vertices in C to a different value from its own domain. Let dom(xi ) be the domain of variable xi ; initially, every variables has the same domain. We take the first variable in C, and we assign it the minimum value in its domain; then we take the second variable in C and we assign it the second value in its domain; and so on. With a small abuse of notation, we write: xi ← min{dom(xi )}
for i ∈ C.
(5)
where after each assignment, propagation reduces the other variable domains. Note that whenever it is possible to use this variable fixing technique, then, once the variables have been fixed and all other problem constraints have propagated, it is possible to construct a new conflict graph G using the residual bin capacity obtained by considering the fixing in (5). The new conflict graph can again be used for consistency checking and, likely, to post additional all different constraints. 3.2
Symmetry Breaking Constraints
If the assignment of items to bins is symmetrical, as discussed previously, a different but standard way to break symmetries during search consists in posting
360
S. Gualandi and M. Lombardi
an additional constraint that invalidates equivalent feasible assignments (e.g., see Chapter 10 in [8]). If we consider a single dimension l, for instance the first dimension l = 1, we can post an ordering constraint on the corresponding subset of load variables: yj,1 ≥ y(j+1),1
∀j ∈ {1, . . . , m − 1}.
(6)
However, no ordering constraint can be posted on the other load variables. Note that constraint (6) reduces the number of equivalent feasible assignments of items to bins, and therefore on easy instances of multibin packing it might have a negative effect when looking for a single feasible solution. We will discuss this issue in the computational results section. The symmetry breaking constraints based on (6) are only applicable when every bin has the same capacity for every dimension. If we perform an itembin variable fixing for statically break some symmetries, as described in Section 3.1, we are in practice modifying the problem and, as a consequence, the bins have no longer an identical capacity for each dimension. For this reason, the two symmetry breaking strategies are incompatible.
4
Computational Results
In order to evaluate our approach, we have implemented the proposed decomposition of multibin packing within the Gecode constraint system v.3.7.3 [4]. Note that Gecode has a very efficient implementation of the Shaw’s Bin Packing constraint [10]. In order to list every maximal cliques of the conflict graph we used cliquer-1.21 that is the state-of-the-art exact clique finder for sparse graphs [7]. Everything was compiled using the gnu-gcc v4.7.2 compiler. All the tests were run on standard computer with Linux as operating system, with 4GB of RAM and an AMD Opteron 2.4GHz CPU, but using a single thread and limiting the process memory size to 1GB. Our implementation of the constraint decomposition is available online2 . We have run experiments using combinations of the following decomposition: multibin packing([yj,l ], [xi ], [wi,l ]) = bin packing([y1,l , . . . , ym,l ], [xi ], [wi,l ]) all different([xC ]) yj,1 ≥ y(j+1),1
∀l ∈ K
(7)
∀C ∈ C ∀j ∈ {1, . . . , m − 1}
(8) (9)
where C is the collection of all maximal cliques of the conflict graph defined for the given instance of multibin packing. We denote by: (A) the decomposition using only constraints (7) (B) the decomposition using constraints (7) and (8) 2
http://github.com/stegua/binpacking/tree/master/release
Effective Decomposition for the Multidimensional Binpacking Constraint
361
(C) the decomposition using constraints (7) and (9) (D) the decomposition using constraints (7), (8), and (9) (E) the decomposition using constraints (7), (8), and (5) The rationale for studying decompositions (B) and (C) is to assess the impact of the additional constraints (7) and (8), and for decompositions (D) and (E) is to compare the two alternative symmetry breaking strategies. In order to make a fair comparison between the different decomposition strategies, in our computational results, we did not update the conflict graph for strategy (E). In practice, constraints (8) are posted on the same collection of maximal clique for method (B), (D), and (E). We consider a set of instances taken from [2] that corresponds to randomly generated instances with 18 items, 6 dimensions, and 6 bins. In order to have a range of instances from “easy infeasible” to “easy feasible” while passing through a “hard” phase transition, the instances differ on the tightness of the bin capacities (i.e. the bin slacks), according to a parameter β (for the details on the instances generation see [2]). The values of β range in {0, . . . 35}, and for each value of β there are 52 instances, for a total of 1872. The phase transition happens for β ∈ {16, . . . , 24}. Figures (1.a)–(1.d) show the average computation times in seconds (vertical axis) in function of the percentage of bin slacks, that is, for value of β from 0 to 35. Plot (1.a) clearly shows that the hard instances correspond to values of β ranging from 15 to 25, while the plots (1.b)–(1.d) show that: – For the hard instances (1.b) and the easy infeasible instances (1.c) the decomposition (E) that exploits both the all different constraints and the variable fixing on the maximum clique, outperforms the other decompositions by a large margin: the average computation time is below 1 second also for the instances with β = 20, and, hence, it is a simple and effective alternative to the multibin packing constraint based on Multivalues Decision Diagrams proposed in [2]. – For the easy infeasible (1.c) and the easy feasible instances (1.d), the symmetry breaking constraint (9) does not always pay off, while it plays an important role on the hard instances (1.b), since decomposition (C) and (D) are always more efficient than (A) and (B). – As expected, for the easy feasible instances (1.d), the simplest decomposition (A) is quite efficient, since in this case the filtering algorithms play a minor role. Figures (2.a) and (2.b) give a different view of the same results by showing the empirical cumulative distributions of the fraction of instances solved as a function of the run times. Figure (2.a) are the distributions for all the 1872 instances proposed in [2], while Figure (2.b) considers only the instances with β = 20, i.e. among the hardest instances. Again decomposition (E) outperforms all the others by a large margin. The decomposition (B) based on the all different constraints outperforms the simple decomposition (A) for a large number of instances, but not for all of them. The decomposition (C) and (D) that exploit
362
Avg. Computation Time (sec)
80
60
S. Gualandi and M. Lombardi
102
(A) k binpacking (B) A + alldifferent (C) A + sym.b.const. (D) B + C (E) B + var.fixing
101
40
100
20
10−1
10−2
0 0
5
10
15
20
25
30
35
16
17
Avg. Computation Time (sec)
(a) Percentage of bin slack (Phase transition)
18
19
20
21
22
23
24
(b) Percentage of bin slack (hard instances)
101
101
100
100
10−1
10−1
10−2
10−2
10−3
10−3 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
25
(c) Percentage of bin slack (easy infeasible instances)
26
27
28
29
30
31
32
33
34
35
(d) Percentage of bin slack (easy feasible instances)
Fraction of instances solved
Fig. 1. Average Computation Time vs. Percentage of Bin Slack
1.0
1.0
0.9
0.9
0.8
0.8
0.7
0.7
0.6
0.6
0.5
0.5
0.4
0.4
0.3
0.3
(A) k binpacking (B) A + alldifferent
0.2
0.2
(C) A + sym.b.const. (D) B + C
0.1
0.1
(E) B + var.fixing
0.0
0.0 10−2
10−1
100
101
(a) Computation time in seconds (all 1872 instances)
102
10−2
10−1
100
101
102
(b) Computation time in seconds (bin slack 20%, 52 instances)
Fig. 2. Empricial Cumulative Distribution of the fraction of instances solved as a function of computation times
Effective Decomposition for the Multidimensional Binpacking Constraint
363
Average number of cliques Average clique size
19 17 15 13 11 9 7 5 3 1 0
5
10
15
20
25
30
35
Percentage of bin slack
Fig. 3. Average number of cliques and average clique size vs. bin slacks
the symmetry breaking constraints are useful on the hard instances, as shown in Figure (2.b), but in some cases the overhead of constraints (9) does not pay off. Finally, since the main contribution of our approach is based on detecting maximal cliques in the conflict graph and on posting an all different constraint for every clique found, Figure 3 characterizes the instances in terms of average clique number and average clique size as a function of the bin slack. Note that for the easy infeasible instances (i.e. β < 15), there are many and large cliques, while for the easy feasible instances (i.e. β > 25) the cliques are few and rather small (sometimes are not even present). Clearly, our decomposition approach is better suited for instances with several large cliques.
References 1. Beldiceanu, N., Carlsson, M., Rampon, J.X.: Global constraint catalog. SICS Research Report (2005) 2. Kell, B., van Hoeve, W.-J.: An MDD approach to multidimensional bin packing. In: Gomes, C., Sellmann, M. (eds.) CPAIOR 2013. LNCS, vol. 7874, pp. 128–143. Springer, Heidelberg (2013) 3. Garey, M.R., Johnson, D.S.: Computers and intractability. Freeman, New York (1979) 4. Gecode Team. Gecode: Generic constraint development environment (2013), http://www.gecode.org 5. Martello, S., Toth, P.: Knapsack problems: algorithms and computer implementations. John Wiley & Sons, Inc. (1990) 6. Mehta, D., O’Sullivan, B., Simonis, H.: Comparing solution methods for the machine reassignment problem. In: Milano, M. (ed.) CP 2012. LNCS, vol. 7514, pp. 782–797. Springer, Heidelberg (2012) ¨ 7. Osterg˚ ard, P.R.J.: A fast algorithm for the maximum clique problem. Discrete Applied Mathematics 120(1), 197–207 (2002)
364
S. Gualandi and M. Lombardi
8. Rossi, F., Van Beek, P., Walsh, T.: Handbook of constraint programming. Elsevier Science (2006) 9. Schaus, P., R´egin, J.-C., Van Schaeren, R., Dullaert, W., Raa, B.: Cardinality reasoning for bin-packing constraint: Application to a tank allocation problem. In: Milano, M. (ed.) CP 2012. LNCS, vol. 7514, pp. 815–822. Springer, Heidelberg (2012) 10. Shaw, P.: A constraint for bin packing. In: Wallace, M. (ed.) CP 2004. LNCS, vol. 3258, pp. 648–662. Springer, Heidelberg (2004) 11. Trick, M.A.: A dynamic programming approach for consistency and propagation for knapsack constraints. Annals of Operations Research 118(1), 73–84 (2003)