A polynomial time algorithm for unloading boxes off

Discrete Optimization 10 (2013) 251–262
Contents lists available at ScienceDirect
Discrete Optimization
journal homepage: www.elsevier.com/locate/disopt
A polynomial time algorithm for unloading boxes off a
gravity conveyor
Pierre Baptiste a , Alain Hertz a,∗ , André Linhares a , Djamal Rebaine b
a
Département de Mathématiques et Génie Industriel, École Polytechnique de Montréal. C.P. 6079, succ. Centre-ville. Montréal (Québec),
Canada, H3C 3A7
b
Département d’informatique et de Mathématique, Université du Québec à Chicoutimi, Chicoutimi (Québec), Canada, G7H 2B1
article
info
Article history:
Received 4 October 2012
Received in revised form 10 July 2013
Accepted 19 July 2013
Available online 22 August 2013
Keywords:
Dynamic programming
Gravity conveyor
Boxes
Unloading
abstract
In this paper, we study the problem introduced by Baptiste et al. (2011) [3] of minimizing
the number of steps to unload a set of boxes off a gravity conveyor. We show that this
problem can be solved
in polynomial time with a dynamic programming algorithm that

runs in O n3 A log F time, where n is the number of boxes initially lined up on the conveyor,
A is the size of the accessible zone, and F is the forklift capacity.
© 2013 Elsevier B.V. All rights reserved.
1. Introduction
A finite number of boxes are placed on a gravity conveyor, as shown in Fig. 1. Each box has a destination, and boxes with
different destinations are depicted with different colors. A forklift driver needs to unload all these boxes from the conveyor
and move them to their corresponding destinations. At each step, he picks a contiguous group of boxes with the same color.
The number of such boxes is restricted by the forklift capacity.
At any given step, only some of the boxes – those in the accessible zone, shown in Fig. 1 – can be removed from the
conveyor. As a contiguous group of boxes is unloaded, a gap is momentarily formed. It is immediately filled by the boxes
to its right (which are positioned at a higher height), which slide down. This movement leads to new boxes entering the
accessible zone.
The order in which boxes are unloaded can greatly influence the amount of time needed before all of them are moved
to their corresponding destinations. Our goal is to develop strategies which unload the gravity conveyor in as few moves as
possible. We prove that this problem can be solved in polynomial time with a dynamic programming algorithm.
The paper is organized as follows. Previous work on the considered problem is summarized in Section 2, while definitions
and notations are given in Section 3. The proposed dynamic programming algorithm is described in Section 4, and illustrated
on an example in Section 5. Concluding remarks are given in Section 6.
∗
Corresponding author. Tel.: +1 514 340 6063; fax: +1 514 340 5665.
E-mail addresses: [email protected] (P. Baptiste), [email protected] (A. Hertz), [email protected] (A. Linhares), [email protected]
(D. Rebaine).
1572-5286/$ – see front matter © 2013 Elsevier B.V. All rights reserved.
http://dx.doi.org/10.1016/j.disopt.2013.07.004
252
P. Baptiste et al. / Discrete Optimization 10 (2013) 251–262
Fig. 1. Unloading boxes off a gravity conveyor.
2. Previous work
The problem has been met in a company that produces household appliances. Many decisions had to be considered
simultaneously: production sequencing (batch sizing and sequencing), sequencing of outgoing semi-trailers, dock allocation,
and finally scheduling of forklift activity. This last decision appeared less critical. Moreover, the forklift driver does not use
a computer and has to adapt his behavior to real-time modifications such as local order inversions and delays in semitrailer movements. Both production scheduling and semi-trailers sequencing have been modeled as a cross-docking problem
(Maknoon and Baptiste [1], Larbi et al. [2]).
The problem of scheduling the forklift activity has been modeled recently. The practical goal is not to solve the problem
to optimality for a given sequence, because, in reality, the sequence of products is not known beforehand, and is built in
real time. However, this task requires substantial overtime, and drivers are paid according to the time spent on the shop
floor. It is therefore important to evaluate the quality of the strategies used by the forklift drivers, and this can be done by
comparing them with the optimal strategy.
A first binary linear programming formulation of the problem was proposed by Baptiste et al. [3]. This model is mainly
based on two indices: i ∈ {1, . . . , n} for the boxes to be unloaded (which are labeled in increasing order from left to right),
and j ∈ {1, . . . , n} for unloading moves (numbered in the order in which they are performed). It has four families of boolean
variables:
•
•
•
•
xi,j indicates whether box i is unloaded during move j;
ai,j indicates whether a box with a label strictly smaller than i is unloaded during move j;
bi,j indicates whether a box with a label strictly larger than i is unloaded during move j;
yj indicates whether a j-th move is performed.
n
The objective is to minimize j=1 yj under the following constraints, where F is the capacity of the forklift, A is the size
of the accessible zone, and c (i) denotes the color of box i:
xk,j ≤ ai,j
∀j, ∀k < i
(1)
xk,j ≤ bi,j
∀j, ∀i < k
(2)
xi,j ≤ yj
∀i, ∀j
(3)
yj ≤ yℓ
∀ℓ < j
(4)
xi,j + xk,j ≤ 1 ∀j, ∀i, k with c (i) ̸= c (k)
n

