IMPLEMENTASI DFS

  • Published on
    11-Sep-2015

  • View
    11

  • Download
    4

Embed Size (px)

DESCRIPTION

algoritma, pencarian, sistem pakar, sistem cerdas, dfs, analisa, implementasi, matlab, kesimpulan

Transcript

IMPLEMENTASI ALGORITMA DEPTH FIRST SEARCH (DFS)

Oleh:Abdurrahman

2015BAB IPENDAHULUAN

DEPTH FIRST SEARCH

Pencarian dengan metode ini dilakukan dari node awal secara mendalam hingga yangpaling akhir n (dead end) atau sampai ditemukan. Dengan kata lain, simpul cabangatau anak yang terlebih dahulu dikunjungi. Sebagai ilustrasinya dapat dilihat padagambar berikut ini:

Prosedur Depth First Search dapat diimplementasikan dengan melakukan modifikasiproses Breadth First Search menjadi (Luger : 2002) :

Prosedure depth first search

BeginOpen := [Start];Closed := [];While Open [] do 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; Discard children of x is already open or closed; Put remaining children on left end of open; End; End; Return FAIL

End.

Untuk memeriksa algoritma di atas, dapat dilihat bahwa keadaan keadaan turunan(descendant) ditambahkan atau dihapuskan dari ujung kiri open. Untuk lebih jelasnya,dapat dilihat aplikasi algoritma tersebut untuk contoh sebelumnya seperti padaBreadth First Search. Langkah penelusuran adalah sebagai berikut:

1. Open = [A]; Closed = []2. Open = [B, C, D]; Closed = [A]3. Open = [E, F, C, D]; Closed = [B, A]4. Open = [K, L, F, C, D]; Closed = [E, B, A]5. Open = [S, L, F, C, D]; Closed = [K, E, B, A]6. Open = [L, F, C, D]; Closed = [S, K, E, B, A]7. Open = [T, F, C, D]; Closed = [L, S, K, E, B, A]8. Open = [F, C, D]; Closed = [T, L, S, K, E, B, A]9. Open = [M, C, D]; Closed = [F, T, L, S, K, E, B, A]10. Open = [C, D]; Closed = [M, F, T, L, S, K, E, B, A]11. Open = [G, H, D]; Closed = [C, M, F, T, L, S, K, E, B, A]12. dan seterusnya sampai U diperoleh atau open =[]

BAB IIPEMBAHASAN

IMPLEMENTASI PADA MATLAB

LISTING CODE:

clear allclose allclc

% default obstacleobstacles(1,:)=[4,5];obstacles(2,:)=[4,1];obstacles(3,:)=[4,2];obstacles(4,:)=[4,3];obstacles(5,:)=[4,4];

startingPosition=[0,5];goal=[5,5]; obstacleColor=[1,0,0]; %merahnodeColor=[0,1,0]; %hijauexpandColor=[0,0,0]; %hitamgoalColor=[0,0,1]; %birupathColor=[0,1,1]; %biru muda

scatter(obstacles(:,1),obstacles(:,2),100,obstacleColor,'filled');grid;axis([0 5 0 5]);hold on; scatter(goal(1,1),goal(1,2),100,goalColor,'filled');fringeCount=1;tempCount=1;fringe(fringeCount,:)=[startingPosition, fringeCount]; while(~((fringe(fringeCount,1)==goal(1,1)) & (fringe(fringeCount, 2)==goal(1,2)))) scatter(fringe(fringeCount, 1), fringe(fringeCount, 2), 100, nodeColor, 'filled'); for x=-1:1 for y=-1:1 if(x*y==0) failsTest=0; tempNode=[fringe(fringeCount, 1)+x,fringe(fringeCount, 2)+y, fringeCount]; if((tempNode(1,1)5)) failsTest=failsTest+1; end if(failsTest