64
1 HO-3 KTL401 Kecerdasan Buatan Menyelesaikan Masalah dengan Pencarian Opim S Sitompul

HO-04 Kecerdasan Buatan

Embed Size (px)

Citation preview

Page 1: HO-04 Kecerdasan Buatan

1

HO-3 KTL401 Kecerdasan Buatan

Menyelesaikan Masalah

dengan Pencarian

Opim S Sitompul

Page 2: HO-04 Kecerdasan Buatan

2

Outline

Agen-agen Penyelesaian-masalah

Jenis-jenis masalah

Formulasi masalah

Contoh-contoh masalah

Algoritma pencarian dasar

Page 3: HO-04 Kecerdasan Buatan

3

Agen-agen Penyelesaian-masalah

Page 4: HO-04 Kecerdasan Buatan

4

Contoh: Romania

Liburan di Romania; saat ini berada di Arad.

Pesawat berangkat besok dari Bucharest

Formulasi goal:

sampai di Bucharest

Formulasi masalah: states: berbagai kota

actions: mengemudi antar kota

Cari penyelesaian: Deretan kota, mis., Arad, Sibiu, Fagaras, Bucharest

Page 5: HO-04 Kecerdasan Buatan

5

Contoh: Romania

Page 6: HO-04 Kecerdasan Buatan

6

Contoh: Romania

Search:

Sebuah agen dengan beberapa pilihan segera dengan nilai yang tidak diketahui dapat memutuskan apa yang dilakukan dengan pertama-tama memeriksa deretan aksi berbeda yang mungkin yang membawa ke state dengan nilai yang diketahui, dan kemudian memilih deretan terbaik.

Algoritma search menerima input sebuah masalah dan mengembalikan sebuah penyelesaian dalam bentuk sederetan aksi.

Page 7: HO-04 Kecerdasan Buatan

7

Contoh: Romania

Page 8: HO-04 Kecerdasan Buatan

8

Problem types

Deterministic, fully observable single-state problem

Agent knows exactly which state it will be in; solution is a sequence

Non-observable sensorless problem (conformant problem)

Agent may have no idea where it is; solution is a sequence

Nondeterministic and/or partially observable contingency problem

percepts provide new information about current state

often interleave} search, execution

Unknown state space exploration problem

Page 9: HO-04 Kecerdasan Buatan

9

Masalah yang terdefinisi baik

dan penyelesaian

Sebuah masalah dapat didefinisikan secara formal oleh empat komponen: State awal, dimana agen itu berada.

Cth.: In(Arad)

Deskripsi tentang kemungkinan aksi yang tersedia bagi si agen. Formulasi yang paling umum menggunakan successor function.

In(Arad) -> initial state

{<Go(Sibiu), In(Sibiu)>, <Go(Timisoara), In(Timisoara)>, <Go(Zerind), In(Zerind)>}

Initial state + successor function -> state space, himpunan semua state yang dapat dicapai dari initial state.

Page 10: HO-04 Kecerdasan Buatan

10

Masalah yang terdefinisi baik

dan penyelesaian

Goal test, menentukan apakah satu state adalah

goal state.

Path cost, fungsi yang memberikan harga

numerik ke masing-masing path.

Memformulasikan masalah

Abstraksi: proses melenyapkan rincian dari

sebuah representasi.

Page 11: HO-04 Kecerdasan Buatan

11

Contoh: vacuum world

States: agen ada di salah satu dari dua lokasi,

masing-masing berdebu atau tidak berdebu. Ada 2 x

22 = 8 state

Initial state: sembarang state

Successor function: menghasilkan langkah sah

yang dihasilkan dari mencoba tiga tindakan (Left,

Right, dan Suck)

Goal test: memeriksa apakah semua ruang bersih

Path cost: setiap langkah berharga 1, sehingga path

cost adalah jumlah langkah dalam path.

Page 12: HO-04 Kecerdasan Buatan

12

Contoh: vacuum world

Single-state, start in #5.

Solution?

Page 13: HO-04 Kecerdasan Buatan

13

Contoh: vacuum world

Single-state, start in #5.

Solution? [Right, Suck]

Sensorless, start in

{1,2,3,4,5,6,7,8} e.g.,

Right goes to {2,4,6,8}

Solution?

Page 14: HO-04 Kecerdasan Buatan

14

Contoh: vacuum world

Sensorless, start in

{1,2,3,4,5,6,7,8} e.g.,

Right goes to {2,4,6,8}

Solution?

[Right,Suck,Left,Suck]

Contingency

Nondeterministic: Suck may

