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
• Pertemuan ini mempelajari bagaimana memecahkan suatu masalah dengan teknik searching.
• Metode searching yang dibahas pada pertemuan ini adalah blind search atau un-informed search yang terdiri dari:
– Breadth First Search (BFS) – Depth First Search (DFS)
Deskripsi
Intro Searching
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.
IF-UTAMA 9
Evaluasi Strategi Pencarian
1. Completeness : Apakah metode tersebut
menjamin penemuan solusijika solusinya memang ada?
2. Time complexity : Berapa lamawaktuyang diperlukan ?
3. Space complexity: berapa banyak memoriyang diperlukan ?
4. Optimality: Apakah metode tersebut menjamin menemukan solusi yangterbaik 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,…,snsuch that:
• s1,…,sn ∈S
• for all 1≤i≤n, si∈N(si-1)
• G(sn) = 1
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
•Root node•Leaf node
•Deskripsi keadaan
•Pointer ke parent
•Kedalaman simpul
•Operator yang membuka simpul ini
•Biaya total dari simpul awal sampai simpul ini
Pohon Pencarian
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
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
Breadth-first search
• Expand shallowest unexpanded node
• Implementation:
– fringe is a FIFO queue, i.e., new successors go at end
Ilustrasi BFS
IF-UTAMA 6
IF-UTAMA 21
Ilustrasi BFS
IF-UTAMA 22
Ilustrasi BFS
IF-UTAMA 23
Ilustrasi BFS
IF-UTAMA 24
Ilustrasi BFS
IF-UTAMA 25
Ilustrasi BFS
IF-UTAMA 26
Ilustrasi BFS
Properties of breadth-first search
• Complete? Yes (if b is finite)
• Time? 1+b+b
2+b
3+… +b
d+ b(b
d-1) = O(b
d+1)
• Space? O(b
d+1) (keeps every node in memory)
• Optimal? Yes (if cost = 1 per step)
• Space is the bigger problem (more than time)
• 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
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
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
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
Depth-first search
• Expand deepest unexpanded node
• Implementation:
– fringe = LIFO queue, i.e., put successors at front
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
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
Ilustrasi DFS Ilustrasi DFS
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 Search Breadth 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?
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
Uniform Cost Search 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,
ceiling(C*/ ε)
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
IF-UTAMA 57
Iterative deepening search l =2
IF-UTAMA 58
Iterative deepening search l =3
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%
Properties of iterative deepening search
• Complete? Yes
• Time? (d+1)b
0+ d b
1+ (d-1)b
2+ … + b
d= O(b
d)
• Space? O(bd)
• Optimal? Yes, if step cost = 1
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
IF-UTAMA 65
Latihan Praktikum II (2)
• Aturan Produksi Water Jug Problem
No 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 galon 12. (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 2
3 0 9
3 3 2
4 2 7
0 2 5 atau 12
2 0 9 atau 11
Latihan Praktikum II (4)
1. Berdasarkan aturan produksi pada tabel 2.1 di halaman II-4 atau berdasarkan kasus yang anda peroleh dari dosen pembina, gambarkan ilustrasi pencarian solusi dengan menggunakan metode Blind Search yang telah dibahas di kelas, jelaskan secara singkat!
2. Analisis ilustrasi tersebut, mana yang memberikan solusi terbaik? Jelaskan alasan anda!
Tugas Rumah II
1. Berdasarkan Latihan Praktikum II, cari atau buat implementasi kasus tersebut (minimum dua
metode 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!
IF-UTAMA 18
IF-UTAMA 69
Referensi
1. Suyanto.2007.”Artificial Intelligence” .Informatika. Bandung 2. Michael L. Littman.2001. “Introduction to Artificial Intelligence-
Search
[online]”.url:http://www.cs.princeton.edu/courses/archive/fall01/cs 302/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/pertemua n-3.ppt.Tanggal Akses: 9 Februari 2011
5. -.2008.”Artificial Intelligence [online]”.url:
http://sitoba.itmaranatha.org/PIB%200809/Presentasi%20PPT/PI B0809-04.ppt. Tanggal Akses: 9 Februari 2011
6. Dan sumber-sumber lain yang terkait