You are on page 1of 55

Course : T0264 – Artificial Intelligence

Year : 2013

LECTURE 03
Searching: Informed Search I
Learning Outcomes

At the end of this session, students will be able to:


» LO 1 : Describe what is AI and identify concept of
intelligent agent
» LO 2 : Explain various intelligent search
algorithms to solve the problems

T0264 - Artificial Intelligence 3


Outline

1. Generate and Test


2. Best First Search (Greedy) Algorithm
3. A* Search Algorithm
4. Summary

T0264 - Artificial Intelligence 4


Generate And Test
http://intelligence.worldofcomputing.net/ai-search/generate-and-test-search.html
» Generate and Test Search Algorithm is a very simple
algorithm that guarantees to find a solution if done
systematically and there exists a solution

» For complex problems even heuristic generate-and-test is


not very effective technique. But this may be made effective
by combining with other techniques in such a way that the
space in which to search is restricted

» 1. Generate a possible solution


2. Test to see if this is the expected solution
3. If the solution has been found quit else go to step 1
T0264 - Artificial Intelligence 6
Generate And Test

» Potential solutions that need to be generated vary


depending on the kinds of problems. For some problems
the possible solutions may be particular points in the
problem space and for some problems, paths from the
start state.
» Generate-and-test, like depth-first search, requires that
complete solutions be generated for testing. In its most
systematic form, it is only an exhaustive search of the
problem space. Solutions can also be generated
randomly but solution is not guaranteed. This approach
is what is known as British Museum algorithm: finding an
object in the British Museum by wandering randomly.

T0264 - Artificial Intelligence 7


Generate And Test

Generate and Test Diagram

T0264 - Artificial Intelligence 8


Generate And Test

Systematic Generate-And-Test
» While generating complete solutions and generating
random solutions are the two extremes there exists
another approach that lies in between. The approach is
that the search process proceeds systematically but
some paths that unlikely to lead the solution are not
considered. This evaluation is performed by a heuristic
function.
» Depth-first search tree with backtracking can be used to
implement systematic generate-and-test procedure. As
per this procedure, if some intermediate states are likely
to appear often in the tree, it would be better to modify
that procedure to traverse a graph rather than a tree.
T0264 - Artificial Intelligence 9
Generate And Test

» Traveling Salesman Problem


8
A B Find the sort path of TSP
graph by using generate
7 5
4 and test algorithm!
3

C 6
D

T0264 - Artificial Intelligence 10


Termasuk dalam Blind Search

Breadth First Search : semua node dikunjungi


sehingga jika ada solusi pasti diketemukan atau
tidak terjebak jalan buntu. Tetapi membutuhkan
memori besar dan waktu pencarian relatif lama.

Dept First Search : node dikunjungi dari ranting paling


kiri. Jika ada solusi bisa diketemukan lebih cepat,
membutuhkan memori kecil dan waktu pencarian
lebih singkat. Tetapi bisa terjebak dalam jalan buntu.

05/01/2020 T0264 - Artificial Intelligence 11


Saat ini: informed search
Informed search:
Menggunakan heuristics untuk mengarahkan
search
 Best first
 A*
 Heuristics
 Hill-climbing
 Simulated annealing

05/01/2020 12
T0264 - Artificial Intelligence
Pelacakan Heuristik

» Heuristik  suatu perbuatan yg membantu utk


menemukan jalan dalam pohon pelacakan yg
menuntun kpda solusi masalah
» Suatu kaidah yg merupakan metode atau prosedur
yg didasarkan kpd pengalaman dan prakter , saran,
trik atau bantuan lainnya membantu
mempersempit dan memfokuskan proses pelacakan
kpd suatu tujuan tertentu
» Membantu mengurangi wilayah pelacakan atau
regenerasi node yg bisa menimbulkan berbagai
alternatif solusi  bisa membimbing ke arah satu
solusi yg jelas
05/01/2020 T0264 - Artificial Intelligence 13
Best-first search
» Idea:
 menggunakan evaluation function untuk setiap node;
perkiraan “desirability”
 ekspan ke node yang paling diinginkan.

» Implementasi:
 QueueingFn = masukkan suksesor dalam penurunan orde
dari yang diinginkan