dirty a clean carpet

Partially observable: location, dirt at current location.

Percept: [L, Clean], i.e., start in #5 or #7

Solution?

Page 15: HO-04 Kecerdasan Buatan

15

Contoh: vacuum world

Sensorless, start in

{1,2,3,4,5,6,7,8} e.g.,

Right goes to {2,4,6,8}

Solution?

[Right,Suck,Left,Suck]

Contingency

Nondeterministic: Suck may

dirty a clean carpet

Partially observable: location, dirt at current location.

Percept: [L, Clean], i.e., start in #5 or #7

Solution? [Right, if dirt then Suck]

Page 16: HO-04 Kecerdasan Buatan

16

Single-state problem formulation

A problem is defined by four items:

1. initial state e.g., "at Arad“

2. actions or successor function S(x) = set of action–state pairs e.g., S(Arad) = {<Arad Zerind, Zerind>, … }

3. goal test, can be explicit, e.g., x = "at Bucharest"

implicit, e.g., Checkmate(x)

4. path cost (additive) e.g., sum of distances, number of actions executed, etc.

c(x,a,y) is the step cost, assumed to be ≥ 0

A solution is a sequence of actions leading from the initial state to a goal state

Page 17: HO-04 Kecerdasan Buatan

17

Selecting a state space

Real world is absurdly complex

state space must be abstracted for problem solving

(Abstract) state = set of real states

(Abstract) action = complex combination of real actions

e.g., "Arad Zerind" represents a complex set of possible routes, detours, rest stops, etc.

For guaranteed realizability, any real state "in Arad“ must get to some real state "in Zerind"

(Abstract) solution =

set of real paths that are solutions in the real world

Each abstract action should be "easier" than the original problem

Page 18: HO-04 Kecerdasan Buatan

18

Vacuum world state space graph

states?

actions?

goal test?

path cost?

Page 19: HO-04 Kecerdasan Buatan

19

Vacuum world state space graph

states? integer dirt and robot location actions? Left, Right, Suck

goal test? no dirt at all locations

path cost? 1 per action

Page 20: HO-04 Kecerdasan Buatan

20

Contoh: The 8-puzzle

states?

actions?

goal test?

path cost?

Page 21: HO-04 Kecerdasan Buatan

21

Contoh: The 8-puzzle

states? locations of tiles

actions? move blank left, right, up, down

goal test? = goal state (given)

path cost? 1 per move

[Note: optimal solution of n-Puzzle family is NP-hard]

Page 22: HO-04 Kecerdasan Buatan

22

Contoh: robotic assembly

states?: real-valued coordinates of robot joint angles parts of the object to be assembled

actions?: continuous motions of robot joints

goal test?: complete assembly

path cost?: time to execute

Page 23: HO-04 Kecerdasan Buatan

23

Tree search algorithms

Basic idea: offline, simulated exploration of state space by generating

successors of already-explored states (a.k.a.~expanding

states)

Page 24: HO-04 Kecerdasan Buatan

24

Tree search example

Page 25: HO-04 Kecerdasan Buatan

25

Tree search example

Page 26: HO-04 Kecerdasan Buatan

26

Tree search example

Fringe: kumpulan node yang telah

dibuat tetapi belum di-expand. Masing-

masing elemen fringe adalah leaf

node.

Page 27: HO-04 Kecerdasan Buatan

27

Implementation: general tree search

Page 28: HO-04 Kecerdasan Buatan

28

Implementation: states vs. nodes

A state is a (representation of) a physical configuration

A node is a data structure constituting part of a search tree includes state, parent node, action, path cost g(x), depth

The Expand function creates new nodes, filling in the various fields and using the SuccessorFn of the problem to create the corresponding states.

Page 29: HO-04 Kecerdasan Buatan

29

Search strategies

A search strategy is defined by picking the order of node expansion

Strategies are evaluated along the following dimensions:

completeness: does it always find a solution if one exists?

time complexity: number of nodes generated

space complexity: maximum number of nodes in memory

optimality: does it always find a least-cost solution?

Time and space complexity are measured in terms of

b: maximum branching factor of the search tree

d: depth of the least-cost solution

m: maximum depth of the state space (may be ∞)

Page 30: HO-04 Kecerdasan Buatan

30

Uninformed search strategies

Uninformed search strategies use only the

information available in the problem definition

Breadth-first search

Uniform-cost search

Depth-first search

Depth-limited search

Iterative deepening search

Page 31: HO-04 Kecerdasan Buatan

31

Breadth-first search

Expand shallowest unexpanded node

Implementation:

