CONTOH LOGIKA FUZZY dengan JAVA 1

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package sisteminformasi;

/**
*
* @author Abbi
*/
import java.awt.*;

class FuzzyNumber {

int iRealNum;
double iFuzzyNum;

int iLeftZero;
int iRightOne;

/**
* @param iRN The real number
**/
FuzzyNumber(int iRN)
{
iRealNum = iRN;

setRightOne(65);
setLeftZero(10);

calcFuzNum();

}

/**
* @param iRN The real number to set this to
**/
public void setReal(int iRN)
{
iRealNum = iRN;
calcFuzNum();
}

/**
* Find out what the fuzzy number should be
**/
private void calcFuzNum()
{
// Calc how much into slant it is
int iDistance = iRealNum – iLeftZero;
double dFactor = (double) 1 / (double) (iRightOne – iLeftZero);

if ( iRealNum <= iLeftZero )
iFuzzyNum = 0;
else if ( iRealNum >= iRightOne )
iFuzzyNum = 1;
else {
iFuzzyNum = (double) iDistance * dFactor;
}

}

/**
* Draw the pretty graph thing
**/
public void displayGraph( Graphics g )
{
g.setColor( Color.white );
g.fillRect( 20, 50, 180, 50 );

g.setColor( Color.black );
g.drawLine( 20, 95, 20 + 2 * iLeftZero, 95 );
g.drawLine( 20 + 2*iLeftZero, 95, 20 + iRightOne * 2, 55 );
g.drawLine( 20 + iRightOne * 2, 55, 200, 55 );

g.setColor( Color.blue );
g.drawLine( 20 + iRealNum * 2, 100, 20 + iRealNum * 2, 50 );

}

/**
* @return The fuzzy value
**/
public double getFuzzyNum()
{
return iFuzzyNum;
}

/**
* @param left The new value for iLeftZero
**/
public void setLeftZero( int left )
{
if (left < iRightOne)
iLeftZero = left;
}

/**
* @param right The new value for iRightOne
**/
public void setRightOne( int right )
{
if (right > iLeftZero)
iRightOne = right;
}

}

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