I wrote this library in order to understand Fuzzy Logic. It mainly implements the draft version of the IEC 1131-7 Fuzzy Control Programming paper. It took me the evening and weekend hours of about one month to implement.

What was implemented:
  • The Fuzzy Control Language up to second (Extension) level, except for the items in the next section.
  • Fuzzy (Linguistic) Variables
  • Piecewise linear sets (triangular, trapezoidal, etc.) and singleton sets. It is possible to use variables in set definitions. It is possible to create any set with the piecewise linear sets.
  • Fuzzification and Defuzzification. I implemented the COG, COGS, MOM, RM and LM defuzzification methods. Default values and ranges are supported.
  • Operator definitions: MAX/MIN, ASUM/PROD, and BSUM/BDIF.
  • Activation methods: PROD and MIN.
  • Accumulation methods: Only MAX.
  • Rules: All FCL expressions are possible, including compound expressions (i.e. A IS S1 OR NOT (B IS S2)), expressions with the 'NOT' within: A IS NOT B, the weighting factor WITH, and multiple subconclusions.
What was not implemented:
  • The COA defuzzification method; because it proved too complicated for me.
  • The BSUM and NSUM accumulation methods: because I have no idea how they should be implemented (with regard to the defuzzification process that follows it) and I am not even sure what they should do exactly
  • The OPTIONS / END_OPTIONS block: no idea what their syntax should be
Remarks

I haven't used Fuzzy Logic yet, but I do have some things to say about it.

  • Apparently it is used mainly for microcontrollers and such devices and to a much lesser degree in games and large scale applications. That surprised me.
  • Fuzzy Logic provides a great way to combine the results of several conflicting production rules. What I miss however, is some factor you can use to specify the importance of a rule. At this time all rules seem to be of the same importance, and I suppose that can be a nuisance.
  • I have only seen the draft version of the FCL specification, but I noticed that the accumulation of the results of different ruleblocks is not defined. If several ruleblocks use different methods of accumulation, which method is used to accumulate all result sets that are created in the execution of the rules.
Sample use
// Create a Fuzzy Logic Model (the container for all parts)
CFuzzyModel Model;

// Load some fcl file to fill the model
Model.Load("files/example.fcl");

// set the contents of the input variables
Model.GetVariable("Our_Health")->SetValue(25);
Model.GetVariable("Enemy_Health")->SetValue(75);

// calculate the new value of the output variables
Model.Update();

// Print the output variable's value
float Crisp = Model.GetVariable("Aggressiveness")->GetValue();
printf("agressiveness: %f \n", Crisp);
                
Links

Somehow all these sites only provide part of the puzzle. And even with all the pieces, there still remain some (excusez) fuzzy areas.

  • IEC 1131-7 Fuzzy Control Programming The "Committee Draft" of the official FCL specification by the IEC. The final version costs somewhat over 100 euro's.
  • Free Fuzzy Logic Library A C++ Fuzzy Logic implementation which has been a great inspiration to me, although I have done the implementation completely different. I hope this Michael Zarozinski dude will find the time to finish his library, because it still misses some important parts.
  • FuzzyJ ToolKit A Java Fuzzy Logic implementation.
  • Lotfi A. Zadeh, the inventor of Fuzzy Logic.
  • Fuzzy Logic FAQ Fuzzy Logic and Fuzzy Expert Systems 1/1 FAQ.
  • The Fuzzly Logic usegroup I haven't really looked at it yet.