(5)
xi,j = 1 ∀i
(6)
xi,j ≤ F
(7)
j=1
n

∀j
i =1
ai,j + bi,j ≤ 2 −
n

ℓ=j+1
xi,ℓ
∀i, ∀j
(8)
P. Baptiste et al. / Discrete Optimization 10 (2013) 251–262
253
Fig. 2. Instance I ex = (10, 4, 3, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), c ex ).
i−
j −1
i−1 

xk,ℓ ≤ A + (i − A) 1 − xi,j


∀i, ∀j.
(9)
k=1 ℓ=1
Constraints (1)–(4) link the variables. Constraint (5) imposes that two boxes which have distinct colors cannot be
unloaded during the same move. Constraint (6) indicates that every box must be unloaded exactly once, while Constraint
(7) makes sure that no more than F boxes are unloaded in one move.
The most interesting constraints are the last two ones. Constraint (8) expresses the fact that if a box i has a predecessor
and a successor that are unloaded in the same move j, then this box has to be unloaded during or before move j. Finally,
Constraint (9) imposes that if a box i is unloaded during move j, then at least i − A boxes on the left of i have to be unloaded
before move j, otherwise box i would not be accessible after the first j − 1 unloading moves. As shown in [3], this model only
allows the solution of small instances.
Several properties and dominance results are also proved in Baptiste et al. [4], and it is shown that if the forklift capacity
and the size of the accessible zone are infinite, then the problem can be solved in polynomial time. The authors also propose
a dynamic programming approach that allows the solution of instances with up to 300 boxes when the capacity F of the
forklift is limited to 3, the size A of the accessible zone is limited to 10, and the number of colors is smaller than 4. For such
instances, the running time ranged from one minute to 56 h, with an average of 5.7 h. Although we postpone numerical
experiments to a subsequent paper, we point out that the algorithm presented here is able to solve these same instances in
a few seconds.
3. Notation and definitions
Each box has an identifier b ∈ N. An instance of the problem is characterized by a tuple
I = (n, A, F , (b1 , . . . , bn ) , c ) ,
where n ∈ N is the number of boxes lined up on the conveyor; A ∈ N∗ is the size (in number of boxes) of the accessible
zone; F ∈ N∗ is the forklift capacity; (b1 , . . . , bn ) ∈ Nn are the boxes lined up on the conveyor (listed from left to right); and
c : {b1 , . . . , bn } → N is a function which assigns to each box bi (i ∈ {1, . . . , n}) a color c (bi ).
In order to illustrate these definitions with an example, let c ex : {1, . . . , 10} → N be a function such that c ex (1) =
c ex (4) = c ex (7) = c ex (8) = 1, c ex (2) = c ex (5) = c ex (9) = c ex (10) = 2, and c ex (3) = c ex (6) = 3. The instance
I ex = (10, 4, 3, (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), c ex ) is depicted in Fig. 2, where colors 1, 2, and 3 are drawn respectively as
white, gray, and black.
At any given time, the list of the boxes that remain on the conveyor, from left to right, defines a state x = (x1 , . . . , xn′ ).
We denote by |x| = n′ the number of boxes in state x. The initial state is (b1 , . . . , bn ), and the final state is ().
A valid move consists in choosing a contiguous group of at most F boxes having the same color and belonging to
 the
accessible zone. It can thus be characterized by a pair of indices σ = (i, j) such that 1 ≤ i ≤ j ≤ min i + F − 1, n′ , A and
c (xi ) = c (xi+1 ) = · · · = c xj . We denote by Σ (x) the set of valid moves for state x. If σ = (i, j) ∈ Σ (x), then applying
move σ leads to a new state σ (x) = (x1 , . . . , xi−1 ) ⊙ (xj+1 , . . . , xn′ ), where ⊙ is the concatenation operator.
A strategy for instance I is an alternating sequence of states and moves which clears the conveyor, that is, a sequence
S = (x0 , σ1 , x1 , . . . , σm , xm ) such that:
 
•
•
•
•
x0 = (b1, . . . , bn );
σt ∈ Σ xt −1 , for all t ∈ {1, . . . , m};
xt = σt xt −1 , for all t ∈ {1, . . . , m}; and
xm = ().


