Basis Data Fuzzy Metode Tahani dengan PHP MySQL
25 December 2013 | Tags: Basis Data Fuzzy, Metode Tahani, PHP MySQL
Kali ini saya mencoba untuk membuat Basis Data Fuzzy Metode Tahani dengan PHP MySQL untuk melihat Umur, Masa Kerja dan Gaji Karyawan.
Pertama-tama kita membuat table standar untuk karyawan :
Untuk menyimpan kelompok kriteria seperti : UMUR, MASA KERJA, dan GAJI kita buatkan tabel tb_kelompok.
Selanjutnya yang menjadi poin dalam perancangan basis data fuzzy ini adalah tb_kriteria. Dalam tabel ini nantinya digunakan untuk menentukan batasan-batasan dalam menentukan derajat keanggotaan. Adapun strukturnya adalah sebagai berikut :
UMUR
Umur karyawan dikategorikan ke himpunan MUDA, PAROBAYA, TUA.
Berdasarkan data dan grafik umur tersebut diatas, bisa kita tentukan nilainya sebagai berikut :
- MUDA : nilai bawah=0, nilai tengah=30, nilai atas=40
- PAROBAYA : nilai bawah=35, nilai tengah=45, nilai atas=50
- TUA : : nilai bawah=40, nilai tengah=50, nilai atas=99 ( asumsi nilai maksimal umur )
Sehingga pada table tb_kriteria kita masukkan datanya sebagai berikut :
MASA KERJA
Masa kerja karyawan dikategorikan ke himpunan BARU, LAMA
Diperoleh :
- BARU : nilai bawah=0, nilai tengah=5, nilai atas=15
- LAMA : nilai bawah=10, nilai tengah=25, nilai atas=99 ( asumsi nilai maksimal masa kerja )
GAJI
Gaji karyawan dikategorikan ke himpunan RENDAH, SEDANG, TINGGI.
Diperoleh gaji dalam ribuan:
- RENDAH : nilai bawah=0, nilai tengah=300, nilai atas=800
- SEDANG : nilai bawah=500, nilai tengah=1000, nilai atas=1500
- TINGGI : nilai bawah=1000, nilai tengah=2000, nilai atas=10000 ( asumsi nilai maksimal gaji )
Dengan demikian pada tabel tb_kriteria, kita akan mempunyai record sebagai berikut :
Berikutnya kita akan membuatkan function PHP untuk menentukan nilai derajat keanggotaan.
<?php function derajat_keanggotaan($nilai, $bawah, $tengah, $atas) { $selisih=$atas-$bawah; if($nilai<$bawah) { $DA=0; } elseif(($nilai>=$bawah) && ($nilai<=$tengah)) { if($bawah<=0) { $DA=1; } else { $DA=($nilai-$bawah) / ($tengah-$bawah); } } elseif(($nilai>$tengah) && ($nilai<=$atas)) { $DA=($atas-$nilai) / ($atas-$tengah); } elseif($nilai>$atas) { $DA=0; } return $DA; } ?>
Adapun script Basis Data Fuzzy Metode Tahani dengan PHP MySQL selengkapnya :
<?php mysql_connect("localhost","root","jukg"); mysql_select_db("ai"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Logika Fuzzy</title> <style> body { font-family:Verdana; font-size:12px; } </style> </head> <body> <?php function derajat_keanggotaan($nilai, $bawah, $tengah, $atas) { $selisih=$atas-$bawah; if($nilai<$bawah) { $DA=0; } elseif(($nilai>=$bawah) && ($nilai<=$tengah)) { if($bawah<=0) { $DA=1; } else { $DA=($nilai-$bawah) / ($tengah-$bawah); } } elseif(($nilai>$tengah) && ($nilai<=$atas)) { $DA=($atas-$nilai) / ($atas-$tengah); } elseif($nilai>$atas) { $DA=0; } return $DA; } $kelompok =isset($_GET['kelompok'])?$_GET['kelompok']*1:0; $sql_kelompok ="SELECT * FROM tb_kelompok WHERE id='$kelompok'"; $hasil_kelompok =mysql_query($sql_kelompok); $row_kelompok =mysql_fetch_assoc($hasil_kelompok); $sql ="SELECT * FROM tb_kriteria"; $hasil =mysql_query($sql); $jumkol =mysql_num_rows($hasil); ?> Karyawan berdasarkan : <?php echo $row_kelompok['nama_kelompok'];?> <table border="1" cellpadding="3"> <tr> <td width="17" rowspan="2"><strong>ID</strong></td> <td width="221" rowspan="2"><strong>Nama</strong></td> <td width="28" rowspan="2"><strong>Usia</strong></td> <td width="37" rowspan="2"><strong>Masa Kerja</strong></td> <td width="78" rowspan="2"><strong>Gaji</strong></td> <td colspan="<?php echo $jumkol; ?>"><strong>Derajat Keanggotaan (μ[x])</strong></td> </tr> <tr> <?php $sql ="SELECT * FROM tb_kriteria WHERE kelompok='$kelompok'"; $hasil =mysql_query($sql); while($row=mysql_fetch_assoc($hasil)) { ?> <td><strong><?php echo $row['nama_kriteria'];?></strong></td> <?php } ?> </tr> <?php $sql ="SELECT * FROM tb_emp"; $hasil =mysql_query($sql); while($row=mysql_fetch_assoc($hasil)) { ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['nama']; ?></td> <td><?php echo $row['usia']; ?></td> <td><?php echo $row['masakerja']; ?></td> <td><?php echo number_format($row['gaji'],0,",","."); ?></td> <?php $sql2 ="SELECT * FROM tb_kriteria WHERE kelompok='$kelompok'"; $hasil2 =mysql_query($sql2); while($row2=mysql_fetch_assoc($hasil2)) { ?> <td ><?php echo number_format(derajat_keanggotaan($row[$row_kelompok['field_akses']], $row2['bawah'], $row2['tengah'], $row2['atas']),2,",",".");?></td> <?php } ?> </tr> <?php } ?> </table> </body> </html>
Untuk mencoba hasilnya, pada browser silahkan ketikkan : http://localhost/fuzzy/lofz.php?kelompok=3.
Maka akan muncul hasilnya seperti gambar berikut ini :
Dengan pengetahuan yang sedikit tentang Fuzzy, mohon untuk dikoreksi bila ada kesalahan.
Klik disini untuk download file dan database-nya secara lengkap.
Komentar tentang Basis Data Fuzzy Metode Tahani dengan PHP MySQL
Want to learn more about SEO software? http://bit.ly/1hW8iRn
Want the tools to rank your website? http://www.webtrafficsoftware.info
Hiya! I know this is kinda off topic however
I’d figured I’d ask. Would you be interested in exchanging links or maybe guest
authoring a blog post or vice-versa? My website discusses a lot of the same subjects as yours and I believe we could greatly benefit from
each other. If you are interested feel free to send me
an email. I look forward to hearing from you! Great blog by
the way!
Wow! In the end I got a webpage from where I can really
take valuable data concerning my study and knowledge.
My web-site :: SEO Haamilton (nekosan.j43.ca)
Hey there! I’m at work surfing around your blog from my new iphone
4! Just wanted to say I love reading through your blog and
look forward to all your posts! Carry on the great work!
It’s awesome to go to see this site and reading the views
of all colleagues on the topic of this piece of writing, while
I am also eager of getting know-how.
Great items from you, man. I have understand your stuff prior to and you’re just extremely excellent.
I actually like what you have got here, certainly like
what you are stating and the best way through which you assert it.
You’re making it enjoyable and you continue to care for to
keep it sensible. I can’t wait to read far more from you.
That is really a great web site.
Also visit my weblog :: manfaat buah mangga
GM Canada was forced to eliminate the semi-private hospital coverage
its employees enjoyed, and also reduce the annual maximum coverage for things such as orthodontic and dental benefits.
The reason they are able to offer lower rates is simply because their primary motive isn’t profit.
My web page … online title loans
Very rapidly this website will be famous among all blog
viewers, due to it’s fastidious content
My spouse and I absolutely love your blog and find a lot of your post’s to be just what I’m looking for.
Would you offer guest writers to write content in your case?
I wouldn’t mind publishing a post or elaborating on some of the subjects you write in relation to here.
Again, awesome site!
There’s certainly a great deal to learn about this issue.
I love all of the points you’ve made.
Wow! Just outstanding! Thanks a lot for the details shared! I recognize you have put a bunch of effort right into this and I would like to inform you exactly how grateful I am! There have to be a lot more blogs similar to this on the internet! I will absolutely subscribe as well as bookmark to your exceptional site! Hope you produced a lot more remarkable things in the soon and I will certainly come back as well as review it! Maintain the magnum opus!
Wow that was odd. I just wrote an incredibly long comment but after I clicked
submit my comment didn’t appear. Grrrr… well I’m not
writing all that over again. Anyhow, just wanted to
say wonderful blog!