2/4/2012
IF-UTAMA 1
Jurusan Teknik Informatika – Universitas Widyatama
Searching
Pertemuan : 2
Dosen Pembina :
Danang Junaedi
Susetyo Bagas Baskoro
Sriyani Violina
IF-UTAMA 2
• Deskripsi
• Search Problem & Answer
• Search Tree
• Kriteria Ukuran Performansi Teknik Search
• Blind Search atau Un-informed Search
• Heuristic Search atau Informed Search
Overview
IF-UTAMA 3
• Pertemuan ini mempelajari bagaimana
memecahkan suatu masalah dengan tekniksearching.
• Metode searching yang dibahas pada pertemuanini adalah blind search atau un-informed searchyang terdiri dari:– Breadth First Search (BFS)
– Depth First Search (DFS)
– Uniform Cost Search (UCS)
– Depth-Limited Search (DLS)
– Iterative-Deeping Search (IDS)
– Bi-directional search (BDS)
Deskripsi
Jurusan Teknik Informatika – Universitas Widyatama
Intro Searching
2/4/2012
IF-UTAMA 2
IF-UTAMA 5
Pendahuluan
• Para peneliti awal artificial intelligence menitik beratkan pada penyelesaian masalah yang tidak menggunakan metoda komputasi konvensional.
• Permasalahan pada sistem artificial intelligence tidak memiliki algoritma tertentu karena akan menjadi sangat kompleks.
• Karena itu haruslah ditemukan sebuah teknik baru yang mirip dengan cara yang digunakan oleh manusia untuk menyelesaikan masalah dan dapat diimplementasikan pada komputer.
• Salah satu metoda yang cukup terkenal adalah metoda searching.
• Searching dalam sebuah struktur data telah menjadi dasar bagi algoritma komputer, tetapi proses searching pada artificial intelligence memiliki perbedaan.
IF-UTAMA 6
Pendahuluan (contd.)
• Metoda searching pada artificial intelligence merupakan searching terhadap problem space bukan searching data (e.g., angka, karakter, string) tertentu.
• Proses searching ini berupa jalur yang menggambarkan keadaan awal sebuah masalah menuju kepada penyelesaian masalah yang diinginkan (i.e., the solved problem).
• Jalur-jalur ini mengambarkan langkah-langkah penyelesaian masalah.
• Melalui proses searching menuju sebuah penyelesaian akan terbentuk sebuah solution space.
IF-UTAMA 7
Contoh : penyelesaian masalah komputer
IF-UTAMA 8
Contoh (contd.)
• Langkah pertama untuk mengetahui apakah komputer dapat digunakan atau tidak adalah men-switch ON.
• Selanjutnya dengan melakukan inspeksi terhadap kondisi lampu indikator kita dapat menentukan langkah berikutnya.
• Misalnya kondisi lampu OFF.
• Dengan melakukan searching terhadap problem space kita akan tiba pada sebuah penyelesaian masalah agar komputer dapat diaktifkan kembali.
2/4/2012
IF-UTAMA 3
IF-UTAMA 9
Evaluasi Strategi Pencarian
1. Completeness : Apakah metode tersebutmenjamin penemuan solusi jika solusinya memang ada?
2. Time complexity : Berapa lama waktu yang diperlukan ?
3. Space complexity : berapa banyak memori yang diperlukan ?
4. Optimality : Apakah metode tersebut menjamin menemukan solusi yang terbaik jika terdapat beberapa solusi yang berbeda ?
IF-UTAMA 10
Search Problems & Answer
Let S be the set of states (strings)
Input:
• Initial state: s0
• Neighbor generator, N: S → 2S
• Goal function, G: S → {0,1}
Solution:
s1,…,sn such that:
• s1,…,sn ∈ S
• for all 1≤i≤n, si ∈ N(si-1)
• G(sn) = 1
IF-UTAMA 11
Metode Search
• Blind search � tidak ada informasi awal
yang digunakan dalam proses pencarian, simpul pencarian dibangkitkan berdasarkan
urutan tertentu
• Heuristic search � menggunakan suatu
fungsi untuk menghitung biaya perkiraan dari suatu simpul tertentu menuju simpul tujuan
IF-UTAMA 12
•Root node•Leaf node•Branching factor•Ancestor / descendant•Path•Level
•Deskripsi keadaan •Pointer ke parent•Kedalaman simpul•Operator yang membuka simpul ini•Biaya total dari simpul awal sampai simpul ini
Pohon Pencarian
2/4/2012
IF-UTAMA 4
IF-UTAMA 13
Tree search algorithms
Jurusan Teknik Informatika – Universitas Widyatama
Blind Search
IF-UTAMA 15
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go
at end
IF-UTAMA 16
Breadth First Search Algorithm
2/4/2012
IF-UTAMA 5
IF-UTAMA 17
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go
at end
–
IF-UTAMA 18
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go
at end
IF-UTAMA 19
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go
at end
IF-UTAMA 20
Ilustrasi BFS
2/4/2012
IF-UTAMA 6
IF-UTAMA 21
Ilustrasi BFS
IF-UTAMA 22
Ilustrasi BFS
IF-UTAMA 23
Ilustrasi BFS
IF-UTAMA 24
Ilustrasi BFS
2/4/2012
IF-UTAMA 7
IF-UTAMA 25
Ilustrasi BFS
IF-UTAMA 26
Ilustrasi BFS
IF-UTAMA 27
Properties of breadth-first search
• Complete? Yes (if b is finite)
• Time? 1+b+b2+b3+… +bd + b(bd-1) = O(bd+1)
• Space? O(bd+1) (keeps every node in memory)
• Optimal? Yes (if cost = 1 per step)
• Space is the bigger problem (more than time)
IF-UTAMA 28
• Keuntungan BFS: Menemukan jalur solusi dengan jalur tersingkat, karena selalu mengambil lebar dari pohon pencarian.
• Kerugian BFS: Memerlukan ruang dan waktu pencarian yang eksponensial pada kedalaman pencarian.
Keuntungan dan Kerugian BFS
2/4/2012
IF-UTAMA 8
IF-UTAMA 29
Depth First Search Algorithm
IF-UTAMA 30
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
IF-UTAMA 31
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
IF-UTAMA 32
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
2/4/2012
IF-UTAMA 9
IF-UTAMA 33
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
IF-UTAMA 34
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
IF-UTAMA 35
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
IF-UTAMA 36
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
2/4/2012
IF-UTAMA 10
IF-UTAMA 37
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
IF-UTAMA 38
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
IF-UTAMA 39
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
IF-UTAMA 40
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
2/4/2012
IF-UTAMA 11
IF-UTAMA 41
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
IF-UTAMA 42
Ilustrasi DFS
IF-UTAMA 43
Ilustrasi DFS
IF-UTAMA 44
Ilustrasi DFS
2/4/2012
IF-UTAMA 12
IF-UTAMA 45
Ilustrasi DFS
IF-UTAMA 46
Ilustrasi DFS
IF-UTAMA 47
Properties of depth-first search
• Complete? No: fails in infinite-depth spaces, spaces
with loops
– Modify to avoid repeated states along path
� complete in finite spaces
• Time? O(bm): terrible if m is much larger than d
– but if solutions are dense, may be much faster than
breadth-first
• Space? O(bm), i.e., linear space!
• Optimal? No
IF-UTAMA 48
Breadth First vs. Depth First SearchBreadth First vs. Depth First Search
Which type of search would return the result Which type of search would return the result
the fastest for:the fastest for:
M?M?
K?K?
D?D?
G?G?
2/4/2012
IF-UTAMA 13
IF-UTAMA 49
Uniform Cost Search (UCS)Uniform Cost Search (UCS)
• Konsepnya hampir sama dengan BFS, bedanya adalah bahwa BFS menggunakan urutan level yang paling rendah sampai yang paling tinggi, sedangkan UCS menggunakan urutan biaya dari yang paling kecil sampai yang terbesar.
• UCS berusaha menemukan solusi dengan total biaya terendah yang dihitung berdasarkan biaya dari simpul asal menuju ke simpul tujuan.
IF-UTAMA 50
• Modifikasi BFS untuk mendapatkan biaya terendah sepanjang jalur pencarian, bukan hanya dilihat dari solusi yang didapat saja. (lowest cost vs. lowest depth)
• Urutan biaya selalu menaik– g(SUCCESSOR(n)) > g(n)– g(n) = biaya jalur pencarian dari titik awal sampai node n.
• Properti dari algoritma pencarian ini adalah: komplit, optimal / admissible, dan exponensial dalam kompleksiatas waktu dan ruang, O(bd).
Uniform Cost Search
IF-UTAMA 51
Pada graf di atas, proses pencarian berlangsung sebagai berikut:1. OPEN S (start)
2. OPEN A, B, C (cost = 1, 5, 15)3. OPEN B, G, C (cost = 5, 11, 15)4. OPEN G, G, C (cost = 10, 11, 15)5. SOLUTION G (path S-B-G)
Uniform Cost Search
IF-UTAMA 52
Uniform-cost search
• Expand least-cost unexpanded node
• Implementation:– fringe = queue ordered by path cost
• Equivalent to breadth-first if step costs all equal
• Complete? Yes, if step cost ≥ ε
• Time? # of nodes with g ≤ cost of optimal solution, O(bceiling(C*/ ε)) where C* is the cost of the optimal solution
• Space? # of nodes with g ≤ cost of optimal solution, O(bceiling(C*/ ε))
• Optimal? Yes – nodes expanded in increasing order of g(n)
2/4/2012
IF-UTAMA 14
IF-UTAMA 53
Depth-limited search
= depth-first search with depth limit l,
i.e., nodes at depth l have no successors
• Recursive implementation:
IF-UTAMA 54
Iterative deepening search
• IDS merupakan metode yang menggabungkan
kelebihan BFS (Complete dan Optimal) dengan kelebihan DFS (space complexity rendah atau
membutuhkan sedikit memori)
• Tetapi konsekuensinya adalah time complexity-nya
menjadi tinggi.
IF-UTAMA 55
Iterative deepening search l =0
IF-UTAMA 56
Iterative deepening search l =1
2/4/2012
IF-UTAMA 15
IF-UTAMA 57
Iterative deepening search l =2
IF-UTAMA 58
Iterative deepening search l =3
IF-UTAMA 59
Iterative deepening search
• Number of nodes generated in a depth-limited search to depth d with branching factor b:
NDLS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd
• Number of nodes generated in an iterative deepening search to depth d with branching factor b:
NIDS = (d+1)b0 + d b^1 + (d-1)b^2 + … + 3bd-2 +2bd-1 + 1bd
• For b = 10, d = 5,– NDLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111– NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,456
• Overhead = (123,456 - 111,111)/111,111 = 11%
IF-UTAMA 60
Properties of iterative deepening search
• Complete? Yes
• Time? (d+1)b0 + d b1 + (d-1)b2 + … + bd = O(bd)
• Space? O(bd)
• Optimal? Yes, if step cost = 1
2/4/2012
IF-UTAMA 16
IF-UTAMA 61
Bi-Directional Search (BDS)
• Pencarian dilakukan dari dua arah : pencarian maju (dari start ke goal) dan pencarian mundur (dari goal ke start). Ketika dua arah pencarian telah membangkitkan simpul yang sama, maka solusi telah ditemukan, yaitu dengan cara menggabungkan kedua jalur yang bertemu.
IF-UTAMA 62
Summary of algorithms
IF-UTAMA 63
Repeated states
• Failure to detect repeated states can turn a
linear problem into an exponential one!
IF-UTAMA 64
Latihan Praktikum II (1)
• Water Jug Problem
2/4/2012
IF-UTAMA 17
IF-UTAMA 65
Latihan Praktikum II (2)
• Aturan Produksi Water Jug ProblemNo Aturan Produksi State Keterangan
1. (x,y)If x < 4
� (4,y) Isi penuh gelas 4 galon
2. (x,y)If y < 3
�(x,3) Isi penuh gelas 3 galon
3. (x,y)If x > 0
� (x-d,y) Buang sebagian air dari gelas 4 galon
4. (x,y)If y > 0
� (x,y-d) Buang sebagian air dari galon ukuran 3 galon
5. (x,y)If x > 0
� (0,y) Kosongkan gelas 4 galon
6. (x,y)If y > 0
� (x,0) Kosongkan gelas 3 galon
7. (x,y)If x+y ≥4 and y > 0
� (4,y-(4-x))
Tuangkan air dari gelas 3 galon ke gelas 4 galon sampai gelas 4 galon penuh
8. (x,y)If x+y ≥ 3 and x > 0
� (x-(3-y),3)
Tuangkan air dari gelas 4 galon ke gelas 3 galon sampai gelas 3 galon penuh
9. (x,y)If x+y ≤4 and y > 0
� (x+y,0) Tuangkan seluruh air dari gelas 3 galon ke gelas 4 galon
10. (x,y)If x+y ≤3 and x > 0
� (0,x+y) Tuangkan seluruh air dari gelas 4 galon ke gelas 3 galon
11. (0,2) � (2,0) Tuangkan 2 galon air dari gelas 3 galon ke gelas 4 galon12. (2,y) �(0,y) Buang 2 galon dalam gelas 4 galon sampai habis.
IF-UTAMA 66
Latihan Praktikum II (3)
• Contoh solusi untuk Water Jug Problem
Jumlah galon dalam
gelas 4 galon
Jumlah galon dalam
gelas 3 galon
Aturan yang
dilakukan
0 0 -0 3 23 0 9
3 3 24 2 70 2 5 atau 12
2 0 9 atau 11
IF-UTAMA 67
Latihan Praktikum II (4)
1. Berdasarkan aturan produksi pada tabel 2.1 di
halaman II-4 atau berdasarkan kasus yang andaperoleh dari dosen pembina, gambarkan ilustrasi
pencarian solusi dengan menggunakan metodeBlind Search yang telah dibahas di kelas, jelaskansecara singkat!
2. Analisis ilustrasi tersebut, mana yang memberikan
solusi terbaik? Jelaskan alasan anda!
IF-UTAMA 68
Tugas Rumah II
1. Berdasarkan Latihan Praktikum II, cari atau buat
implementasi kasus tersebut (minimum duametode yaitu Breadth First Search dan Depth First
Search)!
2. Analisis programnya, kemudian buat penjelasan
perbaris program dan penjelasan program secara keseluruhan serta hasil running-nya! Kirim
dokumen hasil analisis program via e-mail!
Deadline: 8 Februari 2012 jam 24:00
2/4/2012
IF-UTAMA 18
IF-UTAMA 69
Referensi
1. Suyanto.2007.”Artificial Intelligence” .Informatika. Bandung2. Michael L. Littman.2001. “Introduction to Artificial Intelligence-
Search [online]”.url:http://www.cs.princeton.edu/courses/archive/fall01/cs302/notes/9-19/Search.ppt,Tanggal Akses : 9 Februari 2011
3. Irfan Subakti.2006.“Artificial Intelligence [online]”,url:http://is.its-sby.edu/subjects/ai2006-1/Irfan%20-%20Artificial%20Intelligence%20-%203.ppt, Tanggal Akses : 9 Februari 2011
4. Yeni Kustiyaningsih.2010. “Kecerdasan Buatan-pertemuan 3 MASALAH, RUANG KEADAAN DAN PENCARIAN [online]”.url: http://yenikustiyahningsih.files.wordpress.com/2010/10/pertemuan-3.ppt.Tanggal Akses: 9 Februari 2011
5. -.2008.”Artificial Intelligence [online]”.url: http://sitoba.itmaranatha.org/PIB%200809/Presentasi%20PPT/PIB0809-04.ppt. Tanggal Akses: 9 Februari 2011
6. Dan sumber-sumber lain yang terkait