We define |S | = m to be the number of moves in strategy S, and S (I ) to be the set of strategies for an instance I. Our goal
is to find a strategy with the minimum number of moves, that is, we want to compute the quantity OPT(I ) = minS ∈S (I ) |S |.
Equivalently, our goal is to maximize the number of moves we save with respect to the trivial strategy, which consists
in unloading the boxes one by one. If we define G(S ) = n − |S | to be the gain of strategy S, then we want to compute
G (I ) = maxS ∈S (I ) G(S ) = n − OPT(I ).
Note that, a move can also be defined by using
the identifiers of the leftmost and the rightmost box it unloads (instead

of their current positions). Thus a strategy x0 , σ1 = (i1 , j1 ) , x1 , . . . , σm = (im , jm ) , xm can also be represented as the
sequence

 

−1 m−1
x0i1 , x0j1 , x1i2 , x1j2 , . . . , xm
im , xjm


, called its compact representation.
254
P. Baptiste et al. / Discrete Optimization 10 (2013) 251–262
Fig. 3. Instance I3,6,3 .
4. A dynamic programming algorithm
Let us consider an instance I = (n, A, F , (b1 , . . . , bn ) , c ). Without loss of generality, assume that (b1 , . . . , bn ) = (1,
. . . , n). Assume also that A ≥ 2 and F ≥ 2 (otherwise, the problem is trivial), and that A ≤ n (if we had A > n, then all boxes
would be in the accessible zone, and reducing the size of this zone to n would clearly not change the problem).
Let P = {(i, j) : 1 ≤ i <
 j ≤ n, c (i) = c (j)} be the set of pairs of boxes having the same color. For (i, j) ∈ P and
a ∈ {2, . . . , A}, let Ii,j,a = j − i + 1, a, F , (i, . . . , j), ci,j denote the instance formed by boxes i, . . . , j, with an accessible
zone of size a, and with the same forklift capacity as instance I, where ci,j is the restriction of function c to the set {i, . . . , j}.
For example, if I is the instance depicted in Fig. 2, then I3,6,3 is the instance depicted in Fig. 3.
For (i, j) ∈ P, k ∈ {0, . . . , F − 2}, and a ∈ {2, . . . , A}, we define Si,j,k,a as the set of strategies for instance Ii,j,a with the
additional constraint that the last move consists in picking boxes i and j, along with at most k other boxes placed between
them. More precisely, we have
Si,j,k,a =


1
 m−1  ≤ k + 2 .
x0 = (i, . . . , j), σ1 , x1 , . . . , σm , xm = () ∈ S (Ii,j,a ), x1m−1 = i, xmx−
m−1 = j, x


|

|
Let g (i, j, k, a) be the maximum gain that we can get from instance Ii,j,a with this additional constraint, that is, g (i, j, k, a) =
opt
maxS ∈Si,j,k,a G(S ). Let also Si,j,k,a be the set of optimal strategies among those of Si,j,k,a , that is
opt
Si,j,k,a = S ∈ Si,j,k,a : G(S ) = g (i, j, k, a) .


Finally, let K be the smallest set of integers satisfying the following three properties:
• F −2∈K;
• if k ∈ K , k ≡ 0 mod 2, and k > 0,
 then
 k−1∈K;
• if k ∈ K and k ≡ 1 mod 2, then 2k ∈ K .
Note that this definition implies that |K | is in O(log F ).
The goal is to compute the value of g (i, j, k, a) for all (i, j) ∈ P, k ∈ K , and a ∈ {2, . . . , A}. In the following, we show that
these values can be used to compute G (I ). Propositions 1–5 break the problem of computing such values into five cases. We
start with the case in which only two boxes are accessible.
Proposition 1. If (i, j) ∈ P and k ∈ K , then g (i, j, k, 2) = 1.
Proof. If the size of the accessible zone is 2, and we want boxes i and j to be removed in the last move, then there is only
one possible strategy, which consists in unloading boxes i + 1, . . . , j − 1 one by one, then unloading boxes i and j together.
This strategy consists of j − i moves, one less than the trivial strategy. Now, we turn to the case where at least three boxes are accessible, and k ≥ 1. For (i, j) ∈ P, we define Ni,j to be the
set of the indices of the boxes strictly between boxes i and j having the same color as them, that is, we define Ni,j = {u ∈
{i + 1, . . . , j − 1} : c (i) = c (u) = c (j)}. We have three subcases, described in Propositions 2–4.
Proposition 2. If (i, j) ∈ P, k ∈ K \ {0}, a ∈ {3, . . . , A}, and k ≡ 0 mod 2, then