fringe is a FIFO queue, i.e., new successors go at

end

Page 32: HO-04 Kecerdasan Buatan

32

Breadth-first search

Expand shallowest unexpanded node

Implementation:

fringe is a FIFO queue, i.e., new successors go

at end

Page 33: HO-04 Kecerdasan Buatan

33

Breadth-first search

Expand shallowest unexpanded node

Implementation:

fringe is a FIFO queue, i.e., new successors go at

end

Page 34: HO-04 Kecerdasan Buatan

34

Breadth-first search

Expand shallowest unexpanded node

Implementation:

fringe is a FIFO queue, i.e., new successors go at

end

Page 35: HO-04 Kecerdasan Buatan

35

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)

Page 36: HO-04 Kecerdasan Buatan

36

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)

Page 37: HO-04 Kecerdasan Buatan

37

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 38: HO-04 Kecerdasan Buatan

38

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 39: HO-04 Kecerdasan Buatan

39

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 40: HO-04 Kecerdasan Buatan

40

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 41: HO-04 Kecerdasan Buatan

41

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 42: HO-04 Kecerdasan Buatan

42

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 43: HO-04 Kecerdasan Buatan

43

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 44: HO-04 Kecerdasan Buatan

44

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 45: HO-04 Kecerdasan Buatan

45

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 46: HO-04 Kecerdasan Buatan

46

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 47: HO-04 Kecerdasan Buatan

47

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 48: HO-04 Kecerdasan Buatan

48

Depth-first search

Expand deepest unexpanded node

Implementation:

fringe = LIFO queue, i.e., put successors at front

Page 49: HO-04 Kecerdasan Buatan

49

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

Page 50: HO-04 Kecerdasan Buatan

50

Depth-limited search

= depth-first search with depth limit l,

i.e., nodes at depth l have no successors

Recursive implementation:

Page 51: HO-04 Kecerdasan Buatan

51

Iterative deepening search

Page 52: HO-04 Kecerdasan Buatan

52

Iterative deepening search l =0

Page 53: HO-04 Kecerdasan Buatan

53

Iterative deepening search l =1

Page 54: HO-04 Kecerdasan Buatan

54

Iterative deepening search l =2

Page 55: HO-04 Kecerdasan Buatan

55

Iterative deepening search l =3

Page 56: HO-04 Kecerdasan Buatan

56

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%

Page 57: HO-04 Kecerdasan Buatan

57

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

Page 58: HO-04 Kecerdasan Buatan

Breadth-first search Procedure breadth-first-serach;

Begin

open = [start];

closed = [];

while open ≠ []

begin

remove leftmost state from open, call it X;

if X is a goal then return(success)

else begin

generate children of X;

put X on closed;

eliminate children of X on open or closed;

put remaining children on right-end of open;

end;

return(failure)

End. 58

Page 59: HO-04 Kecerdasan Buatan

Depth-first search Procedure breadth-first-serach;

Begin

open = [start];

closed = [];

while open ≠ []

begin

remove leftmost state from open, call it X;

if X is a goal then return(success)

else begin

generate children of X;

put X on closed;

eliminate children of X on open or closed;

put remaining children on left-end of open;

end;

return(failure)

End. 59

Page 60: HO-04 Kecerdasan Buatan

Adjacency List

Arad Zerind(75) Sibiu(140) Timisoara(118)

Zerind Oradea(71)

Sibiu Fagaras(99) RimnicuVilcea(80)

Timisoara Lugoj(111)

Oradea Sibiu(151)

Lugoj Mehadia(70)

Fagaras Bucharest(211)

RimnicuVilcea Pitesti(97) Craiova(146)

Pitesti Bucharest(101)

Craiova Pitesti(138)

Mehadia Drobeta(75)

Drobeta Craiova(120)

Bucharest Giurgiu(90) Urziceni(85)

Urziceni Hirsova(98) Vaslui(142)

Hirsova Eforie(86)

Vaslui Lasi(92)

Lasi Neamt(87)

60

Page 61: HO-04 Kecerdasan Buatan

61

Summary of algorithms

Page 62: HO-04 Kecerdasan Buatan

62

Repeated states

Failure to detect repeated states can turn a

linear problem into an exponential one!

Page 63: HO-04 Kecerdasan Buatan

63

Graph search

Page 64: HO-04 Kecerdasan Buatan

64

Summary

Problem formulation usually requires abstracting away real-world

details to define a state space that can feasibly be explored

Variety of uninformed search strategies

Iterative deepening search uses only linear space and not much

more time than other uninformed algorithms