Operations Research Letters 22 (1998) 19–25
An integer-programming-based heuristic for the balanced loading problem Kamlesh Mathur ∗ Department of Operations Research, Weatherhead School of Management, Case Western Reserve University, Cleveland, OH 44106, USA Received 1 May 1997; revised 1 July 1997
Abstract This paper presents an ecient heuristic algorithm for the one-dimensional loading problem in which the goal is to pack homogeneous blocks of given length and weight in a container in such a way that the center of gravity of the packed blocks is as close to a target point as possible. The proposed algorithm is based on the approximation of this problem as a knapsack problem. This algorithm has the same computational complexity but a better worst-case performance than the algorithm recently proposed by Amiouny et al. [Oper. Res. 40 (1992) 238]. Moreover, the computational results also show that, in c 1998 Elsevier Science B.V. All rights reserved. general, it performs better on randomly generated problems. Keywords: Integer programming; Heuristic; Balanced loading
1. Introduction Amiouny et al. [1] recently introduced the onedimensional balanced loading problem in which the goal is to pack homogeneous blocks of given length and weight in a one-dimensional container in such a way that the center of gravity of the packed blocks is as close to a target point as possible. The target point is collinear with the container, but need not fall within the container. In their paper they also cited various applications of this problem in loading of the aircraft and trucks. The one-dimensional aspect of this problem assumes that balancing the load is more important along one direction than others. For example, as pointed out ∗
Fax: +1 216 368 4776; e-mail:
[email protected].
c 1998 Elsevier Science B.V. All rights reserved 0167-6377/98/$19.00 PII S 0 1 6 7 - 6 3 7 7 ( 9 7 ) 0 0 0 4 4 - 8
by Amiouny et al., in loading an airplane, balancing the load along longitudinal axis is considered more crucial than along the lateral or vertical axis. Let n = number of blocks to be packed; lj = length of the jth block; wj = weight of the jth block; P j lj = length of the container; p = distance of the target point from the left end of the container; where we assume that the weights and lengths are scaled such that n X j=1
wj = 1
and
n X j=1
lj = 1
20
K. Mathur / Operations Research Letters 22 (1998) 19–25
and the blocks are sequenced in ascending order of their density, that is,
respect to density. That is, if the order of the packing is (I1 ; I2 ; : : : ; In ), then there exists a k, such that
wj wj+1 6 lj lj+1
(wI1 =lI1 )6(wI2 =lI2 )6 · · · (wIk =lIk )
j = 1; 2; : : : ; (n − 1):
The algorithm proposed by Amiouny et al. [1] uses the following steps: Algorithm BALANCE Step 1 : Initialize variables: p0 ← p; M0 ← 0 Step 2 : For j = 1; 2; : : : ; n, do: Place the jth block so that its geometric center is as far as possible from Mj−1 pj ← pj−1 − P n wj i=j
respecting the placement of the previously loaded blocks. Let Mj be the moment about pj induced by the jth block. The worst-case eort of this algorithm is dominated by the O(n log n) eort to sort the blocks in ascending order of their density. Moreover, the authors have shown that if lmax is the length of the longest block to be packed, this algorithm guarantees that the center of gravity of the packed blocks is either within 12 lmax of the target point or else it is as close as possible. In this paper, an alternate heuristic is proposed that also has the computational complexity of O(n log n) but has a better worst-case performance. In particular, it guarantees that the center of gravity of the packed blocks is either within 12 lmax (1 − w1 =l1 ) of the target point or else it is as close as possible. Furthermore, the preliminary computational results show that the proposed algorithm, in general, performs better. In Section 2, the motivation behind the proposed algorithm as well as the algorithmic steps are presented. Section 3 contains the proof of the worst-case performance. Results of a preliminary computational study are summarized in Section 4. 2. Development of the algorithm The idea behind the proposed algorithm comes from the observation that the heuristic BALANCE in Section 1 produces packings that are unimodal with
and (wIk =lIk )¿(wIk+1 =lIk+1 )6 · · · (wIn =lIn ): Even though the optimal packing may not always be unimodal, the proposed heuristic however, attempts to nd the best such unimodal packing. In any unimodal packing, the blocks to the left of the most dense block n will be arranged in non-decreasing order of density, while the blocks to the right of n are arranged in the non-increasing sequence. Let 1 if the jth block is packed to the left of block n; xj = 0 if the jth block is packed to the right of block n. Recalling that the blocks are sequenced in the ascending order of their densities, if the ith block is to the left of the nth block (i.e., xi = 1), then Mil , its moment around the left corner of the container is computed as follows: l1 if i = 1; 2 w1 Mil = i−1 X li lj xj + wi if i = 2; 3; : : : ; (n − 1): 2 j=1
Similarly, if the ith block is to the right of the nth block (i.e., xi = 0), then Mir , its moment around the left corner of the container is computed as follows: n X l1 lj + w1 if i = 1; 2 Mir =
j=2
i−1 n X X li lj xj + lj + wi 2 j=1
j=i+1
if i = 2; 3; : : : ; (n − 1):
Also Mn , the moment of the nth block around the left corner of the container is n−1 X l n lj xj + wn : Mn = 2 j=1
K. Mathur / Operations Research Letters 22 (1998) 19–25
P Using these moments, and recalling that wj = 1, the distance C of the center of gravity from the left corner of the container is C=
n−1 X
[Mil xi + Mir (1 − xi )] + Mn :
(1)
i=1
If we de ne Li =
n X
lj ;
i = 1; 2; : : : ; n
j=i
and Wi =
n X
wj ;
i = 1; 2; : : : ; n;
j=i
then by algebraic manipulation, Eq. (1) can be simpli ed as C=
n−1 X
Ai xi + ;
(2)
i=1
et al. [1], it is easy to prove that in this case this solution is not only optimum for the restricted model for unimodal packing, but is, in fact, optimal for the original loading problem. P n−1 Case 2: If i=1 Ai + ( − p)60, then xi = 1; i = 1; 2; : : : ; (n − 1) is the optimal solution. That is, arrange the blocks in non-decreasing order of the density. Moreover, using the same argument as in Lemma 2 of Amiouny et al. [1], it is easy to prove that in this case this solution is not only optimum for the restricted model for unimodal packing, but is in fact optimal for the original loading problem. P n−1 Case 3: If ( − p)¡0, but i=1 Ai + ( − p)¿0 then the optimal solution to above problem can be found by solving the following two knapsack problems: Max: s:t:
n−1 X
Ai = li Wi+1 − wi Li+1 ;
Ai xi
i=1 n−1 X
Ai xi 6(p − )
i=1
where
xi = 0 − 1; i = 1; 2; : : : ; (n − 1)
i = 1; 2; : : : ; (n − 1)
21
Min: s:t:
n−1 X
Ai xi
i=1 n−1 X
Ai xi ¿(p−)
i=1
xi = 0 − 1; i = 1; 2; : : : ; (n − 1):
The objective is to nd 0−1 values for the variables xi ; i = 1; 2; : : : ; (n − 1) so that the center of gravity is as close to the target point (whose distance from the left end of the container is p) as possibe. That is n−1 X Ai xi + ( − p) : Minimize
For Case 3, rather than solving the knapsack problems – which are NP hard – to optimality, we rely on heuristic procedures. Note that for Case 3, we can pose the problem as: “Given a set of non-negative numbers Ai ; i = 1; : : : ; (n − 1) and a target (p − )¿0 such that P n i=1 Ai ¿(p − P), nd a subset S ⊆ {1; 2; : : : ; (n − 1)} such that i∈S Ai − (p − ) is minimized”. One simple linear time heuristic algorithm suggested by a referee can be: Step 0: Let S = ∅. P Step 1: For k = 1; 2; : : : ; (n − 1), if Ak + i∈S Ai 6 (p − ) + Ak =2 then add k to S. It is easy to see that this heuristic algorithm will terminate with set S that guarantees the following: X Ai − (p − ) 6Ak =2 for some k: (4)
To solve this problem, consider the following three cases: Case 1: If ( − p)¿0, then xi = 0; i = 1; 2; : : : ; (n − 1) is the optimal solution. That is, arrange the blocks in the non-increasing order of density. Moreover, using the same argument as in Lemma 1 of Amiouny
This is precisely the condition needed to prove the worst-case performance of our approach in next section. We, however, propose an alternate heuristic algorithm that computationally performs better. The general idea is to simultaneously pack (n − 1) objects of size Ai ; i = 1; : : : ; (n − 1) in two knapsacks
and =
n−1 X
n
wi Li+1 +
i=1
1X wi li : 2 i=1
Moreover, it is easy to show that n−1 X
Ai = 1 − 2:
(3)
i=1
i=1
i∈S
22
K. Mathur / Operations Research Letters 22 (1998) 19–25
(knapsack-1 and knapsack-2) of capacities (p − ) and (1 − p − ), such that the sum of Ai in knapsack-1 is as close (over or under)Pto its capacity as possible. Note from Eq. (3) that Ai is precisely the sum of the capacities of the two knapsacks. Hence, any complete packing represented by a set S of blocks packed in knapsack-1 and a set S 0 of blocks packed in knapsack-2 satis es the following condition: X X Ai − (p − ) = Ai −(1−p−) : (5) 0 i∈S
i∈S
Also, observe that packing the kth block in knapsack-1 implies xk = 1, that is, pack the kth block to the left of block n. Likewise, packing the kth block in knapsack-2 implies xk = 0, that is, pack the kth block to the right of block n. Based on these observations, the algorithm outlined below, sequentially pack the kth block in the knapsack with the larger remaining capacity (Step 2). However, before packing the kth block, the algorithm checks if packing this block in one knapsack and all the remaining n − k − 1 blocks in other knapsack produces a better packing than the one found so far (Step 1). The algorithm starts with the packing in which all blocks are packed in one knapsack (knapsack-1 or knapsack- 2, which ever is better) as the current best solution (Step 0(c)). Algorithm KNAPSACK Step 0 (Initialization): Compute: Ln = ln ; Li = Li+1 + li ;
i = (n − 1); (n − 2); : : : ; 2; 1
Wn = wn ; Wi = Wi+1 + wi ;
i = (n − 1); (n − 2); : : : ; 2; 1
Ai = li Wi+1 − wi Li+1 ;
=
n−1 X i=1
wi Li+1 +
1 2
n X i=1
i = 1; 2; : : : ; (n − 1)
wi li ;
R1 = (p − ); and
R2 = (1 − 2) − (p − ) = (1 − − p);
where R1 and R2 represents the remaining capacities of the two knapsacks. Check the following cases: (a) If (−p)¿0, stop. In this case xi = 0; i = 1; 2; : : : ; (n − 1) is the optimal solution, that is, arrange thePblocks in the non-increasing order of density. n−1 (b) If i=1 Ai +(−p)60, stop. xi = 1; i = 1; 2; : : : ; (n−1) is the optimal solution, that is, arrange the blocks in the non-decreasing order of density. Pn−1 (c) If ( − p)¡0, but i=1 Ai + ( − p)¿0, then de ne the following current best solution: If R1 ¡R2 xi∗ = 0 i = 1; 2; : : : ; (n − 1) with z ∗ = R1 ; Otherwise xi∗ = 1 i = 1; 2; : : : ; (n − 1) with z ∗ = R : 2
Also set yi = −1 i = 1; 2; : : : ; (n − 1) to indicate that none of the blocks is packed yet. During the algorithm, these values will be changed to 1 or 0 depending on whether the associated object is packed in knapsack-1 or knapsack-2. Initialize k = 1, and go to Step 1. Step 1 (Improving the current best solution): Before deciding in which knapsack the kth block should be packed, check if packing it in one knapsack and remaining n − k − 1 blocks in the other knapsack produces a better packing than the current best solution. In particular, consider following two cases: (a) If |Ak − R1 |¡z ∗ , then packing the kth block in knapsack-1, and the remaining (n − k − 1) blocks in knapsack-2 provides a better current solution. That is, set xi∗ = yi xk∗ = 1; x∗ = 0 i
i = 1; 2; : : : ; (k − 1); (k + 1); : : : ; (n − 1)
with z ∗ = |Ak − R1 |. (b) If |Ak − R2 |¡z ∗ , then packing the kth block in knapsack-2, and the remaining (n − k − 1) blocks in knapsack-1 provides a better current solution.
K. Mathur / Operations Research Letters 22 (1998) 19–25
That is, set xi∗ = yi xk∗ = 0; x∗ = 1 i
i = 1; 2; : : : ; (k − 1);
23
where Li =
n X
lj
j=i
(k + 1); : : : ; (n − 1)
with z ∗ = |Ak − R2 |. In any case, go to Step 2. Step 2 (Packing the kth block): Pack the kth block in the knapsack with the larger remaining capacity. In particular, if R1 ¿R2 , then pack the kth block in knapsack-1, that is, set yk = 1 and change the remaining capacity of the knapsack to R1 = R1 − Ak . Otherwise, pack the block in knapsack-2, that is, set yk = 0, and change its remaining capacity to R2 = R2 − Ak . In any case increment k by 1. If k = n, go to Step 3, otherwise go to Step 1. Step 3 (Constructing the nal packing): Let set S = {i|xi∗ = 1} and S 0 = {i|xi∗ = 0}. Arrange the blocks in set S in the non-decreasing order of their density and pack them to the left of block n, the block with the highest density. Arrange the blocks in set S 0 in the non-increasing order of their density and pack them to the right of the block n. This packing will result in the center of gravity at a distance of z ∗ from the target point. 3. Complexity and worst-case performance of the algorithm Observe that the computational eort is dominated by sorting of blocks required at the beginning when they need to be arranged in the ascending order of their density. Thus, the computational complexity of the algorithm is of the order of O(n log n). To determine the worst-case performance requires the following two lemmas pertaining to the value Ai computed in previous section for each block. Lemma 1. 06Ai 6lmax −nlmin wmin ; where lmin is the length of the shortest block; and wmin is the weight of the lightest block. Proof. Recall that Ai = li Wi+1 − wi Li+1 ;
and Wi =
n X
wj :
j=i
Since wi =li 6wi+1 =li+1 , Pn wi Wi+1 j=i+1 wj = Pn ¿ : Li+1 li l j j=i+1 Thus, li Wi+1 − wi Li+1 ¿0 To prove the upper bound: Ai = li Wi+1 − wi Li+1 i n X X = li − li wj + wi lj j=1
j=i+1
6lmax − (ilmin wmin + (n − i)lmin wmin ) = lmax − nlmin wmin : Lemma 2. (Ai =li )¿(Ai+1 =li+1 ). Proof. By algebraic manipulation it is easy to show that Ai+1 wi Ai wi+1 Li+1 : − = − li li+1 li+1 li Since wi =li 6wi+1 =li+1 , and Li+1 ¿0, above equation gives Ai+1 Ai − ¿0: li li+1 Using Lemmas 1 and 2, now it is easy to prove the following theorem. Theorem 1. If lmax is the length of the largest block; then the proposed heuristic either produces an optimal packing or guarantees that the center of gravity of the packed blocks is within 12 lmax (1 − w1 =l1 ) of the target point.
24
K. Mathur / Operations Research Letters 22 (1998) 19–25
Proof. If the algorithm terminates in either Step 0(a) or Step 0(b), then the algorithm Pn−1produces the optimal packing. Otherwise, since i=1 Ai xi ¿(p−), all blocks together exceed the capacity of the knapsack-1. It is easy to argue that in the nal solution produced by the algorithm, for some k,
generated. For each problem, if:
Dierence between the center of gravity of the blocks and the target 6 12 Ak : point
then the problem has trivial solution if the target point is below tl or is higher than tm . Thus each problem was solved four times with target point at tl + 0:125t, tl + 0:250t, tl + 0:375t, and tl + 0:500t, where t = tm − tl . For the 400 problems thus solved, KNAPSACK algorithm produced better solution for 85 problems, where as for the remaining 315 problems, the solution from both these algorithms had the same objective function value. We were surprised that BALANCE did not nd a better solution for any of the problems. Same result was observed for another set of 400 problems. This leads us to an interesting conjecture that even though the two algorithms use dierent concepts and ideas, and has no similarity in their algorithmic steps, KNAPSACK without step 1 somehow is identical to BALANCE but checks in Step 1 results in a better solution for some problems. Also, unlike BALANCE which is somewhat rigid in its implementation, the ideas behind KNAPSACK provides us with a foundation for alternate heuristic procedures. For example, one possible variation is to resort the objects (at the cost of additional sorting) in the descending order of their Ai values. This variation when applied to the same 400 problems as above, gave a better solution than BALANCE for 236 problems, the same solution for 33 problems, but a worse solution for the remaining 131 problems. Since all algorithms (BALANCE as well as variations of KNAPSACK) are computationally very fast, for practical applications one may use some or all of them and select the best solution.
This is because, if in the nal solution, the sum of the Ai of the objects packed in knapsack-1 (i.e., xi∗ = 1) exceeds its capacity, then the last object packed in the knapsack satis es above inequality – otherwise, the packing without it would have given a better solution. Similarly, if the sum of the Ai of the objects packed in knapsack-1 is below its capacity, then the last object packed in the knapsack-2 satis es above inequality – otherwise, at that point in the algorithm, packing this job in knapsack-1 would have given a better solution in Step 1(a). Lemma 1, therefore, provides an immediate worst-case performance of within 12 (lmax −nlmin wmin ). Lemma 2 however, provides a slightly stronger bound: Dierence between the 1 center of gravity of the 6 Ak blocks and the target 2 point 1 Ak = lk 2 lk 1 A1 6 lmax 2 l1 w1 1 1− lmax : = 2 l1
4. Computational results Both algorithms KNAPSACK and BALANCE were programmed and compared on randomly generated problems. The problems were generated with numbers of blocks ranging from 5 to 100 in increments of 5. For each block in a problem, the length li was generated uniformly in the range [30, 90], and the density wi =li uniformly between [1, 18]. For each problem size (number of blocks), 5 problems were
tl = center of gravity if the blocks are packed in descending order of the density, tm = center of gravity if the blocks are packed in ascending order of the density,
5. Extension: length of the container exceeds
P
lj
In this paper we P assumed that the length of the container is exactly lj . This algorithm can be trivially extended to the case where the length of the container is say, b units longer than needed. In this case, apply the above algorithm by considering the “left corner” as (b=2) units to the right of the actual corner. Once the solution is obtained, move the entire
K. Mathur / Operations Research Letters 22 (1998) 19–25
packing left or right (with a maximum of (b=2) units) to improve the solution. This results in a worst-case bound of max{0; 1=2[lmax (1 − w1 =l1 ) − b]}. The same idea of course can be used in BALANCE, resulting in a worst case bound of max{0; 1=2[lmax − b]}. Another approach might be to apply the algorithm by iteratively moving the left corner to the right in small steps. In KNAPSACK, this requires changing only the
25
capacities of the knapsacks. In contrast, BALANCE will have to start from scratch.
References [1] S. Amiouny, J.J. Bartholdi, J.H. Vande Vate, J. Zhang, Balanced loading, Oper. Res. 40 (2) (1992) 238 –246.