Lecture#6 - Branch-and-Bound Algorithm
Lecture#6 - Branch-and-Bound Algorithm
C S E - 2 3 7 : A L G O R I T H M D E S I G N A N D A N A LY S I S
BASIC TERMINOLOGY
• Branch and Bound (BnB) is an algorithm design paradigm which is generally used for
solving combinatorial optimization problems.
• These problems are typically exponential in terms of time complexity and may require
exploring all possible permutations in worst case.
• The Branch and Bound Algorithm technique solves these problems relatively quickly.
• Bounding refers to setting a bound on the solution quality and trimming off branches in
the solution tree (pruning) whose solution quality is estimated to be poor.
• The following figure is the state space tree of the 0/1 backpack problem for 3 products:
• Grpah Search as Tree Search <=> Finding the paths reachable from the node S
• State Space - described by an initial state, a set of possible actions and a goal
state.
• A State Space Tree - the collection of all possible states, a problem can have.
• A Path - any sequence of actions that lead from a state to another state and
finally reached (hopefully) the goal node.
• Path cost - the aggregated of a path that lead to the goal state.
• Goal Test - whether the goal (optimal) is found in the state space problem
Greedy Algorithms 10
8 PUZZLE PROBLEM
1 5 2 1 2 3
7 8 6 7 8
• Initial State: The location of each of the 8-puzzle in one of the nine squares
• Path cost: Each step costs 1 point, total path cost will be equal to the number of steps
taken
• Goal test: State matches the goal configuration (given board pattern)
• Operators: blank moves [1] Left, [2] Right, [3] Up & [4] Down.
1 5 2
• Consider the following generalized evaluation function
4 3
f(n) = g(n) + h(n)
7 8 6
where n is any state in the search
g(n) is the cost from the start state1 5 2 1 5 1 5 2
h(n) is the heuristic estimate of
4 3 4 3 2 4 3 6
the cost to the goal node
7 8 6 7 8 6 7 8
1 5 2
4 3 6
3 4
7 8 • Two Potential
No of Tiles Sum of the
Out of place Manhattan Distances Cost functions
• Cost Function,
f(n) = g(n) + h(n)
• The searches begin by visiting the root node of the search tree, given by the initial state.
• Among other book-keeping details, three major things happen in sequence in order to
visit a node:
• Finally, if the result of the check is negative, we then expand the node.
Goal State
Initial State
• Note that if these successor nodes are already in the frontier, or have
already been visited, then they should not be added to the frontier again.
Goal State
THE PATH TO THE GOAL NODE WITH BFS THE NODES EXPANDED BY BFS ARE
IS SHOWN IN THE FOLLOWING FIGURE: SHOWN IN THE FOLLOWING FIGURE:
THE PATH TO THE GOAL NODE WITH DFS THE NODES EXPANDED BY BFS ARE
IS SHOWN IN THE FOLLOWING FIGURE: SHOWN IN THE FOLLOWING FIGURE:
Greedy Algorithms 21
N-QUEEN PROBLEM
• Practice #1 : n queens need to be placed on different columns, and check which row each
queen is on the column to which it belongs is where it should be placed.
• i.e. the size of the answer-state space is n x n x n x… x n = nn [ 256 for n=4 ]
• Practice #2 : n queens need to be placed in different columns and different rows. In addition
to the position of the queen who was placed before, it is necessary to check which row of
each queen is the place where it should be placed.
• i.e. the size of answer-state space is n x (n-1) x (n-2) x… x 1 = n! [ 24 for n=4 ]
X1 1 4
2 3
X2 2 4 1 4 1 4 1 3
3 3 2 2
X3 3 4 2 4 2 3 3 4 1 4 1 3 2 4 1 4 1 2 2 3 1 3 1 2
X4 4 3 4 2 3 2 4 3 4 1 3 1 4 2 4 1 2 1 3 2 3 1 2 1
• Assuming that the position of Queen Q1 is (a, xa) and the position of Queen Q2 is (b,
xb), the following positions will cause the two queens to eat each other.
1
1 4
2 3
2 11 18 25
2 4 1 4 1 4 1 3
3 3 2 2
3 4 7 12 13 14 19 23 24 26 30 33
3 4 2 4 2 3 3 4 1 4 1 3 2 4 1 4 1 2 2 3 1 3 1 2
5 6 8 10 15 17 20 21 27 28 31 32
4 3 4 2 3 2 4 3 4 1 3 1 4 2 4 1 2 1 3 2 3 1 2 1
9 16 22 29
() ()
Greedy Algorithms 27
GRAPH (VERTEX) COLORING PROBLEM
• The smallest number of colors required to color a graph G is called its chromatic
number of that graph. Graph coloring problem is a NP Complete problem.
• The steps required to color a graph G with n number of vertices are as follows −
• Step 2 − Choose the first vertex and color it with the first color.
• Step 3 − Choose the next vertex and color it with the lowest numbered color that has not
been colored on any vertices adjacent to it.
• If all the adjacent vertices are colored with this color, assign a new color to it.
• Repeat this step until all the vertices are colored.
1
1
4
2 2 3 4
3
6 6
5
5
1 4 5
3, 1 3, 2 4
2 3
6 7
3 4 4, 1 4, 2
2
5 6
8
5, 1
5 6 Coloring the Map with k=3
9 10 11
Graphical Presentation of Map 6, 1 6, 2 6, 3