Tomasz Gebarowski

Fuzzy Logic Controller

This project is an exemplary application of fuzzy logic for controlling different types of processes. I wrote it for an Artificial Intelligence course in Windesheim University of Applied Sciences. The assignment is composed of four components:

image Fuzzy Logic

Knowledge base

It is a set of rules and constraints, describing a given process, defined in Bacus-Naur form:

<knowledge base> ::= KB <universe list>
                        <variable list> <rule list>
                     KB_END 
<universe list> ::= <universe> { <universe> } 
<universe> ::= UNIVERSE 
                   <universe name> <set list>
               UNIVERSE_END 
<set list> ::= <set> { <set> } 
<set> ::= SET <set name> 
                <x1> <x2> <x3> <x4>
               SET_END 
<variable list> ::= <variable> { <variable> } 
<variable> ::= VARIABLE <variable name>
                   <universe name> <variable type> 
               VARIABLE_END 
<variable type> ::= in | out 
<rule list> ::= <rule> { <rule> } 
<rule> ::= RULE <rule name>
             IF <premisse> THEN <conclusion>
           RULE_END 
<premisse> ::= <expression> 
<conclusion> ::= <simple expression> 
<expression> ::= <term> { OR <term> } 
<term> ::= <factor> { AND <factor> } 
<factor> ::= <simple expression> | 
              NOT <factor> | ( <expression> ) 
<simple expression> ::= <variable name> IS <set name>
<set name> ::= <name> 
<variable name> ::= <name> 
<universe name> ::= <name> 
<rule name> ::= <name> 
<x1> ::= <double> 
<x2> ::= <double> 
<x3> ::= <double> 
<x4> ::= <double> 
<name> ::= <letter or underscore>
            { <letter or underscore> | <digit> } 
<letter or underscore> ::= <letter> | _ 
<letter> ::= a..z | A .. Z 
<digit> ::= 0 .. 9 
<double> ::= <signed double> | <unsigned double> 
<signed double> ::= - <unsigned double> 
<unsigned double> ::= <number> | 
                          <number> . <number> 
<number> ::= <digit> { <digit> }

In general our knowledge base implementation has a tree-based structure in

which different levels of parsed data are stored. The figure below defines the relationships and connections between elements.

image Fuzzy Logic

Parser

The parsing process is divided into two subprocesses. The first one analyzes the structure of knowledge base, the second is concerned with evaluation of expressions. Parsing of knowledge base may be depicted in steps as follows:

Fuzzy Logic Controller

FLC uses the data gained in the parsing process. It evaluates every rule from the knowledge base. First, the premise is evaluated and the membership to a given fuzzy set is assigned. In case of complex premises, when OR operator is used the maximum value of two simple premises is taken into account, for the AND operator the minimum value would be taken. This process is described as fuzzification stage. Next, the decision making process itself begins. The conclusion provides FLC with a fuzzy set, that should be clipped at the value acquired from premise.

All the clipped fuzzy sets from analyzed rules are combined and the process advances to defuzzification stage. The defuzzification stage is based on calculating the point of gravity of the fuzzy set combined form all the clipped sets from decision making stage. The result of the defuzzification phase is passed to the controlled process.

Controller Processes

In this exemplary application two processes can be controlled:

image Fuzzy Logic

image Fuzzy Logic

However, it should be rather easy to plugin arbitrary complex process implementing the same API.

Application can be downloaded from here:

fuzzything.zip