Fuzzylite
fuzzylite: a fuzzy logic control library in C++
Install / Use
/learn @fuzzylite/FuzzyliteREADME
by <a href="https://fuzzylite.com/about"><b>Juan Rada-Vilela, PhD</b></a>
</div><a name="fuzzylite">FuzzyLite</a>
The FuzzyLite Libraries for Fuzzy Logic Control refer to fuzzylite
(C++), pyfuzzylite (Python),
and jfuzzylite (Java).
The goal of the FuzzyLite Libraries is to easily design and efficiently operate fuzzy logic controllers following an object-oriented programming model with minimal dependency on external libraries.
<a name="license">License</a>
fuzzylite is dual-licensed under the GNU GPL 3.0 and under a
proprietary license for commercial purposes.
You are strongly encouraged to support the development of the FuzzyLite Libraries by purchasing a license
of QtFuzzyLite.
QtFuzzyLite is the best graphical user interface available to easily design and
directly operate fuzzy logic controllers in real time. Available for Windows, Mac, and Linux, its goal is to
significantly speed up the design of your fuzzy logic controllers, while providing a very useful, functional
and beautiful user interface.
Please, download it and check it out for free at fuzzylite.com/downloads.
<a name="documentation">Documentation</a>
Visit fuzzylite.com/documentation
<a name="features">Features</a>
(6) Controllers: Mamdani, Takagi-Sugeno, Larsen, Tsukamoto, Inverse Tsukamoto, Hybrid
(25) Linguistic terms: (5) Basic: Triangle, Trapezoid, Rectangle, Discrete, SemiEllipse. (8) Extended: Bell, Cosine, Gaussian, GaussianProduct, PiShape, SigmoidDifference, SigmoidProduct, Spike. (7) Edges: Arc, Binary, Concave, Ramp, Sigmoid, SShape, ZShape. (3) Functions: Constant, Linear, Function. (2) Special: Aggregated, Activated.
(7) Activation methods: General, Proportional, Threshold, First, Last, Lowest, Highest.
(9) Conjunction and Implication (T-Norms): Minimum, AlgebraicProduct, BoundedDifference, DrasticProduct, EinsteinProduct, HamacherProduct, NilpotentMinimum, LambdaNorm, FunctionNorm.
(11) Disjunction and Aggregation (S-Norms): Maximum, AlgebraicSum, BoundedSum, DrasticSum, EinsteinSum, HamacherSum, NilpotentMaximum, NormalizedSum, UnboundedSum, LambdaNorm, FunctionNorm.
(7) Defuzzifiers: (5) Integral: Centroid, Bisector, SmallestOfMaximum, LargestOfMaximum, MeanOfMaximum. (2) Weighted: WeightedAverage, WeightedSum.
(7) Hedges: Any, Not, Extremely, Seldom, Somewhat, Very, Function.
(3) Importers: FuzzyLite Language fll, Fuzzy Inference System fis, Fuzzy Control Language fcl.
(7) Exporters: C++, Java, FuzzyLite Language fll, FuzzyLite Dataset fld, R script, Fuzzy Inference
System fis, Fuzzy Control Language fcl.
(30+) Examples of Mamdani, Takagi-Sugeno, Tsukamoto, and Hybrid controllers from fuzzylite, Octave, and Matlab,
each included in the following formats: C++, Java, fll, fld, R, fis, and fcl.
<a name="example">Example</a>
FuzzyLite Language
#File: ObstacleAvoidance.fll
Engine: ObstacleAvoidance
InputVariable: obstacle
enabled: true
range: 0.000 1.000
lock-range: false
term: left Ramp 1.000 0.000
term: right Ramp 0.000 1.000
OutputVariable: mSteer
enabled: true
range: 0.000 1.000
lock-range: false
aggregation: Maximum
defuzzifier: Centroid 100
default: nan
lock-previous: false
term: left Ramp 1.000 0.000
term: right Ramp 0.000 1.000
RuleBlock: mamdani
enabled: true
conjunction: none
disjunction: none
implication: AlgebraicProduct
activation: General
rule: if obstacle is left then mSteer is right
rule: if obstacle is right then mSteer is left
//File: ObstacleAvoidance.cpp
#include <fl/Headers.h>
fl::Engine* engine = fl::FllImporter().fromFile("ObstacleAvoidance.fll");
C++
//File: ObstacleAvoidance.cpp
#include <fl/Headers.h>
using namespace fuzzylite;
Engine* engine = new Engine;
engine->setName("ObstacleAvoidance");
engine->setDescription("");
InputVariable* obstacle = new InputVariable;
obstacle->setName("obstacle");
obstacle->setDescription("");
obstacle->setEnabled(true);
obstacle->setRange(0.000, 1.000);
obstacle->setLockValueInRange(false);
obstacle->addTerm(new Ramp("left", 1.000, 0.000));
obstacle->addTerm(new Ramp("right", 0.000, 1.000));
engine->addInputVariable(obstacle);
OutputVariable* mSteer = new OutputVariable;
mSteer->setName("mSteer");
mSteer->setDescription("");
mSteer->setEnabled(true);
mSteer->setRange(0.000, 1.000);
mSteer->setLockValueInRange(false);
mSteer->setAggregation(new Maximum);
mSteer->setDefuzzifier(new Centroid(100));
mSteer->setDefaultValue(fl::nan);
mSteer->setLockPreviousValue(false);
mSteer->addTerm(new Ramp("left", 1.000, 0.000));
mSteer->addTerm(new Ramp("right", 0.000, 1.000));
engine->addOutputVariable(mSteer);
RuleBlock* mamdani = new RuleBlock;
mamdani->setName("mamdani");
mamdani->setDescription("");
mamdani->setEnabled(true);
mamdani->setConjunction(fl::null);
mamdani->setDisjunction(fl::null);
mamdani->setImplication(new AlgebraicProduct);
mamdani->setActivation(new General);
mamdani->addRule(Rule::parse("if obstacle is left then mSteer is right", engine));
mamdani->addRule(Rule::parse("if obstacle is right then mSteer is left", engine));
engine->addRuleBlock(mamdani);
<a name="operation">Operation</a>
using namespace fuzzylite;
std::string status;
if (not engine->isReady(&status))
throw Exception("[engine error] engine is not ready:\n" + status, FL_AT);
InputVariable* obstacle = engine->getInputVariable("obstacle");
OutputVariable* steer = engine->getOutputVariable("steer");
for (int i = 0; i <= 50; ++i){
scalar location = obstacle->getMinimum() + i * (obstacle->range() / 50);
obstacle->setValue(location);
engine->process();
FL_LOG("obstacle.input = " << Op::str(location) <<
" => " << "steer.output = " << Op::str(steer->getValue()));
}
<a name="compile-build-execute">Compile, Link, and Execute</a>
Once you have an engine written in C++, you can compile it to create an executable file which links to the fuzzylite
library. The linking can be either static or dynamic. Basically, the differences between static and dynamic linking are
the following.
Static linking includes the fuzzylite library into your executable file, hence increasing its size, but the
executable no longer needs to have access to the fuzzylite library files.
Dynamic linking does not include the fuzzylite library into your executable file, hence reducing its size, but the
executable needs to have access to the fuzzylite shared library file. When using dynamic linking, make sure that the
shared library files are either in the same directory as the executable, or are reachable via environmental variables:
rem Windows:
set PATH="\path\to\fuzzylite\release\bin;%PATH%"
#Unix:
export LD_LIBRARY_PATH="/path/to/fuzzylite/release/bin/:$LD_LIBRARY_PATH"
Windows
The commands to compile your engine in Windows are the following:
C++11 (default)
rem static linking:
cl.exe ObstacleAvoidance.cpp fuzzylite-static.lib /Ipath/to/fuzzylite /EHsc /MD
rem dynamic linking:
cl.exe ObstacleAvoidance.cpp fuzzylite.lib /Ipath/to/fuzzylite /DFL_IMPORT_LIBRARY /EHsc /MD
C++98
rem static linking:
cl.exe ObstacleAvoidance.cpp fuzzylite-static.lib /Ipath/to/fuzzylite /DFL_CPP98=ON /EHsc /MD
rem dynamic linking:
cl.exe ObstacleAvoidance.cpp fuzzylite.lib /Ipath/to/fuzzylite /DFL_IMPORT_LIBRARY /DFL_CPP98=ON /EHsc /MD
Unix
The commands to compile your engine in Unix are the following:
C++11 (default)
#static linking
g++ ObstacleAvoidance.cpp -o ObstacleAvoidance -I/path/to/fuzzylite -L/path/to/fuzzylite/release/bin -lfuzzylite-static --std=c++11
#dynamic linking
g++ ObstacleAvoidance.cpp -o ObstacleAvoidance -I/path/to/fuzzylite -L/path/to/fuzzylite/release/bin -lfuzzylite
C++98
#static linking
g+
