Mata Kuliah: Kecerdasan Artifisial (AI401) | 3 SKS
Setelah pertemuan ini, mahasiswa mampu:
Pada Pertemuan 1, kita belajar tentang agen cerdas
Pertanyaan: Bagaimana agen menemukan urutan aksi untuk mencapai tujuan?
Proses sistematis menemukan urutan aksi dari kondisi awal ke kondisi tujuan
| Kategori | Karakteristik | Contoh |
|---|---|---|
| Uninformed Search (Blind Search) |
Tidak ada info tambahan tentang jarak ke goal | BFS, DFS, UCS |
| Informed Search (Heuristic Search) |
Menggunakan heuristik untuk estimasi | Greedy, A* (Pertemuan 3) |
š· Lihat: images/p02-01-komponen-problem-pencarian.png
Tujuan: Mencari rute dari Arad ke Bucharest
| State Space | Semua kota di Romania |
| Initial State | Arad |
| Actions | Pergi ke kota tetangga |
| Goal Test | State = Bucharest? |
| Path Cost | Jarak total (km) |
š· Lihat: images/p02-02-peta-romania.png
| 7 | 2 | 4 |
| 5 | ⬠| 6 |
| 8 | 3 | 1 |
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | ⬠|
Actions: Geser kotak kosong (ā ā ā ā)
š· Lihat: images/p02-03-8-puzzle.png
Search Tree adalah representasi pohon dari proses pencarian
š· Lihat: images/p02-04-search-tree.png
| Expand | Menghasilkan semua child node dari suatu node |
| Frontier | Node yang sudah di-generate tapi belum di-expand (Open List) |
| Explored Set | State yang sudah di-expand (Closed List) |
| Parameter | Simbol | Deskripsi |
|---|---|---|
| Branching Factor | b | Jumlah maksimal anak per node |
| Depth of Goal | d | Kedalaman goal terdekat |
| Maximum Depth | m | Kedalaman maksimal pohon |
š· Lihat: images/p02-05-parameter-kompleksitas.png
Eksplorasi semua node pada kedalaman d
sebelum ke kedalaman d+1
[1] ā Level 0: Ekspansi pertama
/ \
[2] [3] ā Level 1: Ekspansi kedua & ketiga
/ \ / \
[4][5][6][7] ā Level 2: Ekspansi 4, 5, 6, 7
Queue: [1] ā [2,3] ā [3,4,5] ā [4,5,6,7] ā ...
FIFO: Masuk Pertama, Keluar Pertama
š· Lihat: images/p02-06-bfs-expansion.png
def bfs(problem):
node = Node(problem.initial_state)
if problem.goal_test(node.state):
return node.path()
frontier = Queue() # FIFO
frontier.enqueue(node)
explored = set()
while not frontier.is_empty():
node = frontier.dequeue()
explored.add(node.state)
for action in problem.actions(node.state):
child = node.child(problem, action)
if child.state not in explored:
if problem.goal_test(child.state):
return child.path()
frontier.enqueue(child)
return None
| Complete? | ā Ya (jika b terbatas) |
| Optimal? | ā Ya (jika step cost = 1) |
| Time | O(bd) |
| Space | O(bd) š° |
ā ļø Memori bisa sangat besar!
Selalu eksplorasi node terdalam di frontier terlebih dahulu
[1] ā Mulai dari root
/ \
[2] [7] ā Kiri dulu, kanan nanti
/ \
[3] [6] ā Terus ke bawah
/
[4] ā Sampai buntu
\
[5] ā backtrack ā Lalu backtrack
Stack: [1] ā [2,7] ā [3,6,7] ā [4,6,7] ā ...
LIFO: Masuk Terakhir, Keluar Pertama
š· Lihat: images/p02-07-dfs-expansion.png
| Complete? | ā Tidak (bisa infinite loop) |
| Optimal? | ā Tidak (bisa temukan solusi lebih dalam) |
| Time | O(bm) š° (bisa sangat buruk) |
| Space | O(bm) š (linear!) |
ā Keunggulan utama: Space complexity!
Jika b = 10 dan d = 10:
| Algoritma | Space | Estimasi |
|---|---|---|
| BFS | O(bd) | 1010 = 10 miliar node! |
| DFS | O(bm) | 10 Ć 10 = 100 node |
100 juta kali lebih hemat!
DFS dengan batas kedalaman maksimal L
def depth_limited_search(problem, limit):
return recursive_dls(Node(problem.initial), problem, limit)
Jalankan DLS berulang dengan limit meningkat:
L=0, L=1, L=2, ...
def iterative_deepening_search(problem):
depth = 0
while True:
result = depth_limited_search(problem, depth)
if result != 'cutoff':
return result
depth += 1
š· Lihat: images/p02-08-iterative-deepening.png
| Complete? | ā Ya (seperti BFS) |
| Optimal? | ā Ya (untuk uniform cost) |
| Time | O(bd) (seperti BFS) |
| Space | O(bd) š (seperti DFS!) |
IDS = Keunggulan BFS + Keunggulan DFS!
Bukankah IDS mengulang eksplorasi?
Contoh: b=3, d=3
| Algoritma | Node Generated |
|---|---|
| BFS | 1+3+9+27 = 40 |
| IDS | 1+4+13+40 = 58 |
Overhead: 58/40 = 1.45Ć saja!
Sebagian besar node ada di level terdalam
Eksplorasi node dengan path cost terendah terlebih dahulu
Start -----(cost 10)----ā A -----(cost 1)----ā Goal
| ā
+-------(cost 5)------ā B ------(cost 5)------+
BFS path: Start ā A ā Goal (cost = 11)
Optimal path: Start ā B ā Goal (cost = 10)
BFS memilih berdasarkan kedalaman, bukan biaya!
š· Lihat: images/p02-09-ucs-expansion.png
def uniform_cost_search(problem):
node = Node(problem.initial_state, path_cost=0)
frontier = PriorityQueue() # priority = g(n)
frontier.push(node, priority=node.path_cost)
explored = set()
while not frontier.is_empty():
node = frontier.pop() # cost terendah
if problem.goal_test(node.state): # test saat expand!
return node.path()
explored.add(node.state)
for action in problem.actions(node.state):
child = node.child(problem, action)
# ... update frontier jika cost lebih rendah
return None
Bukan saat node di-generate!
Alasan: Node dengan cost lebih rendah bisa muncul kemudian
| Complete? | ā Ya (jika step cost ℠ε > 0) |
| Optimal? | ā Ya! š |
| Time | O(b1+āC*/εā) |
| Space | O(b1+āC*/εā) |
C* = biaya solusi optimal, ε = step cost minimum
| Kriteria | BFS | DFS | IDS | UCS |
|---|---|---|---|---|
| Complete | ā | ā | ā | ā |
| Optimal | ā * | ā | ā * | ā |
| Time | O(bd) | O(bm) | O(bd) | O(bC*/ε) |
| Space | O(bd) | O(bm) | O(bd) | O(bC*/ε) |
| Struktur | Queue | Stack | Stack | PQueue |
* jika step cost uniform
| Situasi | Pilih | Alasan |
|---|---|---|
| Step cost bervariasi | UCS | Menjamin optimal |
| Memori terbatas | IDS | Space O(bd), complete |
| Perlu solusi tercepat | BFS/IDS | Solusi terdangkal |
| State space besar/infinite | IDS | Complete, hemat memori |
š· Lihat: images/p02-10-flowchart-pemilihan.png
ā Gunakan UCS untuk misi dengan risiko minimum!
Algoritma mana yang menggunakan Queue (FIFO)?
Jawaban: B. BFS
Jika step cost bervariasi, algoritma mana yang menjamin solusi optimal?
Jawaban: D. UCS
Algoritma mana yang memiliki space complexity paling efisien?
Jawaban: C. IDS - O(bd)
IDS memiliki keunggulan DFS (space) + keunggulan BFS (complete, optimal)
latihan.mdDeadline: Sebelum Pertemuan 03
Pertemuan 02: Pemecahan Masalah dengan Pencarian - Uninformed Search
Ada pertanyaan?