You are on page 1of 8

TUGAS OPTIMASI NUMERIK II

ALGORITMA GENETIKA

Oleh:

Fian Eko Saputra (155090400111009)

Eirene Putri Hutasoit (155090400111010)

Ahmmad Maliki (155090401111033)

PROGRAM STUDI MATEMATIKA

JURUSAN MATEMATIKA

FAKULTAS MATEMATIKA DAN ILMU PENGETAHUAN ALAM

UNIVERSITAS BRAWIJAYA

2018
Soal

Pada kelas mata kuliah optimasi numerik terdiri dari 40 orang mahasiswa. Pada akhir
perkuliahan ada tugas proyek sebagai tugas akhir mata kuliah, dosen ingin membagi mahasiswa
dalam kelas tersebut menjadi 10 kelompok. Agar pembagian nomor kelompok adil dan proyek
dapat dikerjakan maka dosen menetapkan aturan pembagian kelompok sebagai berikut :

a. Dalam setiap kelompok minimum ada satu mahasiswa yang nilai kuisnya diatas 75.
b. Dalam setiap kelompok minimum ada satu mahasiswa yang nilai utsnya diatas 75.
c. Dalam satu kelompok minimum ada satu orang mahasiswa yang memiliki satu orang
yang berjenis kelamin beda.
d. Dalam setiap kelompok minimum ada seorang mahasiswa yang rata-rata tugasnya diatas
80.
Data diambil dari file bertipe xls dan output pembagian kelompok juga berupa file bertipe xls.
Gunakan algoritma genetika untuk menyelesaikan masalah diatas.
1. Tentukan model kromosom untuk masalah diatas.
2. Tentukan fungsi objektif untuk masalah diatas.
3. Tentukan operasi crossover untuk masalah diatas.
4. Tentukan operasi mutasi untuk masalah diatas.
5. Buatlah program untuk masalah diatas.
6. Analisislah hasil program diatas.
Pembahasan

1.

Keterangan
Kotak 1-4 : Kelompok 1
Kotak 5-8 : Kelompok 2
Kotak 9-12 : Kelompok 3
Kotak 13-16 : Kelompok 4
Kotak 17-20 : kelompok 5
Kotak 21-24 : Kelompok 6
Kotak 25-28 : Kelompok 7
Kotak 29-32 : Kelompok 8
Kotak 33-36 : Kelompok 9
Kotak 37-40 : Kelompok 10

Data yang digunakan : (Ket jenis kelamin : 1=laki-laki, 0=perempuan)

Nomer Kuis UTS Jenis Kelamin Rata-Rata Tugas


1 10 25 1 75
2 20 43 0 75
3 70 77 1 80
4 70 87 0 80
5 55 60 1 80
6 80 88 1 75
7 30 43 1 90
8 65 7 0 95
9 90 81 1 80
10 67 80 1 85
11 78 88 0 70
12 50 67 0 85
13 60 76 0 75
14 45 40 1 90
15 65 70 1 95
16 33 40 1 70
17 49 55 0 80
18 67 77 1 75
19 81 90 1 90
20 34 55 0 75
21 70 65 0 80
22 85 90 0 85
23 60 30 1 90
24 72 68 1 95
25 74 60 1 70
26 80 85 0 80
27 45 50 1 90
28 37 40 0 85
29 49 55 0 95
30 71 78 0 75
31 100 90 0 80
32 26 40 1 90
33 40 55 1 85
34 91 90 0 70
35 54 50 1 75
36 51 70 0 80
37 70 75 0 80
38 45 60 0 90
39 40 45 0 95
40 57 70 1 70

2. Fungsi objektif
f=x1+x2+x3+x4+x5+x6+x7+x8+x9+x10

3. Linear Order Crossover

function xx=crossover(MA,PA)
L=length(MA);
k=round(rand*(L-2))+1;
xx(1,1:k)=MA(1:k);
n=k+1;
for i=1:L
q=0;
for j=1:k
if PA(i)==MA(j)
q=q+1;
end
end
if q==0
xx(1,n)=PA(i);
n=n+1;
end
end
xx(2,1:k)=PA(1:k);
n=k+1;
for i=1:L
q=0;
for j=1:k
if MA(i)==PA(j)
q=q+1;
end
end
if q==0
xx(2,n)=MA(i);
n=n+1;
end
end
end

4. Mutasi

function xx=mutasi(xx)
p=round(rand*19+1);
y=round(rand*19+1);
temp1=xx(1,p);
xx(1,p)=xx(1,y);
xx(1,y)=temp1;
temp2=xx(2,p);
xx(2,p)=xx(2,y);
xx(2,y)=temp2;
end

5. Program

clear all;
clc;
n=40;
kuis=xlsread('Book1','B2:B41');
uts=xlsread('Book1','C2:C41');
kelamin=xlsread('Book1','D2:D41');
tugas=xlsread('Book1','E2:E41');
Ngen=n;
Npop=6;
generasi=600;
%costfunction
f='x1+x2+x3+x4+x5+x6+x7+x8+x9+x10';
costfunction=inline(f);
%Generate Initial Random Population
for i=1:Npop
kromosom(i,:)=randperm(Ngen);
end
for s=1:generasi

