jFuzzyLogic: Open Source Fuzzy Logic (Java)

Jave example explained

This is a simple java code used to load a fuzzy inference system (FIS), this code available at net.sourceforge.jFuzzyLogic.TestTipper.java

  • First load an FCL file, using FIS.load(fileName) function.
    String fileName = "fcl/tipper.fcl";
    FIS fis = FIS.load(fileName,true);
    

  • When an error is detected during FIS.load(), a null object is returned.
    if( fis == null ) { // Error while loading?
    	System.err.println("Can't load file: '" + fileName + "'");
    	return;
    }
    

  • Now we can plot the FIS. Actually, we plot each Variable in the FUNCTION_BLOCK (and each LinguisticTerm in each Variable). This might only be usefull when you are debugging your code.
     fis.chart(); 

    And we get the following images:

  • Now we use the FIS. We start by setting FIS' inputs
    fis.setVariable("service", 3);
    fis.setVariable("food", 7);
    

  • And we run the system
    fis.evaluate();

  • If we want to know the system's output (in this case there's only one output variable 'tip')
    fis.getVariable("tip").getLatestDefuzzifiedValue();

  • We can also plot output's defuzzifier (probably only during debuging)
    fis.getVariable("tip").chartDefuzzifier(true);

  • And, of course, we can print the FIS
    System.out.println(fis);

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Author: Pablo Cingolani (pcingola@users.sourceforge.net)
Key words (for search engines):
Fuzzy logic
Fuzzy logic software
Fuzzy logic package
Fuzzy logic library
Fuzzy logic sourceforge sf.net
Open source
GNU
GPL LGPL
java
Windows Linux OSX
FCL
IEC 1131
IEC 61131
IEC 61131 part 7
IEC 61131-7
Fuzzy logic Wikipedia