g (i, j, k, a) = max g (i, j, 0, a), max {g (i, u, 0, a) + g (u, j, k − 1, a − 1)} .
u∈Ni,j
Proof. In order to solve instance Ii,j,a with the additional constraint that the last move has to unload boxes i and j along with
at most k other boxes, we have two cases to consider.
• Case 1: the last move consists in unloading boxes i and j alone. In this case, the maximum possible gain is g (i, j, 0, a).
• Case 2: the last move consists in unloading boxes i and j along with at least one other box. If we suppose that u ∈ Ni,j is
the leftmost box among them, we must first perform the following moves:
– unload boxes i + 1, . . . , u − 1 by performing all but the last move of a strategy of the set Si,u,0,a . This can be done using
(u − i + 1) − g (i, u, 0, a) − 1 moves.
– unload boxes u + 1, . . . , j − 1, leaving at most k − 1 boxes of color c (i) = c (j), by performing all but the last move of
a strategy of the set Su,j,k−1,a−1 . This can be done using (j − u + 1) − g (u, j, k − 1, a − 1) − 1 moves.
P. Baptiste et al. / Discrete Optimization 10 (2013) 251–262
255
We must then unload the remaining boxes. Since their number is at most k + 2 ≤ F , all of color c (i) = c (j), this can be
done with one move.
The minimum number of moves if u is the leftmost box unloaded with i and j is thus
[(u − i + 1) − g (i, u, 0, a) − 1] + [(j − u + 1) − g (u, j, k − 1, a − 1) − 1] + 1
= j − i + 1 − g (i, u, 0, a) − g (u, j, k − 1, a − 1),
and the maximum gain is g (i, u, 0, a) + g (u, j, k − 1, a − 1). It then follows that the maximum gain for Case 2 is
maxu∈Ni,j {g (i, u, 0, a) + g (u, j, k − 1, a − 1)}. Proposition 3. If (i, j) ∈ P, k ∈ K , a ∈ {3, . . . , A}, k ≡ 1 mod 2, and a −
k
≥ 3, then
 
 

k
k
k
k
g (i, j, k, a) = max g i, j,
, a , max g i, u,
, a + g u, j ,
,a −
−1
.
 
 

2
 
 
2


2
u∈Ni,j
2
2
opt
Proof. Among all strategies in Si,j,k,a , let S be one that unloads the minimum number of boxes in its last move. We have
two cases to consider:
 
• Case 1: the last move of S consists in unloading boxes i and j along with at most 2k other boxes. In this case, we have
 k 
g (i, j, k, a) = g i, j, 2 , a .
 
• Case 2: the last move of S consists in unloading boxes i and j along with at least 2k + 1 other boxes. Let u ∈ Ni,j be the
 
( 2k + 1)-th leftmost box among those which are unloaded with i and j in the last move of S. Note that the last move of
 
  
S unloads at most k − 2k + 1 = 2k boxes among u + 1, . . . , j − 1.
 
Let Si,u be the strategy used in S for unloading all but exactly 2k boxes of color c (i) = c (u) = c (j) among i + 1, . . . ,
 
u − 1, and let Su,j be the strategy used in S for unloading all but at most 2k boxes of color c (i) = c (u) = c (j) among
   
u + 1, . . . , j − 1. It follows that |S | = Si,u  + Su,j  + 1.
 

 
 

– by the optimality of S, we have Su,j  = (j − u + 1) − g u, j, 2k , a − 2k − 1 − 1.


opt
– if there is a strategy S ′ ∈ S  k  that unloads i and u along with at most 2k − 1 other boxes, then let Si′,u be the
i,u, 2 ,a
 
strategy formed by all but the last move of S ′ . This strategy unloads all but at most 2k − 1 boxes among i + 1, . . . , u − 1.
opt
By replacing Si,u by Si′,u in S, one would obtain a strategy in Si,j,k,a in which the last move unloads fewer boxes than the
last move of S. This is a contradiction, and it therefore follows that Si,u  = (u − i + 1) − g i, u,
Hence, the number of moves in strategy S is



k
2

, a − 1.
 

 
 




  
k
k
k
, a − 1 + (j − u + 1) − g u, j,
,a −
−1 −1 +1
|S | = (u − i + 1) − g i, u,
2
2
2

  

 
 

k
k
k
= (j − i + 1) − g i, u,
, a − g u, j,
,a −
−1 .
2
2
2
The gain obtained with strategy S is therefore equal to g (i, j, k, a) = G(S ) = (j − i + 1) − |S | = g i, u,

g u, j ,

k
2
,a −
k
2

k
2

,a +
−1 .
In summary, g (i, j, k, a) is equal to either g i, j, 2k , a or to g i, u,
u ∈ Ni,j . In order to conclude, we have to prove that

 
g (i, j, k, a) ≥ max g
i, j,
 
k
2

 
 

, a , max g i, u,

 
k
2
u∈Ni,j

k
2


 
 

, a + g u, j, 2k , a − 2k − 1 for some value

, a + g u, j,
 
k
2
,a −
 
k
2

−1
.
To do so, we proceed with the following two steps.
   
