home Forums # Technical Support Problem with importing and getting results

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1641
    Unknown
    Member

    Hi Juan,

    Thanks for your great toolbox. I wanted to use your toolbox in my project. I used following codes, but every time I get “nan”as a result. Would you please help me out?

    Cheers
    Mohammad

    FUNCTION_BLOCK Backoff

    VAR_INPUT
    NBRate: REAL;
    Datarate: REAL;
    END_VAR

    VAR_OUTPUT
    BE: REAL;
    END_VAR

    FUZZIFY NBRate
    RANGE := (-0.100 .. 6.000);
    TERM low := Triangle -0.100 0.000 0.200;
    TERM medium := Triangle 0.000 0.750 1.500;
    TERM mediumhigh := Triangle 0.750 1.500 2.750;
    TERM high := Triangle 2.000 5.000 6.000;
    END_FUZZIFY

    FUZZIFY Datarate
    RANGE := (0.000 .. 102.000);
    TERM low := Triangle 0.000 1.600 3.200;
    TERM medium := Triangle 1.600 24.000 50.000;
    TERM mediumhigh := Triangle 24.000 50.000 80.000;
    TERM high := Triangle 50.00 100.000 102.000;
    END_FUZZIFY

    DEFUZZIFY BE
    RANGE := (1.000 .. 9.000);
    TERM d1 := Triangle 1.000 2.010 2.500;
    TERM d2 := Triangle 2.000 2.510 3.000;
    TERM d3 := Triangle 2.000 3.010 4.000;
    TERM d4 := Triangle 3.000 4.010 5.000;
    TERM d5 := Triangle 5.000 6.010 7.000;
    TERM d6 := Triangle 6.000 7.010 8.000;
    TERM d7 := Triangle 7.000 8.010 9.000;
    METHOD : COG;
    ACCU : MAX;
    DEFAULT := nan;
    END_DEFUZZIFY

    RULEBLOCK
    AND : MIN;
    OR : MAX;
    ACT : MIN;
    RULE 1 : is NBRate is low AND Datarate is low then BE is d2;
    RULE 2 : if NBRate is low AND Datarate is medium then BE is d2;
    RULE 3 : if NBRate is low AND Datarate is mediumhigh then BE is d2;
    RULE 4 : if NBRate is low AND Datarate is high then BE is d2;
    RULE 5 : if NBRate is medium AND Datarate is low then BE is d3;
    RULE 6 : if NBRate is medium AND Datarate is medium then BE is d3;
    RULE 7 : if NBRate is medium AND Datarate is mediumhigh then BE is d3;
    RULE 8 : if NBRate is medium AND Datarate is high then BE is d4;
    RULE 9 : if NBRate is mediumhigh AND Datarate is low then BE is d4;
    RULE 10 : if NBRate is mediumhigh AND Datarate is medium then BE is d4;
    RULE 11 : if NBRate is mediumhigh AND Datarate is mediumhigh then BE is d4;
    RULE 12 : if NBRate is mediumhigh AND Datarate is high then BE is d5;
    RULE 13 : if NBRate is high AND Datarate is low then BE is d4;
    RULE 14 : if NBRate is high AND Datarate is medium then BE is d5;
    RULE 15 : if NBRate is high AND Datarate is mediumhigh then BE is d5;
    RULE 16 : if NBRate is high AND Datarate is high then BE is d5;
    END_RULEBLOCK

    END_FUNCTION_BLOCK

    Engine* engine = new Engine;
    FclImporter* importer = new FclImporter;
    std::string inputFilename = “NBrateDatarate_BEv10.fcl”;
    engine = importer->fromFile(inputFilename);
    engine->setInputValue(“NBRate”, 5.5);
    engine->setInputValue(“Datarate”, 50.0);
    engine->process();
    cout<<“This is for Back-off: “<< engine->getOutputValue(“BE”) <<endl;

    #1642

    Hi Mohammad,

    you should use QtFuzzyLite to help you with such kind of issues.

    The problems you have are:
    (1) the first rule starts with is instead of if
    (2) the fuzzy operators (AND, OR) are case sensitive, and in fuzzylite you utilize “and” and “or” instead of their upper-case operators.

    Cheers,

    Juan

    #1645
    Unknown
    Member

    Thanks Juan.

    Cheers,
    Mohammad

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.