Documente Academic
Documente Profesional
Documente Cultură
David S. Johnson
AT&T Labs Research
2010 AT&T Intellectual Property. All rights reserved. AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
Outline
Lecture 1: Today
Introduction to Bin Packing (Problem 1)
Introduction to TSP (Problem 2)
Applications
Packing commercials into station breaks
Packing files onto floppy disks (CDs, DVDs, etc.)
Packing MP3 songs onto CDs
Packing IP packets into frames, SONET time
slots, etc.
Packing telemetry data into fixed size packets
NP-Hardness
Means that optimal packings cannot be constructed in
worst-case polynomial time unless P = NP.
In which case, all other NP-hard problems can also be
solved in polynomial time:
Satisfiability
Clique
Graph coloring
Etc.
Worst-Case Bounds
Theorem [Ullman, 1971][Johnson et al.,1974].
For all lists L,
OPT: N bins
FF, BF:
N/2 bins
N bins
= 1.5 OPT
OPT: N bins
FF, BF:
= 5/3 OPT
1/43 + ,
1/1806 + ,
etc.
1/3 +
OPT: N bins
(1.691..) OPT
1/3 +
1/2 +
OPT: N bins
1/4-2
1/4+
1/4-2
1/4-2
1/4+2
1/4+
1/4+2
1/4+
1/4+2
6n bins
3n bins
OPT = 9n
1/4+
6n bins
2n bins
FFD, BFD = 11n
1/4-2
1/4-2
1/4-2
3n bins
Asymptotic Worst-Case
Ratios
RN(A) = max{A(I)/OPT(I): OPT(I) = N}
R(A) = max{RN(A): N > 0}
absolute worst-case ratio
R(A) = limsupNRN(A)
asymptotic worst-case ratio
Why Asymptotics?
Partition Problem: Given a set A of numbers
ai, can they be partitioned into two subsets
with the sums (aAa)/2?
This problem is NP-hard, and is equivalent to
the special case of bin packing in which we ask
if OPT = 2.
Hence, assuming P NP, no polynomial-time
bin packing algorithm can have R(A) < 3/2.
Gap
Size
If x fits in the gap of the nodes left child, let that node become the
current node.
Otherwise,
delete the current node.
pack x in the current nodes bin.
reinsert that bin into the tree with its new gap.
Otherwise,
If the current node has a right child, let that become the current
node.
Otherwise, pack x in a new bin, and add that to the tree.
1.00
.56
.41
.11
.99
.56
.41
.56
.37
.82
.82
.03
.77
.99
.50
.26
.99
.26
.77
.17
.77
.44
1.00
1.00
To Be Continued
Next time: Average-Case Behavior
For now: On to the TSP!
Find:
Permutation : {1,2,..., N} {1,2,..., N} that minimizes
N 1
d(c
i1
(i)
N = 10
N = 10
How Hard?
NP-Hard for all the above applications
How Hard?
Number of possible tours:
N! = 123(N-1)N = (2NlogN)
10! = 3,628,200
20! ~ 2.431018 (2.43 quadrillion)
How Hard?
Number of possible tours:
N! = 123(N-1)N = (2NlogN)
10! = 3,628,200
20! ~ 2.431018 (2.43 quadrillion)
N = 10
N = 100
N = 1000
N = 10000
N = 2392
N = 7397
N = 33,810
N = 85,900
d(c,c) =
1 if {c,c} E
N2N if {c,c} E
A
d(A,D) d(A,E) + d(E,D)
B
E
d(B,C) d(B,E) + d(E,C)
D
C
Note: By -inequality, an optimal tour need not contain any crossed edges.
d(A,D) + d(B,C) (d(A,E) + d(E,D)) + (d(B,E) + d(E,C))
= (d(A,E) + d(E,C)) + (d(B,E) + d(E,D))
= d(A,C) + d(B,D)
For the Euclidean metric, the inequalities are strict
(unless all relevant cities are co-linear)
Theorem
1
1+
Li/2 + 1
Fi+1:
Fi
1+
Li/2 + 1
1+
Fi
Let Li be the number of edges encountered if we travel stepby-step from the leftmost vertex in Fi to the rightmost.
L1 = 2,
Li+1 = 2Li + 2
k 1
i
2
L
2
= 2k + 2k 1 < 2k+1
1
=
i 0
NN(Fk) Lk + 1 + 2
i1
k -1-i
k 1
P1
Optimal Tour
P2
NI(I) = 2N-2
OPT(I) = N+1
2
2
Another Approach
Observation 1: Any connected graph in which
every vertex has even degree contains an
Euler Tour a cycle that traverses each
edge exactly once, which can be found in
linear time.
Can we do better?
No polynomial-time algorithm is known that has a
worst-case ratio less than 3/2 for arbitrary instances
satisfying the -inequality.
Assuming P NP, no polynomial-time algorithm can do
better than 220/219 = 1.004566 [Papadimitriou &
Vempala, 2006].
For Euclidean and related metrics, there exists a
polynomial-time approximation scheme (PTAS): For
each > 0, a polynomial-time algorithm with worst-case
ratio 1+. [Arora, 1998][Mitchell, 1999].
PTAS RunningTimes
[Arora, STOC 1996]:
O(N100/)
O(N(logN)O(1/))
Performance In Practice
Testbed: Random Euclidean Instances
Nearest Neighbor
Greedy
Smart Shortcuts
Smart-Shortcut Christofides
Smart-Shortcut Christofides
2-Opt
3-Opt
Original Tour
Original Tour
Data Elements
Array T: Permutation of Point indices
Array H: H[i] = index of tree leaf containing Point i
Tree Vertex k:
Index L in
Array T of
First Point
Index U in
Array T of
Last Point
Widest
Dimension
Median Value
in Widest
Dimension
Leaf?
Empty?
Operations
Construct kd-tree (recursively): O(NlogN)
Delete or temporarily delete points (without
rebalancing): O(1)
Find nearest neighbor to one of points:
typically O(logN)
Given point p and radius r, find all points p with d(p,p)
r (ball search):
typically O(logN + number of points returned).
rnn(k,p,M):
If Vertex k is a leaf,
For each point x in vertex ks list,
If dist(p,x) < M, set M = dist(p,x) and Champion = x.
Otherwise,
Let d be vertex ks widest dimension, m be its median value for
that dimension, and pd the value of ps coordinate in dimension d.
If pd > m, let NearChild = 2k+1 and FarChild = 2k.
Otherwise, NearChild = 2k and FarChild = 2k+1.
If NearChild has not been explored, rnn(NearChild,p,M).
If |pd m| < M, rnn(FarChild,p,M).
2-Opt:
N(N 3) 4 the
Organizing
2
Search
AB
Try each
in C
turn
the current
improving
TryAall
notaround
adjacent
to A ortour
B inuntil
the an
current
tourmove is found
take first one found. If none found after all cities tried for A, halt.
(N-3 possibilities) .
C
D
A
If this is an improving move, we cannot have both
d(A,B) < d(A,C) and d(D,C) < d(D,B),
Since this would imply d(A,C) + d(D,B) > d(A,B) + d(D,C).
A
Conseqeuently, for a given choice of A and B, we only
need to consider those C with d(A,C) < d(A,B)
-- possibly a much smaller number than N.
Taking Advantage
First Idea (trading preprocessing time for later speed):
Preprocess by constructing for each city A, a sorted list of the
other cities C in increasing order by d(A,C).
Preprocessing Time = (N2logN)
Need double-linking (both Next and Prev) in order to identify legal 2-Opt moves in constant time:
If the first deleted edge is Next[A], then the second must be Prev[C], and vice versa.
Queries
Prev(c) -- Returns city before c in tour.
Next(c) -- Returns city after c in tour.
Between(a,b,c) Yes if and only if c is encountered
before b when traversing tour forward from a.
Why Between(a,b,c)?
3-Opt
B
D
Why Between(a,b,c)?
3-Opt
Why Between(a,b,c)?
Doesnt work!
3-Opt
A
Only D with Between(A,C,D) = Yes are viable
2-Level Tree
Divide tour into sqrt(N) segments, each
of length sqrt(N).
For each segment, store
A bit indicating whether that segment
should be traversed in forward or reversed
direction
Pointers to the next and previous segments
in the tour.
2-Level Tree
Parent
Prev Segment
Next Segment
Size
Seq. #
Start of Segment
End of Segment
Parent Structure
Parent
Prev
Seq. #
City
Next
2-Level Tree
Initialize: O(N)
Flip: O(sqrt(N))
Next, Prev: O(1)
Between: O(1)
In practice, beats arrays once N > 1000
Lower Bounds
(logN/loglogN)
Improving on 3-Opt
K-Opt (k > 3)
Small tour improvement for major running time increase.
Lin-Kernighan
[1973]
Iterated Lin-Kernighan
[Martin, Otto, & Felten, 1991], [Johnson, 1990]
Run Lin Kernighan
Perform random 3-opt move to resulting tour
Repeat above loop f(N) times (f(N) = N/10, N, 10N, ...)
For more on the TSP algorithm performance, see the website for the
DIMACS TSP Challenge:
http://www2.research.att.com/~dsj/chtsp/index.html/
Comparison: Smart-Shortcut Christofides versus 2-Opt
Tour Length
Estimating Running-Time
Growth Rate for 2-Opt
Microseconds/N
Microseconds/NlogN
Microseconds/N1.25