%mencari penalty
x=penalty(kromosom,kelamin,tugas,kuis,uts);
%Evaluasi Fungsi Objektif
for i=1:Npop

costkromosom(i)=costfunction(x(i,1),x(i,2),x(i,3),x(i,4),x(i,5),x(i,6),x(i,7)
,x(i,8),x(i,9),x(i,10));
fitness(i)=1/(costkromosom(i)+10^-5);
end
oldkromosom=kromosom;
oldfitness=fitness;
%%Rank Selection Method
%Pengurutan Kromosom berdasarkan Fitness Terbesar
for i=1:Npop
BestCost=costkromosom(i);
BestIndex=i;
BestKromosom=kromosom(i,:);
for j=i:Npop
if BestCost >= costkromosom(j)
BestIndex=j;
BestCost=costkromosom(j);
BestKromosom=kromosom(j,:);
end
end
temp=kromosom(i,:);
kromosom(i,:)=BestKromosom;
kromosom(BestIndex,:)=temp;

temp=costkromosom(i);
costkromosom(i)=costkromosom(BestIndex);
costkromosom(BestIndex)=temp;

temp=fitness(i);
fitness(i)=fitness(BestIndex);
fitness(BestIndex)=temp;

clear BestFitness BestIndex BestKromosom


end
clear costkromosom fitness qn x
%Mencari penalty dari kromosom yang telah urut
x=penalty(kromosom,kelamin,tugas,kuis,uts);
for i=1:Npop

costkromosom(i)=costfunction(x(i,1),x(i,2),x(i,3),x(i,4),x(i,5),x(i,6),x(i,7)
,x(i,8),x(i,9),x(i,10));
fitness(i)=1/(costkromosom(i)+10^-5);
end

%% Selanjutnya proses seleksi


%Disini dipakai Rank Selection, Kromosom terbaik mendapat Rank = Npop,
%Terburuk mendapat Rank = 1
SumRank=sum(1:Npop);
for i=1:Npop
Prob(i)=(Npop-i+1)/SumRank;
%Peluang Rank 1 terpilih adalah 1/SumRank, Rank 2 terpilih adalah
%2/SumRank, .. , Rank Npop terpilih adalah Npop/SumRank (Paling
besar)
end
%Berikutnya diterapkan sejenis Roulette Wheel Selection untuk memilih
%kromosom
indekspilih=rws(Prob);
for i=1:Npop
if i==indekspilih
MA=kromosom(i,:);
end
end
indekspilih=rws(Prob);
for i=1:Npop
if i==indekspilih
PA=kromosom(i,:);
end
end
%crossover
xx=crossover(MA,PA);
%mutasi
xx=mutasi(xx);
%update kromosom
kromosom(Npop,:)=xx(2,:);
kromosom(Npop-1,:)=xx(1,:);
end
sheet = 1;
xlRange = 'B2';
xlswrite('Hasil',kromosom,sheet,xlRange);

6. Hasil Analisis

Diperoleh data hasil pengelompokkan kedalam 10 kelompok

Populasi Kelompok 1 Kelompok 2 Kelompok 3 Kelompok 4 Kelompok 5


1 12 9 1 14 33 10 27 2 29 35 4 23 7 20 24 39 21 5 18 15
2 14 9 5 18 33 10 27 4 29 35 1 23 7 20 24 39 21 2 12 15
3 14 9 5 18 33 10 27 2 29 35 1 23 7 20 24 39 21 4 12 15
4 18 9 5 14 33 10 27 2 29 35 1 23 7 20 24 39 21 4 12 15
5 14 9 1 18 33 10 27 2 29 35 20 23 7 5 24 39 21 4 12 15
6 14 9 5 18 33 10 27 2 29 35 20 23 7 1 24 39 21 4 12 15

Kelompok 6 Kelompok 7 Kelompok 8 Kelompok 9 Kelompok 10


3 36 34 30 38 22 28 25 16 11 37 26 13 8 31 6 19 40 32 17
3 36 34 30 38 22 28 25 16 11 37 26 13 8 31 6 19 40 32 17
3 36 34 30 38 22 28 25 16 11 37 26 13 8 31 6 19 40 32 17
3 36 34 30 38 22 28 25 16 11 37 26 13 8 31 6 19 40 32 17
3 36 34 30 38 22 28 25 16 11 37 26 13 8 31 6 19 40 32 17
3 36 34 30 38 22 28 25 16 11 37 26 13 8 31 6 19 40 32 17
Telah dianalisis dengan menggunakan algortima genetika dengan proses crossover menggunakan
linear order crossover didapat sebanyak enam populasi dimana setiap populasi terdiri dari 10
kelompok. Dipilih populasi pertama karena populasi tersebut memiliki nilai cost paling tinggi
dan memenuhi ketentuan.

You might also like