» Kasus khusus:
 greedy search
 A* search

05/01/2020 14
T0264 - Artificial Intelligence
05/01/2020 T0264 - Artificial Intelligence 15
05/01/2020 T0264 - Artificial Intelligence 16
05/01/2020 T0264 - Artificial Intelligence 17
Romania dengan langkah costs dalam km

374

253

329

05/01/2020 18
T0264 - Artificial Intelligence
Greedy search
» Fungsi perkiraan:
h(n) = perkiraan biaya dari n ke goal (heuristic)

» Contoh:
hSLD(n) = jarak garis lurus dari n ke Bucharest

» Greedy search meng-ekspan node pertama yang


nampaknya terdekat ke goal, menurut h(n).

05/01/2020 19
T0264 - Artificial Intelligence
05/01/2020 T0264 - Artificial Intelligence 20
05/01/2020 T0264 - Artificial Intelligence 21
Algoritma : Greedy Best - First
Search

1. Mulai dengan Frontier hanya berisi state awal.


2. Hingga goal didapat atau tidak ada lagi node
tertinggal pada Frontier kerjakan :
(a) Pilih node terbaik pada Frontier.
(b) Hasilkan suksesornya.
(c) Untuk setiap suksesor kerjakan :
I. Jika dia belum dihasilkan (generate)
sebelumnya, evaluasi, tambahkan ke
Frontier, dan catat parent-nya.

05/01/2020 T0264 - Artificial Intelligence 22


II. Jika dia sudah dihasilkan (generate) sebelumnya,
rubah parent-nya jika path baru ini lebih baik dari
sebelumnya. Dalam hal ini, update biaya untuk
mendapatkan node ini dan suksesornya yang
mungkin sudah dimiliki node ini.

05/01/2020 T0264 - Artificial Intelligence 23


05/01/2020 T0264 - Artificial Intelligence 24
Sifat Greedy Search
» Complete? Tidak – dapat terikat daalam loop
mis., Iasi > Neamt > Iasi > Neamt > …
Complete jika space terbatas dengan check pengulangan state.

» Time ? O(b^m) tetapi heuristik yang bagus


dapat memberikan kemajuan dramatis

» Space ? O(b^m) – menyimpan semua node


dalam memori

» Optimal ? Tidak.

05/01/2020 25
T0264 - Artificial Intelligence
Best First Search
(Greedy)
Step 1 Step 2 Step 3
A A A

B (3) C (5) D (1) B (3) C (5) D

Step 4 A Step 5 A
E (4) F (6)

B C (5) D B C (5) D

G (6) H (5) E (4) F (6) G (6) H (5) E F (6)

I (2) J (1)

T0264 - Artificial Intelligence 26


Best First Search
(Greedy)
Underestimates
A

B (3+1) C (4+1) D (5+1)

E (3+2)

F (3+3)

T0264 - Artificial Intelligence 27


Best First Search
(Greedy)
Overestimates A

B (3+1) C (4+1) D (5+1)

E (2+2)

F (1+3)

G (0+4)

T0264 - Artificial Intelligence 28


Best First Search
(Greedy)

Example: Puzzle Games

» H = 1 (true position); find tree solution of game by Best


First Search technical

T0264 - Artificial Intelligence 29


05/01/2020 T0264 - Artificial Intelligence 30
Algoritma Heuristic A*

1. Set FRONTIER={S}, dan EXPLORED={}, dng S dipilih node sbg state


awal.
2. Kerjakan jika FRONTIER blm kosong
a. Cari node dari FRONTIER dimana nilai f(n) minimal. Tempatkan n pd
EXPLORED.
b. Jika n adalah goal, keluar, SUKSES.
c. Ekspan node n.
d. Kerjakan utk setiap anak n, yaitu n’ :
1) Jika n’ belum ada di FRONTIER atau EXPLORED, maka :
a) Masukkan n’ ke FRONTIER. Kemudian set backpointer dari n’ ke n.
b) Hitung :
(1) h(n’)
(2) G(n’) = g(n)+c(n,n’) adalah biaya dari n ke n’, dan
(3) F(n’) = g(n’)+h(n’)
2) Jika n’ telah ada di di FRONTIER atau EXPLORED dan jika
g(n’) lebih kecil untuk versi n’ yang baru, maka :
a) Buang versi lama n’
b) Ambil n’ di FRONTIER, dan set backpointer dari n’ ke n.

