INDIAN INSTITUTE OF MANAGEMENT
AHMEDABAD • INDIA
Research and Publications
Speeding up neighborhood search for the tool indexing
problem
Diptesh Ghosh
W.P. No. 2016-09-02
September 2016
✓
✏
The main objective of the Working Paper series of IIMA is to help faculty members,
research staff, and doctoral students to speedily share their research findings with
professional colleagues and to test out their research findings at the pre-publication stage.
✒
✑
INDIAN INSTITUTE OF MANAGEMENT
AHMEDABAD – 380015
INDIA
W.P. No. 2016-09-02
Page No. 1
IIMA • INDIA
Research and Publications
Speeding up neighborhood search for the tool indexing
problem
Diptesh Ghosh
Abstract
The arrangement of tools in tool holding pockets of a tool magazine in a CNC machining
center plays an important role in reducing processing times of complex job processes in automated machining environments. This problem is called the ATC indexing problem (ATCIP).
Computing the cost of a solution for an ATCIP instance of size n requires O(n2 ) time, so that
neighborhood search iteration for the ATCIP on an O(n2 ) neighborhood requires O(n4 ) time.
We describe techniques to reduce this effort for two common neighborhood structures from
O(n4 ) time to O(n2 ) time.
Keywords: Tool indexing, neighborhood search, swap neighborhood, insert neighborhood
1
Introduction
In computer numerically controlled machining centers, multiple operations requiring multiple tools
can be carried out on a job without altering its setup. Changing tools for different operations usually
take up a significant portion of job processing time (see, e.g. Gray et al. 1993). Automatic tool
changers (ATC) are commonly employed in these machining centers to automate the tool changing
process and hence reduce the tool changing time. In an ATC, a large number of tools (usually
between 12 and 200) are stored in a tool magazine and changed automatically when required. One
of the most common types of tool magazines is a disc type tool magazine. It can be visualized as a
circular disk with tool holding pockets capable of holding one tool each arranged at equal intervals
on the disk.
The process of changing tools in an ATC follows several steps. The tool change arm first picks
the tool that has finished its operation from the spindle and puts it back to its pocket in the tool
magazine. The tool magazine then indexes, i.e., rotates to bring the tool pocket in which the next
tool required to the index position. It is picked up by the tool change arm and loaded on to the
spindle. The time required for this indexing operation is thus an idle time for the job and should
be minimized if the processing time of the job has to be reduced. One way of achieving this is to
assign tools to tool pockets in a manner so as to minimize the total amount of rotation of the tool
magazine. This assignment problem is called the indexing problem or the ATC indexing problem
(ATCIP) (see, e.g. Baykasoğlu and Ozsoydan 2015). Formally stated, in the ATC indexing problem,
we are given a sequence of operations required to process a job, the tool required for each operation,
and a tool magazine with a specified number of pockets. Our aim is to assign the tools to the pockets
in such a manner that the total amount of rotation of the tool magazine in order to bring the tools
required for all the operations to the index position in proper sequence is the minimum possible.
The amount of rotation is measured as multiples of the rotation required to move a tool pocket one
position away from the index position to the index position.
We now derive a mathematical expression for the indexing cost for processing a job when tools
have been assigned to pockets. This cost will be measured in units, where an unit is the amount
of rotation required to move from one holding pocket to the next. If we are considering a tool
W.P. No. 2016-09-02
Page No. 2
IIMA • INDIA
Research and Publications
magazine with n pockets, then this amounts to a rotation of 2π/n radians. If a tool at pocket j is
required by the tool changer immediately after a tool at a position k, then the cost associated with
this change is djk = min{|k − j|, |j + n − k|} units. Note that this cost remains unchanged if the
tools are interchanged in the magazine. Now assume that m tools are required for a particular job
and the tools are being assigned to pockets in a n-pocket tool magazine, with m ≤ n. Let us denote
the assignment as a permutation Π = (π[0] , π[1] , . . . , π[n−1] ) where π[i] denotes the tool that occupies
the i-th pocket in the magazine. If π[i] ≥ m then the tool is a “dummy” tool and the i-th pocket
is actually empty. (We count indices from 0 rather than 1 since it helps the exposition in the later
part of this paper.) The frequency with which tools r and s are required for consecutive operations
is given by frs which is obtained from the sequence of operations and the tools required for each
operation. Obviously if either r or s has a value of m or more, then the corresponding f value is 0.
Then the indexing cost for the arrangement is
z(Π) =
n−1
X
n
X
fπ[j] π[k] djk units.
(1)
j=1 k=j+1
Our objective in the ATCIP is to find a permutation Π with minimum cost. The mathematical
programming formulation of the problem is the following quadratic assignment problem (QAP)
formulation (see Loiola et al. 2007, for a survey of QAP). QAPs are difficult combinatorial problems
to solve, and the formulation above does not exploit the fact that in the ATCIP, locations are
equidistant on the circumference of a circle. So the formulation given above may not be practical
for solving large ATCIP instances. A common alternative therefore is to use neighborhood search
based algorithms to solve the ATCIP. However, common neighborhoods are quadratic in problem
size and thus the effort required to search such neighborhoods naı̈vely is O(n4 ). We describe two
neighborhoods commonly used by neighborhood search algorithms solving problems similar to the
ATCIP. We show that searching these neighborhoods can be achieved in O(n2 ) time. The inspiration
for our technique is the work in Palubeckis (2015), although the single row facility layout problem
studied in that paper and the ATCIP have important differences.
Neighborhood search algorithms work by imposing a neighborhood structure on all feasible solutions to a problem instance. This structure is imposed by defining moves that transform one
solution to another. Such moves are pre-defined, and allow the algorithm to consider those solutions
that any particular solution can be transformed to as neighbors of that solution. Neighborhood
search algorithms are iterative. At each iteration, the algorithm starts with a solution (called the
current solution), searches its neighbors to find the best solution in the neighborhood (called the
next solution), and discards the current solution in favor of the next solution based on pre-specified
rules. It stops when a pre-specified stopping condition is satisfied and outputs the best solution that
it has encountered. The performance of such an algorithm critically depends on the neighborhood
structure it defines, and the speed with which it can search the neighborhood. The neighborhood
structure in turn often depends on the representation of a solution by the algorithm. In classic
neighborhood search algorithms (called local search), the next solution in an iteration replaces the
current solution only if its cost is lower than the current solution’s. Local search terminates when
the next solution has a cost not lower than the current solution’s.
For our problem, a solution is a permutation of the tool indices including the dummy indices
used when the number of holding pockets exceed the number of tools. We denote a solution as
Π = (π[0] , . . . , π[i] , . . . , π[n−1] ), where π[i] denotes the index of the tool occupying pocket i in the tool
magazine.
We use two neighborhood structures in this work. The first is the SWAP neighborhood in
which a neighbor of a solution is generated by swapping the positions of two tools in a solution. For example, a swap neighbor of Π obtained by swapping tools in positions p and q is
ΠS(p,q) = (π[0], . . . , π[p − 1], π[q], π[p + 1], . . . π[q − 1], π[p], π[q + 1], . . . , π[n − 1]). The second
is an INSERT neighborhood in which a neighbor of a solution is obtained by removing a tool
from its position and inserting it at some other position in the solution. For example, an in-
W.P. No. 2016-09-02
Page No. 3
IIMA • INDIA
Research and Publications
sert neighbor of Π obtained by removing tool π[p] and reinserting it after the tool π[q] is ΠI(p,q) =
(π[0] , . . . , π[p−1] , π[p+1] , . . . ,π[q−1] , π[q] , π[p] , π[q+1] , . . . , π[n−1] ). Notice that the position q can be
at most n − 2 positions away from p in the clockwise direction if ΠI(p,r) is to be distinct from Π.
There are O(n2 ) neighbors of each solution in both the neighborhoods, and each solution requires
O(n2 ) time to evaluate using Eq. (1). Hence brute force implementations of neighborhood search will
require O(n4 ) time to search either of the neighborhoods, and will make such algorithms impractical
for tool assignment. But in the remainder of this section, we will demonstrate that we can reduce the
search to O(n2 ) time by careful book-keeping. We will make use of the function φ : [−(n − 1), 2n] →
[0, n − 1] in our description of the computation process.
n − (−a mod n) if − n < a < 0,
a
if 0 ≤ a < n,
φ(a) =
(a mod n)
if n ≤ a ≤ 2n.
2
Speeding up search through the SWAP neighborhood
Consider the swap neighbor ΠS(p,q) of Π formed by swapping the positions of tools π[p] and π[q] . This
swap move can be thought of as comprising the following three steps:
Step 1: remove tool π[p] from its current position;
Step 2: add a copy of tool π[p] at position q in the solution obtained after Step 1; and
Step 3: remove tool π[q] from its position in the solution obtained after Step 2.
Each of these steps involve a change in the solution cost. We will now demonstrate how to compute
these changes.
First we compute the reduction in solution cost by removing tool π[p] from its current position
(Step 1). Removing this tool eliminates the cost of interchanging tool π[p] and all other tools from
z(Π). Since the value of fπ[p] ,π[p] = 0 we can write this cost reduction as
k−1
X
i fπ[φ(p+i)] ,π[p] + fπ[φ(p−i)] ,π[p] + k fπ[φ(p+k)] ,π[p] if n = 2k;
i=0
(2)
ρ(p) =
k
X
i fπ[φ(p+i)] ,π[p] + fπ[φ(p−i)] ,π[p]
if n = 2k + 1.
i=0
Note that the computation of ρ() values for all positions requires a total of O(n2 ) time.
Next we compute the increase in cost due to Step 2 after Step 1 is executed. Since fπ[p] ,π[p] = 0,
the increase in cost in this step is the same as the increase in cost if a copy of π[p] was added at
position q in Π.
Let n be even, say n = 2k for some integer k. Then the increase γ(p, q) in cost of the solution if
a copy of the tool π[p] is placed at position q.
γ(p, q) =
k−1
X
i=0
i fπ[φ(q+i)] ,π[p] + fπ[φ(q−i)] ,π[p] + k fπ[φ(q+k)] ,π[p] .
(3)
Notice that γ(p, q) = ρ(p). From Eq. (3) we compute the difference δ(p, q) between γ(p, q + 1) and
γ(p, q) as
k
2k
X
X
(4)
fπ[p] π[φ(q+1+i)] ;
δ(p, q) = γ(p, q + 1) − γ(p, q) =
fπ[p] π[φ(q+1+i)] −
i=k+1
i=1
W.P. No. 2016-09-02
Page No. 4
IIMA • INDIA
Research and Publications
and the difference ∆(p, q) between δ(p, q) values for successive q’s as
∆(p, q) = δ(p, q + 1) − δ(p, q) = 2 fπ[p]π[φ(q+1)] − fπ[p] π[φ(q+k+1)] .
So if we know γ(p, q) and γ(p, q + 1), we can compute γ(p, q + 2) as
γ(p, q + 2) = 2γ(p, q + 1) − γ(p, q) + ∆(p, q)
= 2γ(p, q + 1) − γ(p, q) + 2 fπ[p] π[φ(q+1)] − fπ[p] π[φ(q+k+1)] .
(5)
If n is odd, say n = 2k + 1 for some integer k, then from similar calculations we find that
γ(p, q) =
k
X
i=0
i fπ[φ(q+i)] ,π[p] + fπ[φ(q−i)] ,π[p] ;
δ(p, q) = u(p, q + 1) − u(p, q) =
2k
X
i=k+1
fπ[p] π[φ(q+1+i)] −
(6)
k−1
X
fπ[p] π[φ(q+1+i)] ; and
(7)
i=1
∆(p, q) = δ(p, q + 1) − δ(p, q) = 2fπ[p]π[φ(q+1)] − fπ[p] π[φ(q+k+1)] − fπ[p] π[φ(q+k+2)] .
(8)
So if n = 2k + 1, knowing u(p, q) and u(p, q + 1), we can compute u(p, q + 2) as
γ(p, q + 2) = 2γ(p, q + 1) − γ(p, q) + ∆(p, q)
= 2γ(p, q + 1) − γ(p, q) + 2fπ[p] π[φ(q+1)] − fπ[p] π[φ(q+k+1)] − fπ[p]π[φ(q+k+2)] .
(9)
For a fixed p we can compute γ(p, p) in O(n) time using Eq. (3) (resp. Eq. (6)) if n is even
(resp. odd). We can then compute δ(p, q) in O(n) time using Eq. (4) (resp. Eq. (7)) if n is even
(resp. odd); and compute γ(p, p + 1) = γ(p, p) + δ(p, q). Once γ(p, p) and γ(p, p + 1) are known we
can use Eq. (5) (resp. Eq. (9)) if n is even (resp. odd) repeatedly to compute γ(p, p + 2) through
γ(p, p − 2) in O(n) time. This shows that we can compute γ() values for all (p, q) pairs in O(n2 )
time.
Lastly, we compute the reduction in cost due to Step 3. This cost reduction is similar to that of
Step 1 with one difference. Here the reduction due to the interchanging of tools π[p] and π[q] must
be ignored since tool π[p] is no longer in its original position after Step 2. Hence the reduction in
this step is
(10)
σ(p, q) = ρ(q) + fπ[p] ,π[q] (|p − q|).
Notice that given ρ() values, the computation of σ() values for all (p, q) pairs also requires O(n2 )
time.
The difference in cost between solutions Π and ΠS(p,q) is given by
z(Π) − z(ΠS(p,q) ) = ρ(p) − γ(p, q) + σ(p, q).
(11)
Since all the three terms on the right hand side of Eq. 11 can be computed in O(n2 ) time, the
computation of z(Π) − z(ΠS(p,q) ) for all (p, q) pairs is achievable in O(n2 ) time. Thus, using the
method shown here, searching the SWAP neighborhood of a solution can be done in O(n2 ) time for
a ATCIP instance with an n-pocket tool magazine.
3
Speeding up search through the INSERT neighborhood
Consider the insert neighbor ΠI(p,q) of Π formed by removing tool π[p] and re-inserting it after tool π[q] .
This move can be thought of as the result of a series of component moves. In the first component
W.P. No. 2016-09-02
Page No. 5
IIMA • INDIA
Research and Publications
move, tool π[p] is interchanged with tool π[φ(p+1)] . In the i-th component move thereafter with
2 ≤ i ≤ q, tool π[p] is interchanged with tool π[φ(p+i)] in the solution obtained after the (i − 1)-th
component move. The reduction in the cost achieved by transforming from solution Π to ΠI(p,q) is
the sum of the cost reductions due to all the component moves.
Consider the i-th component move (2 ≤ i ≤ q). In this move, tool π[p] is interchanged with tool
π[φ(p+i)] in the solution obtained after the (i − 1)-th move. The difference in cost of the solution
before and after this move is due only to the change in positions of tools π[p] and π[φ(p+i)] since the
relative positions of all other pairs of tools remain unchanged by the move. Hence the reduction in
cost after the move can be thought to as having two components, (1) the reduction due to a change
in the position of tool π[p] , and (2) the reduction due to a change in the position of tool π[φ(p+i)] .
We first compute the reduction in the cost z(Π) when the tool π[p] changes position. Let n be
even, say n = 2k for some integer k. The cost c(p, i) associated with tool π[p] in the solution after
the i-th component move is
k−1
k
i
X
X
X
if p ≤ k, and
jfπ[p]π[φ(p+i+j)]
+
jf
+
jf
π
π
π
π
[p] [φ(p+i−j)]
[p] [φ(p+i+1−j)]
j=1
j=i+1
j=1
c(p, i) =
k−1
2k−i−1
k
X
X
X
jfπ[p] π[φ(p+i+1+j)] otherwise.
+
jf
+
jf
π
π
π
π
[p] [φ(p+i+j)]
[p] [φ(p+i+1−j)]
j=1
j=1
j=2k−i
(12)
So the reduction in cost associated with π[p] after the first component move is given by
r(p, 1) = c(p, 0) − c(p, 1) =
k
X
fπ[p] π[φ(p+j)] −
j=2
n−1
X
fπ[p]π[φ(p+j)] ,
(13)
j=k+1
and in general, the difference in cost associated with π[p] from after the i-th component move to
after the (i + 2)-th component move is given by
r2 (p, i) =c(p, i) − c(p, i + 2)
= 2fπ[p]π[φ(k+p+i+1)] − (fπ[p]π[φ(p+i+1)] + fπ[p]π[φ(p+i+2)] )
If n is odd, say n = 2k + 1 for some integer k, then
k
k
i
X
X
X
jfπ[p]π[φ(p+i+j)]
+
jf
+
jf
π[p] π[φ(p+i−j)]
π[p] π[φ(p+i+1−j)]
j=1
j=i+1
j=1
c(p, i) =
k
2k−i
k
X
X
X
+
jfπ[p] π[φ(p+i+j+1)]
jf
+
jf
π[p] π[φ(p+i+j)]
π[p] π[φ(p+i+1−j)]
j=1
j=1
k
X
n−1
X
(14)
if p ≤ k, and
otherwise,
j=2k−i+1
(15)
fπ[p]π[φ(p+j)] , and
(16)
r2 (p, i) = (fπ[p]π[φ(k+p+q+1)] + fπ[p]π[φ(k+p+q+2)] ) − (fπ[p]π[φ(p+q+1)] + fπ[p]π[φ(p+q+2)] ).
(17)
r(p, 1) =
j=2
fπ[p]π[φ(p+j)] −
j=k+2
The computation of c(p, 0) using Eq. (12) or Eq. (15) requires O(n) time. The value of r(p, 1)
can be computed using either Eq. (13) or Eq. (16) in O(n) time. Hence c(p, 1) = c(p, 0) − r(p, 1) can
be calculated in O(n) time. Also, since r2 (p, i) can be computed in constant time using Eq. (14) or
Eq. (17), we can compute the value of c(p, i) for all values of i in O(n) time. This in turn implies
that c(p, i) can be computed for all (p, i) pairs in O(n2 ) time.
Next we compute the reduction in z(Π) due to the change in the position of the tool π[φ(p+i)] .
This tool does not change its position in any but the i-th component move. In that move it shifts
W.P. No. 2016-09-02
Page No. 6
IIMA • INDIA
Research and Publications
to position φ(p + i − 1). The decrease in cost (d(p, i)) associated with tool π[φ(p+i)] due to this move
is calculated by computing the cost associated with π[φ(p+i)] before and after the move and finding
the difference.
If n is even, i.e., n = 2k for some integer k, then there are three cases to consider. If position p
is between positions φ(p + i − 1) and φ(p + i − k + 1) then
d(p, i) =
k−1
X
fπ[φ(p+i)] π[φ(p+i+j)] −
fπ[φ(p+i)] π[φ(p+i−j)] + fπ[φ(p+i)] π[p]
j=1
j=1
=
k
X
k−1
X
fπ[φ(p+i)] π[φ(p+i+j)] −
k−1
X
fπ[φ(p+i)] π[φ(p+i−j)]
j=1
j=1
!
+ fπ[φ(p+i)] π[p] − fπ[φ(p+i)] π[φ(p+i−k)] .
(18)
If position p is between positions φ(p + i + 1) and φ(p + i + k − 1), then
d(p, i) =
k
X
fπ[φ(p+i)] π[φ(p+i+j)] − fπ[φ(p+i)] π[p] −
fπ[φ(p+i)] π[φ(p+i−j)] + fπ[φ(p+i)] π[p]
j=1
j=1
=
k−1
X
k−1
X
fπ[φ(p+i)] π[φ(p+i+j)] −
k−1
X
fπ[φ(p+i)] π[φ(p+i−j)]
j=1
j=1
!
− fπ[φ(p+i)] π[p] − fπ[φ(p+i)] π[φ(p+i+k)] .
(19)
Otherwise if position p is the position φ(p + i + k) then
d(p, i) =
k−1
X
fπ[φ(p+i)] π[φ(p+i+j)] −
k−1
X
fπ[φ(p+i)] π[φ(p+i−j)] .
(20)
j=1
j=1
If n is odd, i.e., n = 2k + 1 for some integer k, then there are two cases to consider. If position
p is between positions φ(p + i − 1) and φ(p + i − k), then
d(p, i) =
k
X
fπ[φ(p+i)] π[φ(p+i+j)] −
fπ[φ(p+i)] π[φ(p+i−j)] + fπ[φ(p+i)] π[p]
j=1
j=1
=
k+1
X
k
X
fπ[φ(p+i)] π[φ(p+i+j)] −
k
X
fπ[φ(p+i)] π[φ(p+i−j)]
j=1
j=1
!
+ fπ[φ(p+i)] π[p] − fπ[φ(p+i)] π[φ(p+i−k−1)] .
(21)
Otherwise
d(p, i) =
k+1
X
fπ[φ(p+i)] π[φ(p+i+j)] − fπ[φ(p+i)] π[p] −
=
j=1
fπ[φ(p+i)] π[φ(p+i−j)]
j=1
j=1
k
X
k
X
fπ[φ(p+i)] π[φ(p+i+j)] −
k
X
j=1
fπ[φ(p+i)] π[φ(p+i−j)]
!
− fπ[φ(p+i)] π[p] − fπ[φ(p+i)] π[φ(p+i+k+1)] .
(22)
Pk−1
Pk−1
Given an index p, computing j=1 fπ[φ(p+i)] π[φ(p+i+j)] − j=1 fπ[φ(p+i)] π[φ(p+i−j)] if n = 2k and
Pk
Pk
j=1 fπ[φ(p+i)] π[φ(p+i−j)] if n = 2k + 1 requires O(n) time. Once the approj=1 fπ[φ(p+i)] π[φ(p+i+j)] −
priate one among these two are computed, computing d(p, i) for each i requires constant time using
the appropriate equation among Eq. (18) through Eq. (22). Thus for a given p, all d(p, i) values can
be computed in O(n) time, and d() values for all (p, i) pairs can be computed in O(n2 ) time.
W.P. No. 2016-09-02
Page No. 7
IIMA • INDIA
Research and Publications
The difference in cost between solutions Π and ΠI(p,q) is given by
z(Π) − z(ΠI(p,q) ) = c(p, 0) − c(p, (q − p)) +
q−p
X
d(p, i).
(23)
i=1
For a particular index p, if q = φ(p + 1) and if all c() and d() values are known, then computing
this quantity requires constant time. Also, once z(Π) − z(ΠI(p,j) ) is known for some j, computing
z(Π) − z(ΠI(p,j+1) ) = z(Π) − z(ΠI(p,j) ) + c(p, (j − p)) − c(p, (j − p + 1)) + d(p, j + 1) requires constant
time. So computing the values of all the differences z(Π) − z(ΠI(p,j) ) for all values of j requires O(n)
time. This shows that using the technique described here, searching the INSERT neighborhood of
an ATCIP solution requires O(n2 ) time when the instance has an n-pocket tool magazine.
In this paper therefore we have shown that neighborhood search in ATCIP instances can be
performed in O(n2 ) time rather than the O(n4 ) time required by naı̈ve exploration. This allows
neighborhood search to be a viable method to obtain good quality solutions to large size instances
of the problem.
References
A. Baykasoğlu and F.B. Ozsoydan. An improved approach for determination of index positions on
CNC magazines with cutting tool duplications by integrating shortest path algorithm. International Journal of Production Research. DOI: 10.1080/00207543.2015.1055351.
A.E. Gray, A. Seidmann, and K.E. Stecke. A Synthesis of Decision Models for Tool Management in
Automated Manufacturing. Management Science 39 (1993) pp. 549–567.
E.M. Loiola, N.M.M. de Abreu, P.O. Buaventura-Netto, P. Hahn, and T. Querido. A Survey of the
Quadratic Assignment Problem. European Journal of Operational Research 176 (2007) pp. 675–
690.
G. Palubeckis. Fast Local Search for Single Row Facility Layout. European Journal of Operational
Research 246 (2015) pp. 800–814.
W.P. No. 2016-09-02
Page No. 8
© Copyright 2026 Paperzz