• We have Si,j, k ,a ⊆ Si,j,k,a , therefore g (i, j, k, a) ≥ g i, j, 2k , a .
2
• Let u ∈ Ni,j , and consider two strategies Si,u ∈ S opt k  and Su,j ∈ S opt k 
 
u,j, 2 ,a− 2k −1
i,u, 2 ,a
. We can build a strategy S ∈ Si,j,k,a
by using:
 
– all but the last move of Si,u to unload all but at most 2k boxes among i + 1, . . . , u − 1, then
– all but the last move of Su,j to unload all but at most
k
2
boxes among u + 1, . . . , j − 1, then
– one last move to unload the remaining boxes (namely, boxes i, u, j, and at most 2
k
2
= k − 1 others).
256
P. Baptiste et al. / Discrete Optimization 10 (2013) 251–262
   

  
 
We have |S | = Si,u  − 1 + Su,j  − 1 + 1 = Si,u  + Su,j  − 1, therefore
   
g (i, j, k, a) ≥ G(S ) = (j − i + 1) − |S | = (j − i + 2) − Si,u  − Su,j 


   

 
 

k
k
k
= (j − i + 2) − (u − i + 1) − g i, u,
, a − ( j − u + 1 ) − g u, j ,
,a −
−1
2
2
2

  

 
 

k
k
k
= g i , u,
, a + g u, j,
,a −
−1 . 2
2
2
Proposition 4. If (i, j) ∈ P, k ∈ K , a ∈ {3, . . . , A}, k ≡ 1 mod 2, and a −

g (i, j, k, a) = g
i, j,
 
k
2
k
2
≤ 2, then

,a .
Proof. The result follows from the fact that the inequality a −
consists in picking boxes i and j along with at most
k
2
k
2
≤ 2 implies that the last move of any strategy in Si,j,k,a
other boxes.
We are now left with the case where the last move consists in picking exactly two boxes, and the number of accessible
boxes is at least three. For (i, j) ∈ P, let Pi,j be the set of pairs of boxes with the same color and located strictly between
boxes i, j, that is Pi,j = {(i′ , j′ ) ∈ P : i < i′ < j′ < j}. Moreover, we define Qi,j to be the set of subsets of Pi,j whose elements
define pairwise non-crossing intervals, that is,
Qi,j = Q ⊆ Pi,j : [i′ , j′ ] ∩ [i′′ , j′′ ] = ∅ ∀(i′ , j′ ), (i′′ , j′′ ) ∈ Q , (i′ , j′ ) ̸= (i′′ , j′′ ) .


For example, in instance I ex of Fig. 2, we have P2,9 = {(3, 6), (4, 7), (4, 8), (7, 8)} and
Q2,9 = {∅, {(3, 6)} , {(4, 7)} , {(4, 8)} , {(7, 8)} , {(3, 6), (7, 8)}} .
Proposition 5. If (i, j) ∈ P and a ∈ {3, . . . , A}, then



g (i, j, 0, a) = max
Q ∈Qi,j
g (i , j , F − 2, a − 1)
′
′
+ 1.
(i′ ,j′ )∈Q
Proof. In order to solve instance Ii,j,a with the additional constraint that the last move consists in picking boxes i and j only,
we need to start by solving
I ′ = (j 
− i − 1, a − 1, F , (i + 1, . . . , j − 1), ci+1,j−1 ). Therefore we have g (i, j, 0, a)
 1 instance

1
′
= G (I ) + 1. Let Q = z1 , z2 , . . . , z1q , z2q ∈ Qi,j , with z11 < z21 < z12 < z22 < · · · < z1q < z2q . Consider the strategy
S ∈ S (I ′ ) which consists in
•
•
•
•
•
•
•
unloading boxes i + 1, . . . , z11 − 1 one
 by one, then

unloading boxes z11 , . . . , z21 saving g z11 , z21 , F − 2, a − 1 moves, then
unloading boxes z21 + 1, . . . , z12 − 1 one by one, then
unloading boxes z12 , . . . , z22 saving g (z12 , z22 , F − 2, a − 1) moves, then
...
q
q
q
q
unloading boxes z1 , . . . , z2 saving g (z1 , z2 , F − 2, a − 1) moves, then
q
unloading boxes z2 + 1, . . . , j − 1 one by one.
We have G(S ) =

g i′ , j′ , F − 2, a − 1 ,hence

(i′ ,j′ )∈Q


G (I ) ≥ max
′
Q ∈Qi,j


g (i , j , F − 2, a − 1) .
′
′
(i′ ,j′ )∈Q
Now, let S be an optimal strategy for instance I ′ , and
z11 , z21 , . . . , z1m , z2m




its compact representation. Let R be the
set of pairs of identifiers corresponding to the moves of S which unload at least two boxes, that is R =
z1t , z2t : t ∈


