Jfuzzylite
jfuzzylite: a fuzzy logic control library in Java
Install / Use
/learn @fuzzylite/JfuzzyliteREADME
jfuzzylite™ 6.0
<img src="https://raw.githubusercontent.com/fuzzylite/jfuzzylite/master/jfuzzylite.png" align="right" alt="jfuzzylite">A Fuzzy Logic Control Library in Java
By: Juan Rada-Vilela, Ph.D.
Released: 20/March/2017
Table of Contents
License <br/> Introduction<br/> Features<br/> Example <br/> Compile, Link, and Execute<br/> Bulding from Source<br/> Binaries <br/> What's new<br/> What's next <br/>
<a name="license">License</a>
jfuzzylite 6.0 is licensed under the GNU General Public License (GPL) 3.0. You are strongly encouraged to support the development of the FuzzyLite Libraries by purchasing a license of QtFuzzyLite 6.
QtFuzzyLite 6 is the new and (very likely) 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 www.fuzzylite.com/downloads/.
<a name="introduction">Introduction</a>
jfuzzylite is a free and open-source fuzzy logic control library programmed in Java for multiple platforms (e.g., Windows, Linux, Mac, Android). fuzzylite is the equivalent library written in C++ for Windows, Linux, Mac, iOS, and others. Together, they are the FuzzyLite Libraries for Fuzzy Logic Control.
Reference
If you are using the FuzzyLite Libraries, please cite the following reference in your article:
Juan Rada-Vilela. fuzzylite: a fuzzy logic control library, 2017. URL http://www.fuzzylite.com/.
@misc{fl::fuzzylite,
author={Juan Rada-Vilela},
title={fuzzylite: a fuzzy logic control library},
url={http://www.fuzzylite.com/},
year={2017}}
Documentation
The documentation for the fuzzylite library is available at: www.fuzzylite.com/documentation/.
<a name="features">Features</a>
(6) Controllers: Mamdani, Takagi-Sugeno, Larsen, Tsukamoto, Inverse Tsukamoto, Hybrids
(21) Linguistic terms: (4) Basic: triangle, trapezoid, rectangle, discrete. (9) Extended: bell, cosine, gaussian, gaussian product, pi-shape, sigmoid difference, sigmoid product, spike. (5) Edges: binary, concave, ramp, sigmoid, s-shape, z-shape. (3) Functions: constant, linear, function.
(7) Activation methods: general, proportional, threshold, first, last, lowest, highest.
(8) Conjunction and Implication (T-Norms): minimum, algebraic product, bounded difference, drastic product, einstein product, hamacher product, nilpotent minimum, function.
(10) Disjunction and Aggregation (S-Norms): maximum, algebraic sum, bounded sum, drastic sum, einstein sum, hamacher sum, nilpotent maximum, normalized sum, unbounded sum, function.
(7) Defuzzifiers: (5) Integral: centroid, bisector, smallest of maximum, largest of maximum, mean of maximum. (2) Weighted: weighted average, weighted sum.
(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.java
import com.fuzzylite.*;
public class Example {
public static void main(String[] args){
Engine engine = new FllImporter().fromFile("ObstacleAvoidance.fll");
StringBuilder status = new StringBuilder();
if (! engine.isReady(status))
throw new RuntimeException("[engine error] engine is not ready:\n" + status);
InputVariable obstacle = engine.getInputVariable("obstacle");
OutputVariable steer = engine.getOutputVariable("mSteer");
for (int i = 0; i <= 50; ++i){
double location = obstacle.getMinimum() + i * (obstacle.range() / 50);
obstacle.setValue(location);
engine.process();
FuzzyLite.logger().info(String.format(
"obstacle.input = %s -> steer.output = %s",
Op.str(location), Op.str(steer.getValue())));
}
}
}
Java
//File: ObstacleAvoidance.java
import com.fuzzylite.*;
public class Example {
public static void main(String[] args){
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(Double.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(null);
mamdani.setDisjunction(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);
StringBuilder status = new StringBuilder();
if (! engine.isReady(status))
throw new RuntimeException("[engine error] engine is not ready:\n" + status);
InputVariable obstacle = engine.getInputVariable("obstacle");
OutputVariable steer = engine.getOutputVariable("mSteer");
for (int i = 0; i <= 50; ++i){
double location = obstacle.getMinimum() + i * (obstacle.range() / 50);
obstacle.setValue(location);
engine.process();
FuzzyLite.logger().info(String.format(
"obstacle.input = %s -> steer.output = %s",
Op.str(location), Op.str(steer.getValue())));
}
}
}
<a name="building">Building from Source</a>
Building from source requires you to have either Maven or Ant installed.
Maven (preferred)
$ mvn install
The Maven script will create the library target/jfuzzylite-6.0.jar and the source code target/jfuzzylite-6.0-sources.jar.
Ant
$ ant -f build.xml
The Ant script will create the library target/jfuzzylite-6.0.jar and the source code target/jfuzzylite-6.0-sources.jar.
Documentation
The source code of jfuzzylite is very well documented using doxygen formatting, and the documentation is available at fuzzylite.com/documentation. If you want to generate the documentation locally, you can produce the html documentation from the file Doxyfile using the command line: doxygen Doxyfile. The documentation will be created in the documentation folder.
<a name="binaries">Binaries</a>
The console application of jfuzzylite allows you to import and export your engines. Its usage can be obtained executing the console binary. In addit