05/01/2020 T0264 - Artificial Intelligence 31


05/01/2020 T0264 - Artificial Intelligence 33
05/01/2020 T0264 - Artificial Intelligence 34
05/01/2020 T0264 - Artificial Intelligence 35
05/01/2020 T0264 - Artificial Intelligence 36
05/01/2020 T0264 - Artificial Intelligence 37
05/01/2020 T0264 - Artificial Intelligence 38
05/01/2020 T0264 - Artificial Intelligence 39
05/01/2020 T0264 - Artificial Intelligence 40
05/01/2020 T0264 - Artificial Intelligence 41
05/01/2020 T0264 - Artificial Intelligence 42
05/01/2020 T0264 - Artificial Intelligence 43
Fungsi evaluasi

Fungsi evaluasi :
f(n) = h(n) + g(n)
dimana :
f(n) = fungsi evaluasi
g(n) = biaya yang sudah dikeluarkan
dari state awal sampai state n.
h(n) = estimasi biaya untuk sampai
pada suatu tujuan mulai dari n.

05/01/2020 T0264 - Artificial Intelligence 44


Perbandingan 3 algoritma

» Greedy Best-first search


 Yang dipilih nilai h(n) terbaik
» Uniform-cost search
 Yang dipilih nilai g(n) terbaik
» Heuristic A*
 Yang dipilih nilai h(n) + g(n) terbaik

05/01/2020 T0264 - Artificial Intelligence 45


Contoh Soal

S
(3.0)
(1.0)
(2.0)
C (7.0)
A (2.0)

(5.0) (2.0) B (5.0)

(1.0)
D (20.0) E (9.0)

(3.0) F

(5.0)
(1.0)

G (0.0)

05/01/2020 T0264 - Artificial Intelligence 46


Pertanyaan

Berapa node yang diekspand dan sebut path


yang dilalui jika menggunakan :
• Greedy Best first search (bukan BFS)
• Uniform-cost search
• Heuristic A* search

05/01/2020 T0264 - Artificial Intelligence 47


Greedy Best First Search (f(n)=h(n))

S
frontier = [S], explored = []
Evaluasi S, frontier = [A(2), B(5), C(7)],
(7.0) C
A (2.0) explored = [S]
Evaluasi A, frontier = [B(5), C(7), E(9), D(20)],
B (5.0)
explored = [S,A]
Evaluasi B, frontier = [F(3), C(7), E(9), D(20)],
D (20.0) E (9.0)
explored = [S,A,B]
(3.0) F Evaluasi F, frontier = [G(0), C(7), E(9), D(20)],
explored = [S,A,B]
Evaluasi G = goal ,STOP, frontier = [],
explored = [S,A,B]
Jadi urutan node yang dievaluasi : [S,A, B]
dengan jalur solusi : S-B-F-G.
G (0.0)

05/01/2020 T0264 - Artificial Intelligence 48


S
f = {S}; inisial
f= {A, B, C}; dipilih A,B dan C
(7.0) C sebagai suksesor S
A (2.0) f= {B, C, D, E}; h dari A = 2.0 dipilih utk
B (5.0) diekspan jadi D & E
f= {C, D, E, F}; h dari B = 5.0 dipilih utk
D (20.0) E (9.0)
diekspan jadi F
(3.0) F
f= {C, D, E, G} h dari F = 3 dipilih utk
diekspan jadi G
(goal)
Node expanded = 7,

G (0.0)
Path = S-B-F-G.

05/01/2020 T0264 - Artificial Intelligence 49


Uniform-Cost search (f(n)=g(n))

S frontier = [S], explored = []


Evaluasi S, frontier = [A(1), B(2), C(3)], explored = [S]