{1, . . . , m} , z1t ̸= z2 . Moreover, let R′ be the subset of R formed by the elements which are maximal with respect to inclusion, i.e.,

t
R′ =

  
 

 
i , j′ ∈ R : i′ , j′ ̸⊆ i′′ , j′′ ∀ i′′ , j′′ ∈ R \ i′ , j′
.
 ′
Since strategy S is optimal, we have
G I ′ = G(S ) ≤
 

(i′ ,j′ )∈R′
g (i′ , j′ , F − 2, a − 1).
P. Baptiste et al. / Discrete Optimization 10 (2013) 251–262
257
Note that R′ ⊆ Pi,j , and the elements of R′ define pairwise non-crossing intervals. Hence R′ ∈ Qi,j . It then follows that

 ′
G I

≤ max
Q ∈Qi,j
g i , j , F − 2, a − 1
′
′


. (i′ ,j′ )∈Q
Proposition 6 shows how to compute the maximum gain for instance I once we have computed all values
g (·, ·,

 ·, ·).
Let now Q be the set of subsets of P whose elements define pairwise non-crossing intervals, that is Q = Q ⊆ P : i′ , j′


  

  

∩ i′′ , j′′ = ∅ ∀ i′ , j′ , i′′ , j′′ ∈ Q , i′ , j′ ̸= i′′ , j′′ . For instance I ex depicted in Fig. 2, we have
Q = {∅, {(1, 4)}, {(1, 7)}, {(1, 8)}, {(2, 5)}, {(2, 9)}, {(2, 10)}, {(3, 6)}, {(4, 7)}, {(4, 8)}, {(5, 9)},
{(5, 10)}, {(7, 8)}, {(9, 10)}, {(1, 4), (5, 9)}, {(1, 4), (5, 10)},
{(1, 4), (7, 8)}, {(1, 4), (9, 10)}, {(1, 7), (9, 10)}, {(1, 8), (9, 10)}, {(2, 5), (7, 8)},
{(2, 5), (9, 10)}, {(3, 6), (7, 8)}, {(3, 6), (9, 10)}, {(4, 7), (9, 10)},
{(4, 8), (9, 10)}, {(7, 8), (9, 10)}, {(1, 4), (7, 8), (9, 10)},
{(2, 5), (7, 8), (9, 10)}, {(3, 6), (7, 8), (9, 10)}}.
Proposition 6. The maximum gain for instance I is

G (I ) = max
Q ∈Q


g (i′ , j′ , F − 2, A) .
(i′ ,j′ )∈Q
Proof. Similar to that of Proposition 5.
We now describe how to evaluate efficiently the right-hand side expressions on Propositions 5 and 6. Let H be the directed
graph defined as follows:
• the vertex set is V = {1, . . . , n + 1};
• the arc set is E = E1 ∪ E2 , where
– E1 = {(i, i + 1) : i ∈ {1, . . . , n}};
– E2 = {(i, j + 1) : (i, j) ∈ P } = {(i, j + 1) : 1 ≤ i < j ≤ n, c (i) = c (j)}.
For a ∈ {2, . . . , A}, let wa : E → N be the weight function defined as follows:
wa (i, j) =

0,
g (i, j − 1, F − 2, a),
if j = i + 1,
if j > i + 1.
For (i, j) ∈ V 2 and a ∈ {2, . . . , A}, let da (i, j) be the weight of a longest path from i to j in graph H, using the weight
function wa . Propositions 7 and 8 establish the correspondence between the longest paths in graph H and the expressions
we seek to evaluate.
Proposition 7. If (i, j) ∈ P and a ∈ {3, . . . , A}, then



da−1 (i + 1, j) = max
Q ∈Qi,j
g (i , j , F − 2, a − 1) .
′
′
(i′ ,j′ )∈Q
Proof. We can establish a bijection between the set of paths from i + 1 to j in H and the set Qi,j . Let p be a path from i + 1
to j in H, and let E (p) be the set of arcs it uses. We associate to p the following element of Qi,j :
 ′ ′

(i , j ) : (i′ , j′ + 1) ∈ E (p) ∩ E2 .



Conversely, let (i1 , j1 ) , . . . , iq , jq ∈ Qi,j , with i1 < j1 < i2 < j2 < · · · < iq < jq . We associate to this set the path

 

(i + 1, . . . , i1 ) ⊙ (j1 + 1, . . . , i2 ) ⊙ (j2 + 1, . . . , i3 ) ⊙ · · · ⊙ jq−1 + 1, . . . , iq ⊙ jq + 1, . . . , j . Proposition 8. We have that

dA (1, n + 1) = max
Q ∈Q

g i , j , F − 2, A
′
′
(i′ ,j′ )∈Q
Proof. Similar to that of Proposition 7.


.
258
P. Baptiste et al. / Discrete Optimization 10 (2013) 251–262
Theorem 1. The optimal gain G (I ) for instance I can be determined in O n3 A log F time.


