Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 41

Uniform Cost Search &

Branch and Bound Search


Uniform Cost Search (UCS)

5 2
[5] [2]
1 4 1 7
[6] [9] [3] [9]
Goal state
4 5

[x] = g(n) [7] [8]


path cost of node n

2
Uniform Cost Search (UCS)

5 2
[5] [2]

3
Uniform Cost Search (UCS)

5 2
[5] [2]
1 7
[3] [9]

4
Uniform Cost Search (UCS)

5 2
[5] [2]
1 7
[3] [9]
4 5

[7] [8]

5
Uniform Cost Search (UCS)

5 2
[5] [2]
1 4 1 7
[6] [9] [3] [9]
4 5

[7] [8]

6
Uniform Cost Search (UCS)

5 2
[5] [2]
Goal state
1 4 1 7
path cost
g(n)=[6] [3] [9]
[9]
4 5

[7] [8]

7
Uniform Cost Search (UCS)

5 2
[5] [2]
1 4 1 7
[6] [9] [3] [9]
4 5

[7] [8]

8
Uniform Cost Search (UCS)
 In case of equal step costs, Breadth First search finds
the optimal solution.

 For any step-cost function, Uniform Cost search


expands the node n with the lowest path cost.

 UCS takes into account the total cost: g(n).

 UCS is guided by path costs rather than depths.


Nodes are ordered according to their path cost.
9
Uniform Cost Search
This algorithm assumes that all operators have a cost:
1. Initialize: Set OPEN = {s}, CLOSED = { } Set C(s) = 0
2. Fail: If OPEN = { }, then terminate with failure
3. Select: Select the minimum cost state, n, from OPEN
Save n in CLOSED
4. Terminate: If n  G, terminate with success
5. Expand: Generate the successors of n using O.
For each successor, m:
If m [OPEN  CLOSED]
Set C(m) = C(n) + C(n,m) and insert m in OPEN
If m  [OPEN  CLOSED]
Set C(m) = min {C(m), C(n) + C(n,m)}
If C(m) has decreased and m  CLOSED, move it to OPEN
6. Loop: Go To Step 2.
Example of Uniform Cost Search
• Assume an example tree with different edge costs, represented by
numbers next to the edges.

2 a
1
b c
1 2 1 2
f gc dc ec

Notations for this example:


generated node
expanded node
Example of Uniform Cost Search

2 a
1

Closed list:

Open list: a
0
Example of Uniform Cost Search
2 a
1
b c
1 2 1 2

Closed list: a

Open list: b c
2 1
Example of Uniform Cost Search

2 a
1
b c
1 2 1 2
dc ec

Closed list: a c

Open list: b d e
2 2 3
Example of Uniform Cost Search
2 a
1
b c
1 2 1 2
f gc dc ec

Closed list: a c b

Open list: d e f g
2 3 3 4
Example of Uniform Cost Search
2 a
1
b c
1 2 1 2
f gc dc ec

Closed list: a c b d

Open list: e f g
3 3 4
Example of Uniform Cost Search
2 a
1
b c
1 2 1 2
f gc dc ec

Closed list: a c b d e

Open list: f g
3 4
Example of Uniform Cost Search
2 a
1
b c
1 2 1 2
f gc dc ec

Closed list: a c b d e f

Open list: g
4
Example of Uniform Cost Search
2 a
1
b c
1 2 1 2
f gc dc ec

Closed list: a c b d e f g

Open list:
Traveling Salesman Problem
• Solution: Branch and Bound Path Search Technique
The cost matrix is
∞ 20 30 10 11
15 ∞ 16 4 2
3 5 ∞ 2 4
19 6 18 ∞ 3
16 4 7 16 ∞
Step 1: Find the reduced cost matrix

•Apply now reduction method:


•Deduct 10 (which is the minimum) from all values in the 1 st row.
•Deduct 2 (which is the minimum) from all values in the 2 nd row.
•Deduct 2 (which is the minimum) from all values in the 3 rd t row.
•Deduct 3 (which is the minimum) from all values in the 4 th row.
•Deduct 4 (which is the minimum) from all values in the 5 th row.
Row Reduction

∞ 10 20 0 1
13 ∞ 14 2 0
The resulting row wise reduced cost matrix = 1 3 ∞ 0 2
16 3 15 ∞ 0
12 0 3 12 ∞
Row wise reduction sum = 10+2+2+3+4=21.
•Now apply column reduction for the above matrix:
•Deduct 1 (which is the minimum) from all values in the 1 st column.
•Deduct 3 (which is the minimum) from all values in the 2 nd column.
Column Reduction

∞ 10 17 0 1
12 ∞ 11 2 0
The resulting column wise reduced cost matrix (A) = 0 3 ∞ 0 2
15 3 12 ∞ 0
11 0 3 12 ∞
Column wise reduction sum = 1+0+3+0+0=4.
Cummulative
Cumulative reduced sum = row wise reduction + column wise reduction sum.
=21+ 4 =25.

You might also like