J Fuzzy Logic
J Fuzzy Logic
J Fuzzy Logic
I. I NTRODUCTION
Fuzzy rule based systems (FRBSs) are one of the most
important areas for the application of the Fuzzy Set Theory
[1]. Classical rule based systems deal with IF-THEN rules.
FRBSs constitute an extension to classical systems, having
antecedents and consequents composed of fuzzy logic statements.
A Fuzzy Logic Controller (FLC) [2][5] is a FRBS composed of: i-) a Knowledge Base that comprises the information
used by the expert operator in the form of linguistic control
rules; ii-) a Fuzzification Interface, that transforms the crisp
values of the input variables into fuzzy sets; iii-) an Inference
System, that uses the fuzzy values from the Fuzzification
Interface and the information from the Knowledge Base to
perform the reasoning process and iv-) the Defuzzification
Interface, which takes the fuzzy action from the Inference
System and translates it into crisp values for the control
variables.
FLCs are suitable for engineering applications in which
classical control strategies do not achieve good results or when
it is too difficult to obtain a mathematical model. FLCs usually
have two characteristics: the need for human operator experience, and a strong non linearity. Many real-world applications
use FLCs [6] such as mobile robot navigation [7], [8], air
conditioning controllers [9], [10], domotic control [11], [12],
and industrial applications [13], [14].
FLCs are powerful for solving a wide range of problems,
but their implementation requires a certain programming expertise. In the last few years, many fuzzy logic software
tools have been developed to reduce this task. Some are
commercially distributed, for example MATLAB Fuzzy logic
toolbox(www.mathworks.com), while a few are available as
open source software (see section II).
FCL support. Only four packages ( 17%) claim to support IEC 61131-7 specification. Notably two of them are
based on jFuzzyLogic. Only two packages that support
FCL are not based on our software. Unfortunately neither
of them seem to be maintained by their developers any
more. Furthermore, one of them has some code from
jFuzzyLogic.
Programming language. This is an indicator of code
portability. There languages of choice were mainly Java
and C++/C (column Lang.). Java being platform independent has the advantage of portability. C++ has an
advantage in speed, but also allows easier integration in
industrial controllers.
Functionality. Seven packages ( 29%) were made for
specific purposes, marked as specific (column Notes,
Table I). Specific code usually has limited functionality,
but it is simpler and has a faster learning curve for the
user.
Membership functions. This is an indicator of how comprehensive and flexible the package is. Specific packages
include only one membership function (typically trapezoid) and/or one defuzzification method (data not shown).
In some cases, arbitrary combinations of membership
functions are possible. These packages are marked with
asterisk. For example, M + N means that the software
supports M membership functions plus another N which
can be arbitrarily combined.
Latest release. In eight cases ( 33%) there were no
released files for the last three years or more (see Rel.
column in the Table I). This may indicate that the package
is no longer maintained, and in some cases the web site
explicitly mentions this.
Code availability and usability. Five of the packages (
21%) had no files available, either because the project
was no longer maintained or because the project never
released any files at all. Whenever the original sites were
down, we tried to retrieve the projects from alternative
mirrors. In three cases ( 13%) the packages did not
compile. We performed minimal testing by just following
the instructions, if available, and make no effort to correct
any compilation problems.
The specification defines six programming languages: Instruction list (IL), Structured text (ST), Ladder diagram (LD),
Function block diagram (FBD), Sequential function chart
(SFC), and Fuzzy Control Language (FCL). While IL, ST,
and FCL are text based languages, LD, FBD and SFC are
graphic based languages.
Instruction list is similar to assembly language: one instruction per line, low level and low expression commands.
Structured text, as the name suggests, intends to be more
structured and it is very easy to learn and understand for
anyone with a modest experience in programming. The focus
of this work is FCL, which is oriented to fuzzy logic based
control systems and its syntax is similar to ST.
A. IEC Language concepts
All IEC-61131 languages are modular. The basic module is
called Programmable Organization Unit (POU) and includes
Programs, Functions or Function Blocks. A system is usually
composed of many POUs, and each of these POUs can
be programmed in a different language. For instance, in a
system consisting of two functions and one function block
(three POUs), one function may be programed in LD, another
function in IL and the function block may be programmed in
ST. The norm defines all common data types (e.g. BOOL,
REAL, INT, ARRAY, STRUCT, etc.) as well as ways to
interconnect POUs, assign process execution priorities, process
timers, CPU resource assignment, etc.
The concepts of a Program and Functions are quite intuitive.
Programs are simple set of statements and variables. Functions
are calculations that can return only one value and are not
supposed to have state variables.
A Function Block resembles a very primitive object. It
can have multiple input and multiple output variables, can be
enabled by an external signal, and can have local variables.
Unlike an object, a function block only has one execution
block (i.e. there are no methods). The underlying idea for these
limitations is that you should be able to implement programs
using either text-based or graphic-based languages. Having
only one execution block, allows to easily control execution
when using graphic-based language to interconnect POUs.
At first glance FCL is similar to ST. However, there are
some very important differences. FCL uses exclusively a new
POU type: Fuzzy Inference System (FIS) which is a special
case of a Function Block. All fuzzy language definitions
should be within a FIS. Since a fuzzy system is inherently
parallel, there is no concept of execution order, therefore there
are no statements. For instance, there is no way to create
the typical Hello world example since there is no print
statement. A simple example of a FIS using FCL is shown
in Table II, this FCL code calculates the tip in a restaurant
(the equivalent of a Hello world program in fuzzy systems).
Fig. 1 shows the membership functions.
Table III shows the corresponding Java code to run the FCL
code shown in Table II.
TABLE I
C OMPARISSON ON OPEN FUZZY LOGIC SOFTWARE PACKAGES . C OLUMNS DESCRIBE : P ROJECT NAME (NAME ), IEC 61131-7 LANGUAGE SUPPORT (IEC),
LATEST RELEASE YEAR (R EL .), MAIN PROGRAMMING LANGUAGE (L ANG .), SHORT DESCRIPTION FORM WEBSITE (D ESCRIPTION ), NUMBER OF
MEMBERSHIP FUNCTIONS SUPPORTED (MF) AND F UNCTIONALITY ( NOTES ). NAME : PACKAGE IS MAINTAINED , COMPILES CORRECTLY, AND HAS
EXTENSIVE FUNCTIONALITY.
Name
IEC
Rel.
Lang.
Akira
AwiFuzz
DotFuzzy
FFLL
Fispro
FLUtE
FOOL
FRBS
funzy
Fuzzy Logic Tools
FuzzyBlackBox
FuzzyClips
FuzzyJ ToolKit
FuzzyPLC
GUAJE
javafuzzylogicctrltool
JFCM
JFuzzinator
jFuzzyLogic
jFuzzyQt
libai
libFuzzyEngine
nxtfuzzylogic
Octave FLT
XFuzzy3
No
Yes
No
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
Yes
Yes
No
No
No
No
No
2007
2008
2009
2003
2010
2004
2002
2011
2007
2011
2004
2006
2011
2011
2011
2010
2011
2011
2010
2010
2010
2011
2003
C++
C++
C#
C++
C++/Java
C#
C
C++
Java
C++
C/Lisp
Java
Java
Java
Java
Java
Java
Java
C++
Java
C++
Java
Octave
Java
Fig. 1.
Description
MF
B. jFuzzyLogic Implementation
jFuzzyLogic is fully implemented in Java, thus the package
is platform independent. ANTLR [17] was used to generate
Java code for a lexer and parser based on our FCL grammar
definition. This generated parser uses a left to right leftmost
derivation recursive strategy, formally know as LL(*).
Using the lexer and parser created by ANTLR we are able to
parse FCL files by creating an Abstract Syntax Tree (AST), a
well known structure in compiler design. The AST is converted
into an Interpreter Syntax Tree (IST), which is capable of
4
2
1
4
6
1
5
1
2
12
3 + 2
15
11 + 14
2
11 + 14
8
3
1
1
11
6
Notes
Does not compile
Specific
Does not compile
Beta version
Does not compile
Specific
Specific
No files released
No longer maintained
No longer maintained
Uses jFuzzyLogic
Uses FisPro
No files released
Specific
Specific
This paper
Specific
Specific
Specific
Implements XFL3 specification language
TABLE II
E XAMPLE OF F UZZY CONTROL LANGUAGE (FCL) CODE .
FUNCTION_BLOCK tipper
VAR_INPUT
service, food : REAL;
END_VAR
VAR_OUTPUT
tip : REAL;
END_VAR
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
FUZZIFY food
TERM rancid := (0, 1) (1, 1) (3,0);
TERM delicious := (7,0) (9,1);
END_FUZZIFY
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);
METHOD : COG;
// Center of Gravity
END_DEFUZZIFY
RULEBLOCK tipRules
Rule1: IF service IS poor OR food IS rancid THEN tip IS cheap;
Rule2: IF service IS good THEN tip IS average;
Rule3: IF service IS excellent AND food IS delicious THEN tip IS generous;
END_RULEBLOCK
END_FUNCTION_BLOCK
TABLE III
E XAMPLE OF JAVA API TO EXECUTE FCL CODE .
public class TestTipper {
public static void main(String[] args)
throws Exception {
FIS fis = FIS.load("fcl/tipper.fcl", true);
FunctionBlock fb = fis.getFunctionBlock(null);
// Set inputs
fb.setVariable("service", 3);
fb.setVariable("food", 7);
// Evaluate
fb.evaluate();
// Get output
double tip = fb.getVariable("tip").getValue());
}
}
Sum.
Fig. 2.
to the precision-speed trade-off required for a particular application. Inference is performed by evaluating membership
functions at these discretization points. In order to perform
a discretization, the universe for each variable, has to be
estimated. The universe is defined as the range where the
variable has non-neglectable value. For each variable, each
membership function and each term is taken into account when
calculating a universe. Once all rules have been analyzed, the
accumulation for each variable is complete.
The last step when evaluating a FIS is defuzzification.
The value for each variable is calculated using the selected
defuzzification method, which can be Center of gravity,
Rightmost Max, Center of area, Leftmost Max, Mean
max (continuous membership functions), or Center of gravity (discrete membership functions).
C. API extensions
Some of the extensions and benefits provided by jFuzzyLogic are described in this section.
Modularity. Modular design allows to extend the language
and the API easily. It is possible to add custom aggregation,
activation or accumulation methods, defuzzifiers, or membership functions by extending the provided object tree.
Dynamic changes. Our API supports dynamic changes made
onto a fuzzy inference system: i) variables can be used as
membership function parameters; ii) rules can be added or
deleted from rule blocks, iii) rule weights can be modified;
iv) membership functions can use combinations of pre-defined
functions.
Optimization API. An optimization API is available, allowing fine tuning membership function rules and rule weights. A
few optimization algorithms are already implemented, such as
gradient descent, partial derivative, and delta algorithm. Other
optimization algorithms can be implemented based on these
templates.
Data Types. Due to the nature of fuzzy systems and in order
to reduce complexity, jFuzzyLogic considers each variable as
REAL variable which is mapped to a double Java type.
Excecution order. By default it is assumed that a FIS is
composed of only one Function Block, so evaluating the FIS
means evaluating the default FB. If a FIS has more than one
FB, they are evaluated in alphabetical order by FB name. Other
Fig. 4.
TABLE IV
WALL FOLLOWING ROBOT: F UZZY CONTROLLER IN FCL LANGUAGE : VARIABLE DEFINITIONS .
VAR_INPUT
rd : REAL;
dq : REAL;
o : REAL;
v : REAL;
END_VAR
//
//
//
//
VAR_OUTPUT
la : REAL;
av : REAL;
END_VAR
// Linear acceleration
// Angular velocity
FUZZIFY rd
TERM L :=
TERM M :=
TERM H :=
TERM VH :=
END_FUZZIFY
trian
trian
trian
trian
0
0
1
2
Right distance
Distance quotient
Orientation. Note: or is a reserved word
Velocity
0
1
2
3
1;
2;
3;
3;
FUZZIFY dq
TERM L := trian 0 0 2;
TERM H := trian 0 2 2;
END_FUZZIFY
FUZZIFY o
TERM HL :=
TERM LL :=
TERM Z :=
TERM LR :=
TERM HR :=
END_FUZZIFY
trian
trian
trian
trian
trian
FUZZIFY v
TERM L := trian 0 0 1;
TERM H := trian 0 1 1;
END_FUZZIFY
DEFUZZIFY la
TERM VHB := trian
TERM HB := trian
TERM MB := trian
TERM SB := trian
TERM Z
:= trian
TERM SA := trian
TERM MA := trian
TERM HA := trian
TERM VHA := trian
METHOD : COG;
DEFAULT := 0;
END_DEFUZZIFY
DEFUZZIFY av
TERM VHR := trian
TERM HR := trian
TERM MR := trian
TERM SR := trian
TERM Z
:= trian
TERM SL := trian
TERM ML := trian
TERM HL := trian
TERM VHL := trian
METHOD : COG;
DEFAULT := 0;
END_DEFUZZIFY
-1 -1 -0.75;
-1 -0.75 -0.5;
-0.75 -0.5 -0.25;
-0.5 -0.25 0;
-0.25 0 0.25;
0 0.25 0.5;
0.25 0.5 0.75;
0.5 0.75 1;
0.75 1 1;
// Center of Gravity
-1 -1 -0.75;
-1 -0.75 -0.5;
-0.75 -0.5 -0.25;
-0.5 -0.25 0;
-0.25 0 0.25;
0 0.25 0.5;
0.25 0.5 0.75;
0.5 0.75 1;
0.75 1 1;
TABLE V
WALL FOLLOWING ROBOT. F UZZY CONTROLLER IN FCL LANGUAGE : RULE BLOCK .
RULEBLOCK rules
AND : MIN;
ACT : MIN;
ACCU : MAX;
RULE 01:
RULE 02:
RULE 03:
RULE 04:
RULE 05:
RULE 06:
RULE 07:
RULE 08:
RULE 09:
RULE 10:
RULE 11:
RULE 12:
RULE 13:
RULE 14:
RULE 15:
RULE 16:
RULE 17:
RULE 18:
RULE 19:
RULE 20:
RULE 21:
RULE 22:
RULE 23:
RULE 24:
RULE 25:
RULE 26:
RULE 27:
RULE 28:
RULE 29:
RULE 30:
RULE 31:
RULE 32:
RULE 33:
RULE 34:
RULE 35:
RULE 36:
RULE 37:
RULE 38:
RULE 39:
RULE 40:
RULE 41:
END_RULEBLOCK
// Use min for and (also implicit use max for or to fulfill DeMorgans Law)
// Use min activation method
// Use max accumulation method
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
IF
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
rd
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
L
L
L
L
L
L
L
L
L
M
M
M
M
M
M
M
M
M
M
M
M
H
H
H
H
H
H
H
H
H
H
H
H
H
VH
VH
VH
VH
VH
VH
VH
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
dq
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
L
L
L
L
H
H
H
H
H
L
L
L
L
H
H
H
H
H
H
H
H
L
L
L
L
H
H
H
H
H
H
H
H
H
L
L
L
H
H
H
H
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
LL
LL
Z
Z
LL
Z
Z
LR
HR
Z
LR
HR
HR
HL
HL
LL
Z
LR
LR
HR
HR
Z
LR
HR
HR
HL
HL
LL
Z
Z
LR
LR
HR
HR
LR
HR
HR
LL
LR
LR
HR
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
L
H
L
H
L
L
H
H
L
H
H
L
H
L
H
H
L
L
H
L
H
L
H
L
H
L
H
L
L
H
L
H
L
H
L
L
H
L
L
H
L
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
THEN
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
VHB
VHB
Z
HB
MA
MA
HB
VHB
VHB
SA
Z
SA
MB
Z
VHB
SA
HA
HA
SA
Z
VHB
HA
SA
HA
SA
VHB
VHB
HA
HA
SA
HA
SA
HA
SA
HA
HA
SA
HA
HA
SA
HA
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
av
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
is
VHR
VHR
MR
SR
HR
HL
ML
VHL
VHL
HR
VHL
HL
VHL
VHR
VHR
VHR
Z
VHL
VHL
VHL
VHL
VHR
MR
VHL
HL
VHR
VHR
VHR
VHR
VHR
MR
MR
HL
VHL
VHR
HR
HR
VHR
VHR
VHR
HR
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
with
0.4610;
0.4896;
0.6664;
0.5435;
0.7276;
0.4845;
0.5023;
0.7363;
0.9441;
0.3402;
0.4244;
0.5472;
0.4369;
0.1770;
0.4526;
0.2548;
0.2084;
0.6242;
0.3779;
0.6931;
0.7580;
0.5758;
0.2513;
0.5471;
0.5595;
0.9999;
0.9563;
0.9506;
0.4529;
0.2210;
0.3612;
0.2122;
0.7878;
0.3859;
0.5530;
0.4223;
0.3854;
0.0936;
0.7325;
0.5631;
0.5146;