Proof. Propositions
 1–8 lead
 to Algorithm 1. In lines 2–4, we use Proposition 1 to compute the entries of the form g (·, ·, ·, 2),
in O(|P ||K |) = O n2 log F time. The for loop of lines 5–17 iterates through all possible values of a in increasing order and
computes the entries of the form g (·, ·, ·, a). For each value of a, we start by computing the longest path between all pairs
of vertices in graph H, using the weight function wa−1 (which is known at this stage since all values g (·,
 ·, ·, a − 1) have
been computed earlier). This can be done by means of the Floyd–Warshall algorithm [5], which runs in O n3 time. The for
loop of lines 7–17 iterates through the elements of P. For each (i, j) ∈ P, we compute first the entry g (i, j, 0, a) in line 9,
using Propositions 5 and 7. Then, we compute the other entries
 the form g (i, j, ·, a) in the for loop of lines 10–17, using
 of
Propositions 2–4. Note that computing each entry takes O Ni,j  = O(n) time. Therefore, each iteration of the for loop




of lines 5–17 takes O n3 + |P ||K |n = O n3 log F time. Finally, in line 18, whose running time is clearly dominated by
that
 of lines 5–17, we compute

 and return
 G (I ) using Propositions 6 and 8. The total execution time of Algorithm 1 is then
O n2 log F + n3 A log F = O n3 A log F . Algorithm 1: A dynamic programming algorithm.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sort P in such a way that P = {(i1 , j1 ), . . . , (i|P | , j|P | )} and j1 − i1 ≤ · · · ≤ j|P | − i|P |
foreach (i, j) ∈ P do
foreach k ∈ K do
g (i, j, k, 2) ← 1
for a = 3, . . . , A do
compute da−1 (i, j) for all (i, j) ∈ {1, . . . , n}2 , i ≤ j
for t = 1, . . . , |P | do
(i, j) ← (it , jt )
g (i, j, 0, a) ← da−1 (i + 1, j) + 1
foreach k ∈ K \ {0}, in increasing order, do
if k ≡ 0 mod 2 then 

g (i, j, k, a) ← max g (i, j, 0, a) , maxu∈Ni,j {g (i, u, 0, a) + g (u, j, k − 1, a − 1)}
else
 
if a − 2k ≥ 3 then  
  
 
  

 
 

g (i, j, k, a) ← max g i, j, 2k , a , maxu∈Ni,j g i, u, 2k , a + g u, j, 2k , a − 2k − 1
else
   
g (i, j, k, a) ← g i, j, 2k , a
return dA (1, n + 1)
In what follows, we discuss how to find an optimal strategy after executing Algorithm 1. For this purpose, we can use
Algorithm 2, whose correctness follows from Propositions 6 and 8. This algorithm uses the values of g (·, ·, ·, ·) and the
longest paths in graph H with weight function w2 , . . . , wA – which are obtained by using Algorithm 1 – to compute and
return the compact representation L of an optimal strategy. The list L is manipulated through the use of the concatenation
operator (represented by symbol ⊙) and the pop back operation, which removes the last element in a list.
Algorithm 2 relies on Algorithm 3. The latter algorithm takes as parameters four integers i, j, k and a, and returns an
optimal solution for instance Ii,j,a , with the additional constraint that the last move consists in picking boxes i and j, along
with at most k other boxes placed between these two positions and having the same color as i and j. Its correctness follows
from Propositions 1–5 and 7.
Algorithm 2: Retrieving an optimal strategy.
1
2
3
4
5
6
7
8
9
10
let (i1 = 1, . . . , iq = n + 1) be a longest path from 1 to n + 1 in graph H with weight function wA
L ← ()
for t = 1, . . . , q − 1 do
if it +1 = it + 1 then
L ← L ⊙ ([it , it ])
else
L′ ← RetrieveStrategy(it , it +1 − 1, F − 2, A)
L′ .PopBack()
L ← L ⊙ L′
return L
P. Baptiste et al. / Discrete Optimization 10 (2013) 251–262
259
5. A running example
In this section, we present a running example which illustrates our algorithm. We consider instance I ex , depicted in Fig. 2.
A summary of the execution of Algorithm 1 on this instance is depicted in Fig. 4.
Algorithm 3: Auxiliary algorithm for retrieving an optimal strategy.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
RetrieveStrategy(i, j, k, a)
if a = 2 then
L ← ()
for u = i + 1, . . . , j − 1 do
L ← L ⊙ ([u, u])
L ← L ⊙ ([i, j])
else
if k = 0 then
L ← ()
let (i1 = i + 1, . . . , iq = j) be a longest path from i + 1 to j in graph H with weight function wa−1
for t = 1, . . . , q − 1 do
if it +1 = it + 1 then
L ← L ⊙ ([it , it ])
else
L′ ← RetrieveStrategy(it , it +1 − 1, F − 2, a − 1)
L′ .PopBack()
L ← L ⊙ L′
L ← L ⊙ ([i, j])
else
if k ≡ 0 mod 2 then
if g (i, j, k, a) = g (i, j, 0, a) then
L ← RetrieveStrategy(i, j, 0, a)
else
u∗ ← arg maxu∈Ni,j {g (i, u, 0, a) + g (u, j, k − 1, a − 1)}
L′ ← RetrieveStrategy(i, u∗ , 0, a)
L′ .PopBack()
L′′ ← RetrieveStrategy(u∗ , j, k − 1, a − 1)
L′′ .PopBack()
L ← L′ ⊙ L′′ ⊙ ([i, j])
25
26
27
28
29
30
31
32
33
34
else
   
