Created
October 27, 2019 13:02
-
-
Save adibenc/7c7d88decbee1876ed85c9d32b4bc901 to your computer and use it in GitHub Desktop.
fuzzy.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//submit | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class Fuzzy extends CI_Controller | |
{ | |
public function __construct() | |
{ | |
parent::__construct(); | |
//$this->load->model("Grafik_model"); | |
$this->load->library('form_validation'); | |
} | |
public function index (){ | |
// $data["gas_grafik"] = $this->Product_model->getAll(); | |
// $data['tgl'] = $date; | |
// $data["perWaktu"] =$this->Grafik_model->getPerHour() | |
// $this->load->view("admin/product/v_fuzzy", $data); | |
} | |
public function inputdata(){ | |
$this->load->view('admin/product/v_input'); | |
} | |
public function submit(){ | |
$k=$this->input->get('kepadatan'); | |
$p=$this->input->get('polusi'); | |
$t=$this->input->get('tumbuhan'); | |
// echo $k."k_sepi".$k."k_sedang".$t."k_ramai"; | |
// echo $p."p_tpolusi".$p."p_sedang".$p."p_spolusi"; | |
// echo $t."tu_sedikit".$t."tu_sedang".$t."tu_banyak"; | |
//proses | |
// echo "<br>"; | |
// $hasil= | |
// echo $hasil; | |
$fuz=$this->fuzzy($k,$p,$t); | |
// echo $fuz; | |
$data['fuz']=$fuz; | |
$this->load->view('admin/product/v_input',$data); | |
} | |
public function fuzzy($k,$p,$t){ | |
$kepadatan = $k; | |
$polusi = $p; | |
$tumbuhan = $t; | |
$kepadatan = 60; | |
$polusi = 1200; | |
$tumbuhan = 63; | |
$param['k_sepi'] = $this->k_sepi($kepadatan); | |
$param['k_sedang'] = $this->k_sedang($kepadatan); | |
$param['k_ramai'] = $this->k_ramai($kepadatan); | |
$param['p_tpolusi'] = $this->p_tpolusi($polusi); | |
$param['p_sedang'] = $this->p_sedang($polusi); | |
$param['p_spolusi'] = $this->p_spolusi($polusi); | |
$param['tu_sedikit'] = $this->tu_sedikit($tumbuhan); | |
$param['tu_sedang'] = $this->tu_sedang($tumbuhan); | |
$param['tu_banyak'] = $this->tu_banyak($tumbuhan); | |
// var_dump ($this->p_spolusi($polusi)); | |
$aprediket = $this->rules($param); | |
// print_r($aprediket); | |
$hasil = $this->max($aprediket); | |
// print_r($param); | |
//print_r($hasil); | |
$rendah = array(); | |
$normal = array(); | |
$tinggi = array(); | |
for ($i=0; $i<count($hasil) ; $i++) { | |
if ($hasil[$i]['rule'] == 'rendah') { | |
array_push($rendah, $hasil[$i]['min']); | |
} else if ($hasil[$i]['rule'] == 'normal') { | |
array_push($normal, $hasil[$i]['min']); | |
} else if ($hasil[$i]['rule'] == 'tinggi') { | |
array_push($tinggi, $hasil[$i]['min']); | |
} | |
} | |
// echo "Min rendah"; | |
// print_r($rendah); | |
// echo"Min Normal"; | |
// print_r($normal); | |
// echo "Min Tinggi"; | |
// print_r($tinggi); | |
$maxR = max($rendah); | |
$maxN = max($normal); | |
$maxT = max($tinggi); | |
// echo "Max Rendah"; | |
// print_r($maxR); | |
// echo "</br>"; | |
// echo "Max Normal"; | |
// print_r($maxN); | |
// echo "</br>"; | |
// echo "Max Tinggi"; | |
// print_r($maxT); | |
// echo "</br>"; | |
$deR = $this->defuzzi_rendah($maxR); | |
$deN = $this->defuzzi_normal($maxN); | |
$deT = $this->defuzzi_tinggi($maxT); | |
// print_r($deR); | |
// echo "<br>"; | |
// print_r($deN); | |
// echo "<br>"; | |
// print_r($deT); | |
// echo "<br>"; | |
$integralRendah = $this->integralAngka($maxR, $deR, 0); | |
// echo "Defuzzi Rendah:"; | |
// print_r($integralRendah); | |
// echo "<br>"; | |
$integralTinggi = $this->integralAngka($maxT, $deT, 0); | |
// echo "Defuzzifikasi Tinggi:"; | |
// print_r($integralTinggi); | |
// echo "<br>"; | |
$integralPer=$this->integral1($deN, $deT); | |
// echo "Defuzzifikasi Normal:"; | |
// print_r($integralPer); | |
// echo "<br>"; | |
// echo "Luas Daerah Adalah :" ; | |
$luas=$this->luas_daerah($deR, $deN, $deT, $maxR, $maxN, $maxT); | |
$hasil = $this->sum($integralTinggi, $integralPer, $integralRendah) / $luas; | |
// echo($hasil); | |
// echo "Celcius"; | |
print_r($maxR); | |
$ret=sprintf(" | |
Min Rendah: %0.1f \n <br> | |
Min Normal: %0.1f \n <br> | |
Min Tinggi: %0.1f \n <br> | |
Max Rendah: %0.1f \n <br> | |
Max Normal: %0.1f \n <br> | |
Max Tinggi: %0.1f \n <br> | |
Momentum Rendah: %0.1f \n <br> | |
Momentum Normal: %0.1f \n <br> | |
Momentum Tinggi: %0.1f \n <br> | |
Defuzzifikasi Rendah: %d \n <br> | |
Defuzzifikasi Normal: %d \n <br> | |
Defuzzifikasi Tinggi: %d \n <br> | |
Luas Daerah: %d \n <br> | |
Hasil: %0.3f \n <br> | |
", | |
// array( | |
$rendah[0], | |
$normal[0], | |
$tinggi[0], | |
$maxR, | |
$maxN, | |
$maxT, | |
$deR, | |
$deN, | |
$deT, | |
$integralRendah, | |
$integralPer, | |
$integralTinggi, | |
$luas, | |
$hasil | |
// ) | |
); | |
return $ret; | |
} | |
public function k_sepi($x) | |
{ | |
if ($x <=30) { | |
return 1; | |
} | |
else if($x<=50 and $x >=30) { | |
return (50-$x)/(50-30); | |
} | |
else if ($x>=50) { | |
return 0; | |
} | |
} | |
public function k_sedang($x) | |
{ | |
if (($x <=30) or ($x>=70)) { | |
return 0; | |
} | |
else if(($x<=50) and ($x>=30)) { | |
return ($x-30)/(50-30); | |
} | |
else if ($x >=50 and $x<=70) { | |
return (70-$x)/(70-50); | |
} | |
} | |
public function k_ramai($x) | |
{ | |
if ($x <=50){ | |
return 0; | |
} | |
else if (($x>=50) and ($x<=70)){ | |
return ($x-50)/(70-50); | |
} | |
else if ($x>=70) { | |
return 1; | |
} | |
} | |
public function p_tpolusi ($x) | |
{ | |
if ($x <=500){ | |
return 1; | |
} | |
else if (($x<=500) or ($x>=1500)){ | |
return (1000-$x)/ ((1000-500)); | |
} | |
else if ($x>=1000) { | |
return 0; | |
} | |
} | |
public function p_sedang($x) | |
{ | |
if (($x<=500) or ($x>=1500)) { | |
return 0; | |
} | |
else if ((500<=$x) and ($x<=1000)){ | |
return ($x-500)/(1000-500); | |
} | |
else if ((1000<=$x) and ($x<=1500)){ | |
return (1500-$x)/(1500-1000); | |
} | |
} | |
public function p_spolusi($x) | |
{ | |
if ($x<=1000) { | |
return 0; | |
} | |
else if (($x>=1000) and ($x<=1500)){ | |
return ($x-1000)/(1500-1000); | |
} | |
else if ($x>=1500){ | |
return 1; | |
} | |
} | |
public function tu_sedikit($x) | |
{ | |
if ($x<=30) { | |
return 1; | |
} | |
else if (($x<=30) or ($x<=50)){ | |
return (50-$x)/(50-30); | |
} | |
else if ($x>=50){ | |
return 0; | |
} | |
} | |
public function tu_sedang($x) | |
{ | |
if (($x<=50) or ($x>=70)){ | |
return 0; | |
} | |
else if (($x>=50) and ($x<=70)){ | |
return (70-$x)/(70-50); | |
} | |
else if ($x<=70){ | |
return 1; | |
} | |
} | |
public function tu_banyak($x) | |
{ | |
if ($x <=50){ | |
return 0; | |
} | |
else if (($x>=50) and ($x<=70)){ | |
return ($x-50)/(70-50); | |
} | |
else if ($x>=70) { | |
return 1; | |
} | |
} | |
public function rules($x) | |
{ | |
$k_sepi = $x['k_sepi']; | |
$k_sedang = $x['k_sedang']; | |
$k_ramai = $x['k_ramai']; | |
$p_tpolusi = $x['p_tpolusi']; | |
$p_sedang = $x['p_sedang']; | |
$p_spolusi = $x['p_spolusi']; | |
$tu_sedikit = $x['tu_sedikit']; | |
$tu_sedang = $x['tu_sedang']; | |
$tu_banyak = $x['tu_banyak']; | |
$i = 0; | |
// $aprediket = array(0); | |
if ($k_sepi != 0 AND $p_tpolusi != 0 AND $tu_sedikit != 0) { | |
$aprediket[$i]['min']=min($k_sepi, $p_tpolusi, $tu_sedikit); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='1'; | |
$i++; | |
} | |
if ($k_sepi != 0 AND $p_tpolusi != 0 AND $tu_sedang !=0){ | |
$aprediket[$i]['min']=min($k_sepi, $p_tpolusi, $tu_sedang); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='2'; | |
$i++; | |
} | |
if ($k_sepi !=0 AND $p_tpolusi !=0 AND $tu_banyak !=0) { | |
$aprediket[$i]['min']=min($k_sepi, $p_tpolusi, $tu_banyak); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='3'; | |
$i++; | |
} | |
if ($k_sepi !=0 AND $p_sedang !=0 AND $tu_sedikit !=0) { | |
$aprediket[$i]['min']=min($k_sepi, $p_sedang, $tu_sedikit); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='4'; | |
$i++; | |
} | |
if ($k_sepi !=0 AND $p_sedang !=0 AND $tu_sedang !=0){ | |
$aprediket[$i]['min']=min($k_sepi, $p_sedang, $tu_sedang); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='5'; | |
$i++; | |
} | |
if ($k_sepi !=0 AND $p_sedang !=0 AND $tu_banyak !=0){ | |
$aprediket[$i]['min']=min($k_sepi, $p_sedang, $tu_banyak); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='6'; | |
$i++; | |
} | |
if ($k_sepi !=0 AND $p_spolusi !=0 AND $tu_sedikit !=0){ | |
$aprediket[$i]['min']=min($k_sepi, $p_spolusi, $tu_sedikit); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='7'; | |
$i++; | |
} | |
if ($k_sepi !=0 AND $p_spolusi !=0 AND $tu_sedang !=0){ | |
$aprediket[$i]['min']=min($k_sepi, $p_spolusi, $tu_sedang); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='8'; | |
$i++; | |
} | |
if ($k_sepi !=0 AND $p_spolusi !=0 AND $tu_banyak !=0){ | |
$aprediket[$i]['min']=min($k_sepi, $p_spolusi, $tu_banyak); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='9'; | |
$i++; | |
} | |
if ($k_sedang !=0 AND $p_tpolusi !=0 AND $tu_sedikit !=0){ | |
$aprediket[$i]['min']=min($k_sedang, $p_tpolusi, $tu_sedikit); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='10'; | |
$i++; | |
} | |
if ($k_sedang !=0 AND $p_tpolusi !=0 AND $tu_sedang !=0){ | |
$aprediket[$i]['min']=min($k_sedang, $p_tpolusi, $tu_sedang); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='11'; | |
$i++; | |
} | |
if ($k_sedang !=0 AND $p_tpolusi !=0 AND $tu_banyak !=0){ | |
$aprediket[$i]['min']=min($k_sedang, $p_tpolusi, $tu_banyak); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='12'; | |
$i++; | |
} | |
if ($k_sedang !=0 AND $p_sedang !=0 AND $tu_sedikit !=0){ | |
$aprediket[$i]['min']=min($k_sedang, $p_sedang, $tu_sedikit); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='13'; | |
$i++; | |
} | |
if ($k_sedang !=0 AND $p_sedang !=0 AND $tu_sedang !=0){ | |
$aprediket[$i]['min']=min($k_sedang, $p_sedang, $tu_sedang); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='14'; | |
$i++; | |
} | |
if ($k_sedang !=0 AND $p_sedang !=0 AND $tu_banyak !=0){ | |
$aprediket[$i]['min']=min($k_sedang, $p_sedang, $tu_banyak); | |
$aprediket[$i]['rule']='rendah'; | |
$aprediket[$i]['ke']='15'; | |
$i++; | |
} | |
if ($k_sedang !=0 AND $p_spolusi !=0 AND $tu_sedikit !=0){ | |
$aprediket[$i]['min']=min($k_sedang, $p_spolusi, $tu_sedikit); | |
$aprediket[$i]['rule']='rendah'; | |
$aprediket[$i]['ke']='16'; | |
$i++; | |
} | |
if ($k_sedang !=0 AND $p_spolusi !=0 AND $tu_sedang !=0){ | |
$aprediket[$i]['min']=min($k_sedang, $p_spolusi, $tu_sedang); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='17'; | |
$i++; | |
} | |
if ($k_sedang !=0 AND $p_spolusi !=0 AND $tu_banyak !=0){ | |
$aprediket[$i]['min']=min($k_sedang, $p_spolusi, $tu_banyak); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='18'; | |
$i++; | |
} | |
if ($k_ramai !=0 AND $p_tpolusi !=0 AND $tu_sedikit !=0){ | |
$aprediket[$i]['min']=min($k_ramai, $p_tpolusi, $tu_sedikit); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='19'; | |
$i++; | |
} | |
if ($k_ramai !=0 AND $p_tpolusi !=0 AND $tu_sedang !=0){ | |
$aprediket[$i]['min']=min($k_ramai, $p_tpolusi, $tu_sedang); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='20'; | |
$i++; | |
} | |
if ($k_ramai !=0 AND $p_tpolusi !=0 AND $tu_banyak !=0){ | |
$aprediket[$i]['min']=min($k_ramai, $p_tpolusi, $tu_banyak); | |
$aprediket[$i]['rule']='rendah'; | |
$aprediket[$i]['ke']='21'; | |
$i++; | |
} | |
if ($k_ramai !=0 AND $p_sedang !=0 AND $tu_sedikit !=0){ | |
$aprediket[$i]['min']=min($k_ramai, $p_sedang, $tu_sedikit); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='22'; | |
$i++; | |
} | |
if ($k_ramai !=0 AND $p_sedang !=0 AND $tu_sedang !=0){ | |
$aprediket[$i]['min']=min($k_ramai, $p_sedang, $tu_sedang); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='23'; | |
$i++; | |
} | |
if ($k_ramai !=0 AND $p_sedang !=0 AND $tu_banyak !=0){ | |
$aprediket[$i]['min']=min($k_ramai, $p_sedang, $tu_banyak); | |
$aprediket[$i]['rule']='normal'; | |
$aprediket[$i]['ke']='24'; | |
$i++; | |
} | |
if ($k_ramai !=0 AND $p_spolusi !=0 AND $tu_sedikit !=0){ | |
$aprediket[$i]['min']=min($k_ramai, $p_spolusi, $tu_sedikit); | |
$aprediket[$i]['rule']='tinggi'; | |
$aprediket[$i]['ke']='25'; | |
$i++; | |
} | |
if ($k_ramai !=0 AND $p_spolusi !=0 AND $tu_sedang !=0){ | |
$aprediket[$i]['min']=min($k_ramai, $p_spolusi, $tu_sedang); | |
$aprediket[$i]['rule']='tinggi'; | |
$aprediket[$i]['ke']='26'; | |
$i++; | |
} | |
if ($k_ramai !=0 AND $p_spolusi !=0 AND $tu_banyak !=0){ | |
$aprediket[$i]['min']=min($k_ramai, $p_spolusi, $tu_banyak); | |
$aprediket[$i]['rule']='tinggi'; | |
$aprediket[$i]['ke']='27'; | |
$i++; | |
} | |
return $aprediket; | |
} | |
public function max($aprediket) | |
{ | |
for ($i=0; $i < sizeof($aprediket) ; $i++) { | |
$x = $aprediket[$i]['rule']; | |
$a = $aprediket[$i]['min']; | |
// print_r($x); | |
// print_r($a); | |
if ($x == 'rendah'){ | |
if ($a<=22) { | |
$z = 1; | |
} else if (($a >= 22) AND ($a <= 26)){ | |
$z = (26-$a)/(26-22); | |
} else if ($a >= 26){ | |
$z = 0; | |
} | |
$aprediket[$i]['max'] = 26 - $a*(26-22); | |
} else if ($x == 'normal') { | |
if (($a<=22) OR ($a >= 32)) { | |
$z = 0; | |
} else if (($a >= 22) AND ($a <= 26)){ | |
$z = ($a-22)/(26-22); | |
} else if (($a >= 26) AND ($a <= 32)){ | |
$z = (32-$a)/(32-26); | |
} | |
$aprediket[$i]['max'] = 32 - $a*(32-26); | |
} else if ($x == 'tinggi') { | |
if ($a<=26) { | |
$z = 0; | |
} else if (($a >= 26) AND ($a <= 32)){ | |
$z = ($a-26)/(32-26); | |
} else if ($a >= 32){ | |
$z = 1; | |
} | |
$aprediket[$i]['max'] =26-$a*(32-26); | |
} | |
} | |
return $aprediket; | |
} | |
public function defuzzi_rendah($x) | |
{ | |
return $x*(26-22)+22; | |
} | |
public function defuzzi_normal($x) | |
{ | |
return $x*(26-22)+22; | |
} | |
public function defuzzi_tinggi($x) | |
{ | |
return (32-($x*(32-26))); | |
} | |
public function integralAngka($x, $atas, $bawah) | |
{ | |
return ($x/2)*pow($atas,2) - ($x/2)*pow($bawah,2); | |
} | |
// function integralPer($x=1) | |
// { | |
// return ($x**3-22*($x**2))/8-((1/24)*$x**3); | |
// } | |
// function integral1($x=0,$x2=1){ | |
// return integralPer($x2)-integralPer($x); | |
// echo "hasil ".integral1(24, 29.6); | |
function integralPer($x=1){ | |
return | |
($x**3-22*($x**2))/8 | |
- | |
((1/24)*$x**3) | |
; | |
} | |
function integral1($x=0,$x2=1){ | |
return $this->integralPer($x2) - $this->integralPer($x); | |
} | |
public function luas_daerah($deR, $deN, $deT, $maxR, $maxN, $maxT){ | |
return $deR * $maxR + | |
($maxN - $maxT)*($deT-$deN) + | |
$deT * $maxT; | |
} | |
public function sum($x, $y, $z) | |
{ | |
return $x+$y+$z; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment