You are on page 1of 9

TRƯỜNG ĐẠI HỌC BÁCH KHOA TP.

HCM
Khoa Khoa học & Kỹ thuật Máy tính

ARTIFICIAL INTELLIGENCE
Tutorial 3 Solutions

HEURISTIC SEARCH AND GAME PLAYING

Question 1.

The heuristic path algorithm is a best-first search in which the objective function is
f(n) = (2 - w).g(n) + w.h(n)
For what values of w is this algorithm guaranteed to be optimal? (You may assume that h
is admissible) What kind of search does this perform when w = 0? When w = l? When
w = 2?

Solution:
The algorithm guaranteed to be optimal when w = 0. This behaves exactly like uniform-
cost search – the factor of two makes no difference in the ordering of the nodes.
w = 0: uniform-cost search.
w = 1: A* search.
w = 2: greedy search.

Question 2. Prove each of the following statements:

a. Breadth-first search is a special case of uniform-cost search.


b. Breadth-first search, depth-first search, and uniform-cost search are special cases of
best-first search.
c. Uniform-cost search is a special case of A* search.

Solution:
a. When all step costs are equal, g(n) ~ depth(n), so uniform-cost search reproduces
breadth-first search.

b. Breadth-first search is best-first search with f(n) = depth(n).


Depth-first search is best-first search with f(n) = - depth(n).
Uniform-cost search is best-first search with f(n) = g(n).

c. Uniform-cost search is A* search with h(n) = 0.

1
TRƯỜNG ĐẠI HỌC BÁCH KHOA TP.HCM
Khoa Khoa học & Kỹ thuật Máy tính

Question 3.

Figure 1 – A road map of Romania

Figure 1 gives a simplified road map of Romania, in which the road distances between
cities are indicated. Meanwhile, Table 1 presents the straight-line distance from the cities
to Bucharest.

2
TRƯỜNG ĐẠI HỌC BÁCH KHOA TP.HCM
Khoa Khoa học & Kỹ thuật Máy tính

Table 1 – The straight-line distances to Bucharest

a. Find a path from Arad to Bucharest using the greedy algorithm, in which the h function
is defined as the straight-line distance given in Table 1. Present the total cost and the
nodes (cities) to be expanded, in the corresponding order.

b. Find a path from Arad to Bucharest using the uniform-cost search algorithm, in which
the g function is defined as the road distance given in Figure 1. Present the total cost and
the nodes (cities) to be expanded, in the corresponding order.

c. Find a path from Arad to Bucharest using A* algorithm, whose g and f functions are as
presented in Question 1a and 1b. Present the actual total cost and the nodes (cities) to be
expanded, in the corresponding order.

d. Find a case that the greedy function will suffer infinitive loop when finding path
between cities in Romania?

Solution:
a. The path: Arad -> Sibiu -> Fagaras -> Bucharest
The total cost: 140 + 99 + 211 = 450
The order of expanded nodes: same as the path.

3
TRƯỜNG ĐẠI HỌC BÁCH KHOA TP.HCM
Khoa Khoa học & Kỹ thuật Máy tính

b. The path: Arad -> Sibiu -> Rimnicu Vilcea -> Pitesti -> Bucharest
The total cost: 140 + 80 + 97 + 101 = 418
The order of expanded nodes: Arad (0), Zerind (70), Timisoara (118), Sibiu (140),
Oraeda (146), Rimnicu Vilcea (220), Lugoj (229), Fagaras (239), Mehadia (299), Pitesti
(317), Craiova (366), Dobreta (374), Bucharest (418).

c. The path: Arad -> Sibiu -> Rimnicu Vilcea -> Pitesti -> Bucharest
The actual total cost: 140 + 80 + 97 + 101 = 418
The order of expanded nodes: Arad (366), Sibiu (393), Rimnicu Vilcea (413), Pitesti
(415), Fagaras (417), Bucharest (418).

d. Find a path from Iasi to Fagaras.

Question 4.

Given a tree of a game state as presented in Figure 2 (assume that node A is


corresponding to the MAX’s player). If directly applied in the nodes, the static function
will yield the results as given in Table 2.

Figure 2 – A game-state tree

Table 2 – The results returned by the static function when directly applied

Node Score
A 0.95
B 0.25
C 0.1
D 0.05
E 1.0
F -1.0

4
TRƯỜNG ĐẠI HỌC BÁCH KHOA TP.HCM
Khoa Khoa học & Kỹ thuật Máy tính

G -0.2
H -0.7
I 0.75
J -1.0

State the next move that the game playing program will choose if using a Minimax
algorithm. Redraw the subtree with nodes associated with the corresponding evaluated
scores. Suppose that the Minimax algorithm will be set to cover:

a. Up to level 1
b. Up to level 2
c. Unlimited depth.

Solution:
a. Selected move: B

b. Selected move: D

5
TRƯỜNG ĐẠI HỌC BÁCH KHOA TP.HCM
Khoa Khoa học & Kỹ thuật Máy tính

c. Generally, the program will choose randomly between B, C and D. It is up to students


to draw the corresponding tree themselves.

Question 5.

Figure 3 presents a resultant tree when the Minimax algorithm is fully applied on the tree.
In the best case of applying alpha-beta prunes (i.e. best nodes will be incidentally visited
first), which nodes (and branches) will be cut-off?

Figure 3 - A game-state tree with Minimax applied

Solution:

6
TRƯỜNG ĐẠI HỌC BÁCH KHOA TP.HCM
Khoa Khoa học & Kỹ thuật Máy tính

Question 6.

Figure 4 presents a resultant Minimax-applied tree. What are the corresponding resultant
trees when the alpha-beta prunes are applied in the following cases:

a. Normal case: nodes will be visited from left to right when in the same levels
b. Best case
c. Worst case

Figure 4 - A resultant Minimax-applied tree

Solution:

7
TRƯỜNG ĐẠI HỌC BÁCH KHOA TP.HCM
Khoa Khoa học & Kỹ thuật Máy tính

a.

Evaluation times: 14
Static evaluation times: 6

b.

Evaluation times: 9
Static evaluation times: 4

8
TRƯỜNG ĐẠI HỌC BÁCH KHOA TP.HCM
Khoa Khoa học & Kỹ thuật Máy tính

c.

Evaluation times: 22
Static evaluation times: 13

-- End --

You might also like