0% found this document useful (0 votes)
69 views4 pages

Algoritma Genetika

This document contains an algorithm for genetic algorithms written in MATLAB. It initializes a random population matrix Cr, evaluates the fitness of each individual using an equation, selects individuals for reproduction based on fitness, performs crossover on selected parents to generate offspring, performs mutation on offspring, and iterates for 2000 generations or until a perfect solution is found. It outputs the generation number, best solution individual, and proof that it satisfies the equation.

Uploaded by

Ahmed Elsyarief
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views4 pages

Algoritma Genetika

This document contains an algorithm for genetic algorithms written in MATLAB. It initializes a random population matrix Cr, evaluates the fitness of each individual using an equation, selects individuals for reproduction based on fitness, performs crossover on selected parents to generate offspring, performs mutation on offspring, and iterates for 2000 generations or until a perfect solution is found. It outputs the generation number, best solution individual, and proof that it satisfies the equation.

Uploaded by

Ahmed Elsyarief
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Nama : Bayu Ardiansyah

NIM :11506134018
Prodi : T.LEKTRO D3

ALGORITMA GENETIKA

A. Tampilan Hasil Program dengan Matlab


Cr =
48
11
30
24
45
38

23 47 20
0 37 45
41 8 2
22 20 17
31 47 41
40 46 0

Persamaan =
1

generasi =
28

Cr =
14
14
11
14
14
4

6
6
6
6
6
6

2 2
18 2
1 2
1 2
1 2
2 2

hasil =
4

bukti =
30

B. Program
clear all
clc
%initialisation
Cr = randint(6,4,[0,50])
%Cr = [12 5 3 8; 2 1 8 3; 10 4 3 4; 20 1 10 6; 1 4 3 9; 20 5 7 1]
Persamaan = [1 2 3 4]
for w=1:2000
%Evaluation
Fno=(Cr*Persamaan')-30;
%selection
Ff=power(Fno+1,-1);
jmlFf=sum(Ff);
Prob=Ff/jmlFf;
C(1)=Prob(1);
for k=2:6
C(k)=C(k-1)+Prob(k);
end
C;
%R=[0.201 0.284 0.009 0.822 0.398 0.501];
R=rand(6,1);
for i=1:6
for j=1:6
if(R(i)<C(j)),
Cr2(i,:)=Cr(j,:);
break
end
end
end
Cr=Cr2;
%cross over
PC=0.40;
%R1=[0.191 0.259 0.760 0.006 0.159 0.340];
R1=rand(6,1);
jp=0;
for k=1:6
if(R1(k)<PC)
jp=jp+1;

induk(jp,:)=Cr(k,:);
alamat(jp)=k;
end
end
induk;
for e=1:jp
cut=randint(1,e,[1,3]);
end
cut;
for i=1:jp
if(i<jp)
induk2(i,:)=induk(i+1,:);
else
induk2(i,:)=induk(1,:);
end
end
induk2;
for a=1:jp
for b=1:4
if(b<=cut(a))
offspring(a,b)=induk(a,b);
else
offspring(a,b)=induk2(a,b);
end
end
end
offspring;
for i=1:jp
Cr(alamat(i),:)=offspring(i,:);
end
Cr;
%mutasi
Tgen=6*4;
mutarate=round(Tgen/10);
for i=1:mutarate
pos=randint(i,1,[1,Tgen]);
end
pos;
for i=1:mutarate
isi=randint(i,1,[0,30]);
end
isi;
for i=1:mutarate

hit=0;
for j=1:6
for k=1:4
hit=hit+1;
if(hit==pos(i))
Cr(j,k)=isi(i);
end
end
end
end
Cr;
Fno=(Cr*Persamaan')-30;
if(Fno(1)==0)
index=1;
break
elseif(Fno(2)==0)
index=2;
break
elseif(Fno(3)==0)
index=3;
break
elseif(Fno(4)==0)
index=4;
break
elseif(Fno(5)==0)
index=5;
break
elseif(Fno(6)==0)
index=6;
break
end
end
Fno=(Cr*Persamaan')-30;
generasi=w
Cr
hasil=Cr(index,:)
bukti=hasil*Persamaan'

You might also like