Hasil Tugas 5 – HillClambing


membahas tentang logika pencarian tujuan

materi logika pencarian > Searching 2012

materi tambahan > Bab 4 Algoritma Pencarian

flowchart untuk fungsi Hill Clambing saja :

HillCalmbingTesFungsi-2

file PDF > HillCalmbingTesFungsi-2

source code fungsi Hill Clambing dengan cpp :

#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <string.h>

#define MAX 100
extern double Cost(STATE *pS);
extern int Solution(STATE *pS);
extern int GetNeighbours(STATE *pS, STATE Next[MAX]);

int HillClambing(STATE *pS, STATE *pS){
STATE Next[MAX];
int i,n,index;
double c0,c,c1;

if(Solution(pS0)){
CopyState(pS,pS0);
return(1);
}
CopyState(pS,pS0);
c0=Cost(pS0);

while((n=GetNeighbours(pS,Next))>0){
index=0;
c=Cost(&Next[0]);
for(i=0;i<n;i++){
if(Solution(&Next[i])){
CopyState(pS,&Next[i]);
return(1);
}
if((c1=Cost(&Next[i]))<c){
index=i;
c=c1;
}
}

if(c<c0){
CopyState(pS,&Next[index]);
c0=c;
}
else
break;
}

return(0);
//solusi global tak tertemukan
}

Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: