A fuzzy logic C++ library
File Storage


In order to save and recall the FIS parameters, SLIFIS::Read() and SLIFIS::Write() are provided.


The Write() function saves all the parameters (set of membership functions, input and output, and rules) into a file whose name is given as argument. Data can be saved into several formats, at present these are:

Writing to file is as simple as this (you should use for "ext" the appropriate extension, "xml", "fcl" or "fis" for binary format. On failure, it will throw an error (see Error handling).

fis.Write( "MyFile.ext" );

Reading from file is achieved with this:

Read( "MyFis.ext" );

If you want to catch errors on reading, then the code will become:

        Read( "MyFis.ext" );
catch( std::exception const& e )
        cout << "unable to read file, msg:" << e.what();

To select the format, just call the static function SLIFIS::SetDefaultIO() with one of the values in slifis::EN_FF_TYPE, as in the following example:

Additional information:

XML format

XML I/O is achieved using the additional tinyxml library, currently. It is included in source tree, but user can disable XML support at build time using an appropriate flag when calling makefile (see Build options).

See below an example of generated xml file:

<?xml version="1.0" ?>
<slifis lib_version="0.7.1">
    <date>Wed May 22 23:51:53 2013&#x0A;</date>
    <infer_params DefuzzMethod="0" ImplicationMethod="0" OutputAggregation="0" RuleAndMethod="0" RuleOrMethod="0" />
    <input_sets nb_inputs="2">
        <mf_set name="service" nb_mf="3">
            <mf name="poor" nb_pts="2">
                <pt x="0" y="1" />
                <pt x="3" y="0" />
            <mf name="good" nb_pts="4">
                <pt x="0" y="0" />
                <pt x="3" y="1" />
                <pt x="7" y="1" />
                <pt x="10" y="0" />
            <mf name="excellent" nb_pts="2">
                <pt x="7" y="0" />
                <pt x="10" y="1" />
        <mf_set name="food" nb_mf="2">
            <mf name="rancid" nb_pts="2">
                <pt x="0" y="1" />
                <pt x="10" y="0" />
            <mf name="delicious" nb_pts="2">
                <pt x="0" y="0" />
                <pt x="10" y="1" />
        <mf_set name="tip" nb_mf="3">
            <mf name="cheap" nb_pts="3">
                <pt x="0" y="0" />
                <pt x="0.05" y="1" />
                <pt x="0.15" y="0" />
            <mf name="average" nb_pts="3">
                <pt x="0.05" y="0" />
                <pt x="0.15" y="1" />
                <pt x="0.25" y="0" />
            <mf name="generous" nb_pts="3">
                <pt x="0.15" y="0" />
                <pt x="0.25" y="1" />
                <pt x="0.3" y="0" />
    <rule_base nb_rules="3">
        <rule type="MAMDANI" operation="OR" nb_terms="2" degree="1" output="0">
            <term input="0" value="0" />
            <term input="1" value="0" />
        <rule type="MAMDANI" operation="OR" nb_terms="1" degree="1" output="1">
            <term input="0" value="1" />
        <rule type="MAMDANI" operation="OR" nb_terms="2" degree="1" output="2">
            <term input="0" value="2" />
            <term input="1" value="1" />

FCL format

Slifis can export the fis in the FCL format. Importing is planned in further release. For additional information on FCL format, please see:

See below an example of a produced FCL file (build-time generated, if nothing below, please rebuild with 'make-test', and/or check Building the software).

-- FCL definition file (IEC 61131-7)
-- This file was generated by the SLIFIS libray, version 0.7.1, on Wed May 22 23:51:53 2013

    temperature:        REAL;
    pressure:   REAL;
    output: REAL;
FUZZIFY temperature
    TERM Cold := (0,1) (26.6667,0) ;
    TERM Warm := (0,0) (26.6667,1) (53.3333,0) ;
    TERM Hot := (26.6667,0) (53.3333,1) (80,0) ;
    TERM Too hot := (53.3333,0) (80,1) ;
FUZZIFY pressure
    TERM Low := (0,1) (0.5,0) ;
    TERM Fine := (0,0) (0.5,1) (1,0) ;
    TERM High := (0.5,0) (1,1) ;
        Very Bad := (0,0) (0.25,1) (0.5,0) 
        Bad := (0.25,0) (0.5,1) (0.75,0) 
        Good := (0.5,0) (0.75,1) (1,0) 
        METHOD : COG;
        DEFAULT := 0;
        AND : MIN
        RULE  1 : IF temperature IS Cold THEN output IS Very Bad;
        RULE  2 : IF temperature IS Hot THEN output IS Bad;
        RULE  3 : IF temperature IS Too hot THEN output IS Very Bad;
        RULE  4 : IF pressure IS Low THEN output IS Bad;
        RULE  5 : IF pressure IS High THEN output IS Bad;
        RULE  6 : IF temperature IS Warm AND pressure IS Fine THEN output IS Good;
-- (eof)