05 Informed Searching Minimax
05 Informed Searching Minimax
Artificial Intelligence
• Diketahui posisi tile 1 di Start State (2,2) dan di Goal State (0,0)
• Hitung Dman(1) = |2-0|+|2-0| = 2 + 2 = 4
o h1(s) = 6
o h2(s) = Dman(1) + Dman(2)+ Dman(3) + Dman(4)+ Dman(5) + Dman(6)+ Dman(7)
+ Dman(8)= 4+0+3+3+1+0+2+1=14
Merancang Heuristic
Latihan Admissible Heuristic
o Perhatikan 8-puzzle berikut :
d
Dman x, y x j y j
j 1
3 3 4
5 3
4
2
4 2 1
3 3
0
4
5 4
A* Search
f(N) = g(N) + h(N) dengan h(N) = jumlah angka
yang salah posisi
3+3
1+5 2+3
3+4
5+2
0+4 3+2 4+1
1+3 2+3
5+0
3+4
1+5 2+4
A* Search
f(N) = h(N) = jarak semua angka dari posisi
yang benar (base Manhattan Distance)
6 5
2
5 2 1
4 3
0
4
6 5
Admissible Heuristics
Consistency sebuah heuristic :
o Sebuah heuristic dikatakan consistent jika :
h(n) ≤ c(n, a, n’) + h(n’)
o Jika h konsisten, maka :
f(n’) = g(n’) + h(n’)
= g(n) + c(n, a, n’) + h(n’)
≥ g(n) + h(n)
≥ f(n)
o Pada sembarang path, nilai f(n) tidak pernah turun
(nondecreasing), atau monotonic.
o Theorem : If h(n) is consistent, A* using GRAPH-
SEARCH is optimal
Admissible Heuristics
Bukti optimalitas A*(2)
o Node expansion A* berdasarkan urutan nilai f .
o Bayangkan penelusuran state space yang dilakukan
A* menambahkan f-contour.
MIN
2 1 3 - Propagate the evaluation
function upwards:
- Taking minima in MIN
- Taking maxima in MAX
MAX
2 5 3 1 4 4 3
Minimax Example
MAX 1 A
Select this move
MIN 1 B -3 C
MAX 4 D 1 E 2 F -3 G
4 -5 -5 1 -7 2 -3 -8
MAX 2 Alpha-value
MIN 2 =2 Beta-value
1
MAX
2 5 1
Algoritma Alpha-beta Pruning
If an Beta-value is smaller or equal than the Alpha-value of a
descendant node: stop generation of the children of the descendant
MAX 2
MIN 2 =2 Beta-value
1
MAX Alpha-value
2 5 3
Algoritma Alpha-beta Pruning
MAX A
MIN ≤6 B C
MAX 6 D ≥8 E
H I J K
6 5 8
= agent = opponent
Algoritma Alpha-beta Pruning
MAX ≥6 A
MIN 6 B ≤2 C
MAX 6 D ≥8 E 2 F G
H I J K L M
6 5 8 2 1
= agent = opponent
Algoritma Alpha-beta Pruning
MAX ≥6 A
MIN 6 B 2 C
MAX 6 D ≥8 E 2 F G
H I J K L M
6 5 8 2 1
= agent = opponent
Algoritma Alpha-beta Pruning
MAX 6 A
MIN 6 B 2 C beta
cutoff
MAX 6 D ≥8 E 2 F G
alpha
cutoff
H I J K L M
6 5 8 2 1
= agent = opponent
Mini-Max with at work:
4 16 5 31 = 5 39
MAX
8 6 5 23
= 4 15 = 5 30 3 38
MIN
2 10 1 18
1 33
8 2 4 12 3 20 3 25 2 35
=8 5 9 8 = 4 14 = 5 22 9 27 6 29 = 3 37
MAX
8 7 3 9 1 6 2 4 1 1 3 5 3 9 2 6 5 2 1 2 3 9 7 2 8 6 4
1 3 4 7 9 11 13 17 19 21 24 26 28 32 34 36
11 static evaluations saved !!
Example of a perfectly ordered tree
21 MAX
21 12 3 MIN
21 24 27 12 15 18 3 6 9
MAX
21 20 19 24 23 22 27 26 25 12 11 10 15 14 13 18 17 16 3 2 1 6 5 4 9 8 7
Algoritma Alpha-beta Pruning
Kesimpulan :
o alpha-beta algorithm does the same calculation as
minimax, and is more efficient since it prunes
irrelevant branches.
o usually, the complete game tree is not expanded,
search is cut off at some point and an evaluation
function calculated to estimate the utility of a state.
o So far, for a possibly good and efficient search:
• select good search method/technique
• provide info/heuristic if possible
• apply prune irrelevant branches
Ringkasan
Best-first search :
o Uniform-cost search : f(n) = g(n)
o Greedy best-first search : f(n) = h(n)
o A* search : f(n) = g(n) + h(n)
Dengan heuristic yang admissible dan consistent , A* pasti complete dan
optimal.
Heuristic dapat diperoleh dari variasi masalah yang dipermudah, atau
submasalah.
Search di mana environment-nya tidak observable atau non-
deterministic masih bisa diatasi.
Permasalahan utama : menghindari local maximum secara stochastic.
Selesai