jFuzzyLogic: Open Source Fuzzy Logic (Java)

FCL example explained

Fuzzy Control Langage FCL is defined by IEC 1331 part 7. It's a simple language to define a fuzzy inferece system. We'll take a look at an example, for a more detailed explanation, please read the spec.

Keep in mind that FCL is defined as a 'Control language', so the main concept is a 'control block' which has some input and output variables (it's not a 'programm' in the usual way).
We'll be using this example, first take a look at it.

Ok, let's try to annalize each line:

  • First you define each FUNCTION_BLOCK (there may be more than one in each file)
     FUNCTION_BLOCK tipper 

  • Then input and output variable/s are defined (variable type is only REAL, integer is not implemented yet)
    VAR_INPUT
        service : REAL;
        food : REAL;
    END_VAR
    
    VAR_OUTPUT
        tip : REAL;
    END_VAR
    

  • How each input variable is fuzzified is defined in FUZZIFY block. In each block we define one or more TERMs (also called LinguisticTerms). Each term is composed by a name and a membership function. E.g.:
    FUZZIFY service
        TERM poor := (0, 1) (4, 0) ; 
        TERM good := (1, 0) (4,1) (6,1) (9,0);
        TERM excellent := (6, 0) (9, 1);
    END_FUZZIFY
    
    In this lines we define how variable service will be fuzzified. Three terms are used, for instance term poor uses a piece-wise linear membership function defined by points x_0 = 0, y_0 = 1 and x_1 = 4, y_1 = 0

    food variable fuzzify block is define likewise:

    FUZZIFY food
        TERM rancid := (0, 1) (1, 1) (3,0) ;
        TERM delicious := (7,0) (9,1);
    END_FUZZIFY
    


  • Output variables are defuzzified to get a 'real' output number, this is defined in DEFUZZIFY block. Like FUZZIFY block, linguistic terms (or TERMs) are defined:
    DEFUZZIFY tip
        TERM cheap := (0,0) (5,1) (10,0);
        TERM average := (10,0) (15,1) (20,0);
        TERM generous := (20,0) (25,1) (30,0);
    

    Then we may define some other parameters:
     METHOD : COG; 
    Use 'Center of gravity' as defuzzifier's method.

     DEFAULT := 0; 
    Use '0' as default value (if no rule actuvates this variable).

  • We can define now the rules. This is done using a RULEBLOCK. First we define some parameters:
    RULEBLOCK No1
        AND : MIN;
    
    Use 'min' for 'and' (also implicit use 'max' for 'or' to fulfill DeMorgan's Law)

     ACT : MIN; 
    Use 'min' activation method

     ACCU : MAX; 
    Use 'maximum' as accumulation method.

    And now define some rules (3 in this case)
        RULE 1 : IF service IS poor OR food IS rancid THEN tip IS cheap;
        RULE 2 : IF service IS good THEN tip IS average; 
        RULE 3 : IF service IS excellent AND food IS delicious THEN tip is generous;
    END_RULEBLOCK
    
    Ok, that's it, you've got a fuzzy controller.

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

    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