if g (i, j, k, a) = g i, j, 2k  , a then
 
L ← RetrieveStrategy i, j, 2k , a
else

 
 

 
  
u∗ ← arg maxu∈Ni,j g i, u, 2k , a + g u, j, 2k , a − 2k − 1
L′ ← RetrieveStrategy i, u∗ ,
L′ .PopBack()

35
36
L′′ ← RetrieveStrategy u∗ , j,
L′′ .PopBack()
L ← L′ ⊙ L′′ ⊙ ([i, j])

37
38
39
40
k
2
,a
k
2

,a −
k
2

−1
return L
According to Fig. 4(i), the maximal gain is G (I ex ) = 4. This means that there exists a strategy using OPT (I ex ) = n −
G (I ex ) = 6 moves. In order to retrieve an optimal strategy, we use Algorithm 2. A summary of the execution of this algorithm is depicted in Fig. 5. The root node contains the result returned by Algorithm 2. Each other node corresponds to a
recursive call to Algorithm 3. The list inside a given node represents the strategy returned by the corresponding call, and
the four indices on the edge above it represent parameters (i, j, k, a). The optimal strategy found, namely ([1, 1] , [3, 3] ,
[5, 5] , [6, 6] , [4, 8] , [2, 10]), is depicted in Fig. 6.
6. Conclusion


In this paper, we presented an O n3 A log F dynamic programming algorithm for minimizing the number of steps to
unload n boxes off a gravity conveyor, with a forklift of capacity F and an accessible zone of size A. Interesting variants of
260
P. Baptiste et al. / Discrete Optimization 10 (2013) 251–262
(a) Initialization.
(b) Computing entries g (·, ·, ·, 2).
(c) Graph H with weight function w2 .
(d) Longest paths d2 (·, ·).
(e) Computing entries g (·, ·, ·, 3).
Fig. 4. Execution of Algorithm 1 for instance I ex .
P. Baptiste et al. / Discrete Optimization 10 (2013) 251–262
261
(f) Graph H with weight function w3 .
(g) Longest paths d3 (·, ·).
(h) Computing entries g (·, ·, ·, 4).
(i) Graph H with weight function w4 . A longest path with cost d4 (1, 11) is highlighted in bold.
Fig. 4. (continued)
this problem can be obtained by supposing that the colors of the boxes are only revealed the moment when they enter
the accessible zone. In a follow-up paper, we plan to address two variants of this type. In the first one, the decisions are
based only on the boxes in the accessible zone. In the second one, we have partial information about the inaccessible zone,
namely the number of boxes of each color therein. We will present the oblivious and anticipatory online algorithms for these
variants, and perform an experimental study to evaluate their performance.
262
P. Baptiste et al. / Discrete Optimization 10 (2013) 251–262
Fig. 5. Execution of Algorithm 2 for instance I ex .
Fig. 6. An optimal strategy for instance I ex .
References
[1] Mohammad Yousef Maknoon, Pierre Baptiste, Cross-docking: increasing platform efficiency by sequencing incoming and outgoing semi-trailers,
International Journal of Logistics Research and Applications 12 (4) (2009) 249–261.
[2] Rim Larbi, Gülgün Alpan, Pierre Baptiste, Bernard Penz, Scheduling cross docking operations under full, partial and no information on inbound arrivals,
Computers & Operations Research 38 (6) (2011) 889–900.
[3] Pierre Baptiste, Djamal Rebaine, Zayneb Brika, Chargement de véhicules à l’aide d’un convoyeur, in: 9e Congrès International de Génie Industriel,
Saint-Sauveur, Canada, November 2011.
[4] Pierre Baptiste, Djamal Rebaine, Zayneb Brika, Optimizing item trips from a production line to trucks, in: 4th International Conference on Information
Systems, Logistics and Supply Chain, Quebec, Canada, August 2012.
[5] Robert W. Floyd, Algorithm 97 (shortest path), Communications of the ACM 5 (6) (1962) 345.