C (3.0)
Evaluasi A, frontier = [B(2),C(3),E(3),D(6)], explored =
A (1.0) [S,A]
Evaluasi B, frontier = [C(3),E(3),F(3),D(6)], explored =
B (2.0)
[S,A,B]
Evaluasi C, frontier = [E(3),F(3),D(6)], explored =
D(6.0) E (3.0) [S,A,B,C]
F (3.0) Evaluasi E, frontier = [F(3),D(6),G(8)], explored =
[S,A,B,C,E]
Evaluasi F, frontier = [G(5),D(6),G(8)], explored =
[S,A,B,C,E,F]
Evaluasi G = goal ,STOP, frontier = [], explored =
[S,A,B,C,E,F]
G (5.0)
(8.0)
Jadi urutan node yang dievaluasi : [S,A,B,C,E,F]
dengan jalur solusi : S-B-F-G.

05/01/2020 T0264 - Artificial Intelligence 50


S f = {S}; inisial
(3.0) f = {A, B, C}; dipilih A,B dan C sebagai suksesor S
(1.0)
(2.0) f = {B, C, D, E}; krn g ke A=1; B=2; C=3 dipilih A untuk
C diekspan, hasilnya D & E
A
f = {C, D, E, F}; krn g ke B=2; C=3; D=5+1; E=2+1
(5.0) (2.0) B dipilih B (plg kiri) untuk diekspan,
hasilnya F
(1.0)
D E f = {D, E, F, C}; krn g ke C=3; D=6; E=3; F=3 C tidak
bisa diekspan
F f = {D, F, C, G}; krn g ke D=6; E=2+1; F=2+1; C=3 dipilih
E untuk diekspan, hasilnya G
(5.0) f = {D, C, G}; krn g ke D=6; G lewat E=5+2+1;
(1.0) F=3 dipilih E untuk diekspan,
hasilnya G lewat F (goal)
Node expanded = 7,
Path = S-B-F-G.
G

05/01/2020 T0264 - Artificial Intelligence 51


Heuristik A* (f(n) = h(n) + g(n))

S frontier = [S], explored = []


Evaluasi S, frontier = [A(3), B(7), C(10)], explored =
[S]
(10.0) C Evaluasi A, frontier = [B(7),C(10),E(13),D(26)],
A (3.0) explored = [S,A]
Evaluasi B, frontier = [F(6),C(10),E(13),D(26)], explored
B (7.0)
= [S,A,B]
Evaluasi F, frontier = [G(4),C(10),E(13),D(26)], explored
D (26.0) E (13.0) = [S,A,B,F]
(6.0) F Evaluasi G = goal ,STOP, frontier = [], explored =
[S,A,B,F]
Jadi urutan node yang dievaluasi : [S,A,B,F]
dengan jalur solusi : S-B-F-G.

G (4.0)

05/01/2020 T0264 - Artificial Intelligence 52


S f = {S}; inisial
(3.0)
(1.0) f = {A, B, C}; dipilih A,B dan C sebagai
(2.0) suksesor S
C (7.0)
A (2.0) f = {B, C, D, E}; krn f dr A=2+1; B=5+2; C=7+3
(5.0) (2.0) B (5.0) dipilih A untuk diekspan,
hasilnya D & E
(1.0)
D (20.0) E (9.0) f = {C, D, E, F}; krn f dr B=5+2; C=7+3; D=20+5+1;
(3.0) F
E=9+2+1 dipilih B untuk
diekspan, hasilnya F
f = {C, D, E, G}; krn f dr C=7+3; D=20+5+1;
(1.0)
E=9+2+1; F=3+1+2 dipilih F
untuk diekspan, hasilnya G
(goal)
G (0.0)
Node expanded = 7,
Path = S-B-F-G.

05/01/2020 T0264 - Artificial Intelligence 53


References

» Stuart Russell, Peter Norvig,. 2010. Artificial intelligence : a


modern approach. PE. New Jersey. ISBN:9780132071482,
Chapter 4
» Elaine Rich, Kevin Knight, Shivashankar B. Nair. 2010. Artificial
Intelligence. MHE. New York. , Chapter 3
» Greedy Best-First Search Walkthrough:
http://www.cs.utah.edu/~hal/courses/2009S_AI/Walkthrough/
GreedyBFS/
» Introduction to A*:
http://theory.stanford.edu/~amitp/GameProgramming/AStarCo
mparison.html

T0264 - Artificial Intelligence 54


<< CLOSING >>

End of Session 03

Good Luck

T0264 - Artificial Intelligence 55

You might also like