OR2 03 BnBandHeuristic
OR2 03 BnBandHeuristic
Ling-Chieh Kung
OR II: Branch & Bound and Heuristics 1 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Introduction
OR II: Branch & Bound and Heuristics 2 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Introduction
OR II: Branch & Bound and Heuristics 3 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Road map
I Linear relaxation.
I The branch-and-bound algorithm.
I Solving the knapsack problem.
I Heuristic algorithms.
OR II: Branch & Bound and Heuristics 4 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Solving an IP
max 3x1 + x2
I Suppose we are given an IP, how may we s.t. 4x1 + 2x2 ≤ 11
solve it? xi ∈ Z+ ∀i = 1, 2.
I The simplex method does not work!
I The feasible region is not “a region”.
I It is discrete.
I There is no way to “move along edges”.
I But all we know is how to solve LPs. How
about solving a linear relaxation first?
OR II: Branch & Bound and Heuristics 5 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Linear relaxation
I What is the linear relaxation of
max x1 + x2
s.t. x1 + 3x2 ≤ 10
2x1 − x2 ≥ 5
xi ∈ Z+ ∀i = 1, 2?
I Z is the set of all integers. Z+ is the set of all nonnegative integers.
I The linear relaxation is
max x1 + x2
s.t. x1 + 3x2 ≤ 10
2x1 − x2 ≥ 5
xi ≥ 0 ∀i = 1, 2.
OR II: Branch & Bound and Heuristics 6 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Linear relaxation
OR II: Branch & Bound and Heuristics 7 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Proposition 1
Let z ∗ and z 0 be the objective values associated to optimal solutions of
a minimization IP and its linear relaxation, respectively, then z 0 ≤ z ∗ .
Proof. They have the same objective function. However, the linear
relaxation’s feasible region is (weakly) larger than that of the IP.
I For a maximization IP, linear relaxation provides an upper bound.
OR II: Branch & Bound and Heuristics 8 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Proposition 2
Let x0 be an optimal solutions to the linear relaxation of an IP. If x0
is feasible to the IP, it is optimal to the IP.
OR II: Branch & Bound and Heuristics 9 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
OR II: Branch & Bound and Heuristics 10 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
I x∗ = (5, 0) is IP-optimal.
I But x1 = ( 15 9
4 , 4 ) is LR-optimal!
I Rounding up any variable results
in infeasible solutions.
I None of the four grid points
around x1 is optimal.
I We need a way that guarantees to
find an optimal solution.
OR II: Branch & Bound and Heuristics 11 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Road map
I Linear relaxation.
I The branch-and-bound algorithm.
I Solving the knapsack problem.
I Heuristic algorithms.
OR II: Branch & Bound and Heuristics 12 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
OR II: Branch & Bound and Heuristics 14 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
I So when we solve the linear relaxation and find any variable violating
an integer constraint, we will branch this problem into two problems,
one with an additional constraint.
I The two new programs are still linear programs.
I Once we solved them:
I If their LR-optimal solutions are both IP-feasible, compare them and
choose the better one.
I If any of them results in a variable violating the integer constraint,
branch on that variable recursively.
I Eventually compare all the IP-feasible solutions we obtain.
OR II: Branch & Bound and Heuristics 15 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Example
max 3x1 + x2
(P0 ) s.t. 4x 1 + 2x 2 ≤ 11
xi ∈ Z+ ∀i = 1, 2.
OR II: Branch & Bound and Heuristics 16 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblem 1
OR II: Branch & Bound and Heuristics 17 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Branching tree
OR II: Branch & Bound and Heuristics 18 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblem 2
I When we add x1 ≤ 2:
max 3x1 + x2
s.t. 4x1 + 2x2 ≤ 11
(P2 ) x1 ≤ 2
xi ≥ 0 ∀i = 1, 2.
OR II: Branch & Bound and Heuristics 19 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblem 3
I When we add x1 ≥ 3:
max 3x1 + x2
s.t. 4x1 + 2x2 ≤ 11
(P3 ) x1 ≥ 3
xi ≥ 0 ∀i = 1, 2.
I The problem is infeasible!
I This node is “dead” and does
not produce any candidate
solution.
OR II: Branch & Bound and Heuristics 20 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Branching tree
I The current progress can be summarized in the branching tree.
OR II: Branch & Bound and Heuristics 21 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Branching tree
3
I As x2 = 2 in x2 , we will branch subproblem 2 on x2 .
OR II: Branch & Bound and Heuristics 22 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblem 4
I When we add x2 ≤ 1:
3x1 + x2
max
4x1 + 2x2 ≤ 11
s.t.
(P4 ) x1 ≤ 2
x2 ≤ 1
xi ≥ 0 ∀i = 1, 2.
OR II: Branch & Bound and Heuristics 23 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblem 5
I When we add x2 ≥ 2:
max 3x1 + x2
s.t. 4x1 + 2x2 ≤ 11
(P5 ) x1 ≤ 2
x2 ≥ 2
xi ≥ 0 ∀i = 1, 2.
OR II: Branch & Bound and Heuristics 24 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Branching tree
I x4 satisfies all the integer constraints.
I It is IP-feasible and thus a candidate solution to the original IP.
I But branching subproblem 5 may result in a better solution.
OR II: Branch & Bound and Heuristics 25 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Branching tree
I Let’s branch subproblem 5 on x1 .
OR II: Branch & Bound and Heuristics 26 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblem 6
I When we add x1 ≤ 1:
max 3x1 + x2
s.t. 4x1 + 2x2 ≤ 11
x1 ≤ 2
(P6 ) x2 ≥ 2
x1 ≤ 1
xi ≥ 0 ∀i = 1, 2.
OR II: Branch & Bound and Heuristics 27 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblem 7
I When we add x1 ≥ 2:
max 3x1 + x2
s.t. 4x1 + 2x2 ≤ 11
x1 ≤ 2
(P7 ) x2 ≥ 2
x1 ≥ 2
xi ≥ 0 ∀i = 1, 2.
OR II: Branch & Bound and Heuristics 28 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Branching tree
OR II: Branch & Bound and Heuristics 29 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Bounding
I z6 = 132 . If we branch
(P6 ), all the candidate
solutions (if any) under it
will be (weakly) worse
than 132 .
I However, 13 2 < 7 = z4 ,
and x4 is already a
candidate!
I So there is no need to
branch (P6 ). This is the
“bounding” situation in
the branch-and-bound
algorithm.
I This allows us to solve
fewer subproblems.
OR II: Branch & Bound and Heuristics 30 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Summary
OR II: Branch & Bound and Heuristics 31 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Another example
OR II: Branch & Bound and Heuristics 32 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblem 1
I x1 = ( 15 9
4 , 4 ).
I We may branch on either
variable. Let’s branch on x1 .
OR II: Branch & Bound and Heuristics 33 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblems 2 and 3
I Subproblem 2 generates a
candidate solution.
I x3 = (4, 95 ). As
z3 = 41 > z2 = 39, we should
branch subproblem 3.
OR II: Branch & Bound and Heuristics 34 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblems 4 and 5
I x4 = ( 40
9 , 1). As
z4 = 40.56 > z2 = 39, we should
branch subproblem 4.
I Subproblem 5 is infeasible.
OR II: Branch & Bound and Heuristics 35 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblems 6 and 7
I x6 = (4, 1) but z6 = 37 < 39 = z2 .
I x7 = (5, 0) and z7 = 40 > 39 = z2 .
As it is also the last node, x7 is
an optimal solution.
OR II: Branch & Bound and Heuristics 36 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Remarks
I To select a node to branch:
I Among all alive nodes, there are many different ways of selecting a node
to branch.
I One common approach is to branch the node with the highest objective
value (for a maximization problem). Why?
I Another popular approach is “once a node is branched, all its
descendants are branched before any nondescendant. Why?
I Choosing a variable to branch on is also a challenging task.
I The branch-and-bound algorithm guarantees to find an optimal
solution, if one exists.
I However, it is an exponential-time algorithm.
I Roughly speaking, with n integer variables, the number of subproblems
solved is approximately proportional to 2n .
OR II: Branch & Bound and Heuristics 37 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Road map
I Linear relaxation.
I The branch-and-bound algorithm.
I Solving the knapsack problem.
I Heuristic algorithms.
OR II: Branch & Bound and Heuristics 38 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Item 1 2 3 4 5
Value ($) 2 3 4 1 3
Weight (kg) 4 5 3 1 4
OR II: Branch & Bound and Heuristics 39 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
OR II: Branch & Bound and Heuristics 40 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
OR II: Branch & Bound and Heuristics 41 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblems 1, 2, and 3
I We solve the linear relaxation and
get x1 = (0, 0.6, 1, 1, 1) with
objective value 9.8.
I We branch on x2 .
I With x2 ≤ 0: x2 = (0.75, 0, 1, 1, 1)
and z2 = 9.5.
I We set x2 = 0 and then apply
the sorting idea on the
remaining.
I With x2 ≥ 1: x3 = (0, 1, 1, 1, 0.5)
and z3 = 9.5.
I We set x2 = 1 and then apply
the sorting idea on the remaining
four variables and residual
capacity 6.
OR II: Branch & Bound and Heuristics 42 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblems 4 and 5
I We branch the
node for x2 .
I With x2 ≤ 0 and
x1 ≤ 0:
x4 = (0, 0, 1, 1, 1)
and z4 = 8. x4 is
the first candidate
solution.
I With x2 ≤ 0 and
x1 ≥ 1:
x5 = (1, 0, 1, 1, 34 )
with z5 = 9.25.
OR II: Branch & Bound and Heuristics 43 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblems 6 and 7
I We branch the
node for x3 .
I With x2 ≥ 1 and
x5 ≤ 0:
x6 = (0.5, 1, 1, 1, 0)
and z6 = 9.
I With x2 ≥ 1 and
x5 ≥ 1:
x7 = (0, 1, 23 , 0, 1)
and z7 = 263 .
OR II: Branch & Bound and Heuristics 44 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Subproblems 8 and 9
I With x2 ≤ 0,
x1 ≥ 1, x5 ≤ 0:
x8 = (1, 0, 1, 1, 0)
and z8 = 7.
I With x2 ≤ 0,
x1 ≥ 1, x5 ≥ 1:
x9 = (1, 0, 1, 0, 1)
and z9 = 9. x9
becomes the
currently best
candidate.
I No need to branch
the nodes for x6
and x7 (why?).
I x9 is optimal.
OR II: Branch & Bound and Heuristics 45 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Remarks
OR II: Branch & Bound and Heuristics 46 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Road map
I Linear relaxation.
I The branch-and-bound algorithm.
I Solving the knapsack problem.
I Heuristic algorithms.
OR II: Branch & Bound and Heuristics 47 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Item 1 2 3 4 5
Value ($) 2 3 4 1 3
Weight (kg) 4 5 3 1 4
I The formulation is
OR II: Branch & Bound and Heuristics 48 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
OR II: Branch & Bound and Heuristics 49 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
A greedy algorithm
I Our intuitive greedy algorithm may serve as a good one.
I First, we sort all items by their value-to-weight ratios from large to small.
I Along the order, we then try to put each item into the knapsack. If
possible, do it; otherwise, throw it away.
I We stop when all items are tried once.
I Recall our example:
Item 1 2 3 4 5
Value ($) 2 3 4 1 3
Weight (kg) 4 5 3 1 4
OR II: Branch & Bound and Heuristics 50 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Optimality gap
z ∗ − z ALG
= 11.1%.
z∗
OR II: Branch & Bound and Heuristics 51 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Performance evaluation
I To test the average-case performance of a heuristic algorithm:
I Small-scale random instances are generated.
I Each instance is solved by the algorithm and an exact one.
I All the percentage errors are averaged.
I The smaller the average percentage error, the better the algorithm.
I Moreover:
I Large-scale random instances are generated.
I Each instance is solved by the algorithm.
I An upper bound of the objective value of an optimal solution (for a
maximization problem) is obtained (e.g., by linear relaxation).
I The smaller the average percentage error (which is an upper bound for
that calculated with an optimal solution), the better the algorithm.
I In the above example:
I Linear relaxation gives xLR = (0, 0.6, 1, 1, 1) with z LR = 9.8.
LR ALG
I The errors are z LR − z ALG = 1.8 and z −z = 18.4%.
z LR
OR II: Branch & Bound and Heuristics 52 / 53 Ling-Chieh Kung (NTU IM)
Linear relaxation Branch and bound Solving the knapsack problem Heuristic algorithms
Remarks
I Some people refer to the gap between a reported solution and an upper
bound (rather than an optimal solution) as the optimality gap.
I Some people analyze the problem and heuristic algorithm to prove a
worst-case performance guarantee.
I Fascinating but difficult.
I Designing (or proposing) a heuristic algorithm is simple. Evaluation
and analysis are hard.
I Thanks to integer programming, branch and bound, and linear
relaxation:
I We may generate an optimal solution.
I We may use an optimal solution or its upper/lower bound as a
benchmark to evaluate a feasible solution.
I We may thus evaluate a heuristic algorithm.
OR II: Branch & Bound and Heuristics 53 / 53 Ling-Chieh Kung (NTU IM)