home › Forums › # Technical Support › addRule throws exception
- This topic has 2 replies, 2 voices, and was last updated 7 years, 10 months ago by
Unknown.
-
AuthorPosts
-
December 1, 2015 at 10:16 #1979
Unknown
MemberHi! I encountered a problem when initializing the system. I get an unhanded exception when I get to line with addRule. I found in another topic that similar problem was caused by not defining required Input Variables, but I have all of them created.
I would not bother you but for some reason I could not get the debugger working for this library. So I can’t get the concrete type of the exception or an exact line in your code that throws the exception. 🙁
Here is my code:
fl::Engine* engine = new fl::Engine("beamAndBallMain"); engine->configure("Minimum", "Maximum", "Minimum", "Maximum", "Centroid"); // Input 1 odchylka = new fl::InputVariable; odchylka->setName("odchylka"); odchylka->setRange(-1.000, 1.000); odchylka->addTerm(new fl::Triangle("NB", -fl::inf, -0.75f, -0.5f)); odchylka->addTerm(new fl::Triangle("NN", -0.75, - 0.5, - 0.25)); odchylka->addTerm(new fl::Triangle("NS", -0.5, - 0.25, 0)); odchylka->addTerm(new fl::Triangle("ZE", -0.25, 0, 0.25)); odchylka->addTerm(new fl::Triangle("PS", 0, 0.25, 0.5)); odchylka->addTerm(new fl::Triangle("PM", 0.25, 0.5, 0.75)); odchylka->addTerm(new fl::Triangle("PB", 0.5, 0.75, fl::inf)); engine->addInputVariable(odchylka); // Input 2 deltaE = new fl::InputVariable; deltaE->setName("deltaE"); deltaE->setRange(-1.000, 1.000); odchylka->addTerm(new fl::Triangle("NB", -fl::inf, -0.75f, -0.5f)); odchylka->addTerm(new fl::Triangle("NN", -0.75, -0.5, -0.25)); odchylka->addTerm(new fl::Triangle("NS", -0.5, -0.25, 0)); odchylka->addTerm(new fl::Triangle("ZE", -0.25, 0, 0.25)); odchylka->addTerm(new fl::Triangle("PS", 0, 0.25, 0.5)); odchylka->addTerm(new fl::Triangle("PM", 0.25, 0.5, 0.75)); odchylka->addTerm(new fl::Triangle("PB", 0.5, 0.75, fl::inf)); engine->addInputVariable(deltaE); // Output angle = new fl::OutputVariable; angle->setName("angle"); angle->setRange(-1.000, 1.000); angle->setDefaultValue(fl::nan); odchylka->addTerm(new fl::Triangle("NM3", -fl::inf, -0.75f, -0.5f)); odchylka->addTerm(new fl::Triangle("NM2", -0.75, -0.5, -0.25)); odchylka->addTerm(new fl::Triangle("NM1", -0.5, -0.25, 0)); odchylka->addTerm(new fl::Triangle("NPM", -0.25, 0, 0.25)); odchylka->addTerm(new fl::Triangle("PM1", 0, 0.25, 0.5)); odchylka->addTerm(new fl::Triangle("PM2", 0.25, 0.5, 0.75)); odchylka->addTerm(new fl::Triangle("PM3", 0.5, 0.75, fl::inf)); engine->addOutputVariable(angle); // Rules fl::RuleBlock* ruleblock = new fl::RuleBlock; ruleblock->setEnabled(true); ruleblock->setName(""); ruleblock->setConjunction(new fl::Minimum()); ruleblock->setDisjunction(new fl::Maximum()); ruleblock->setImplication(new fl::Minimum()); ruleblock->addRule(fl::Rule::parse("if odchylka is NB and deltaE is NB then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NM and deltaE is NB then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NS and deltaE is NB then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is ZE and deltaE is NB then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PS and deltaE is NB then angle is NM2", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PM and deltaE is NB then angle is NS1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PB and deltaE is NB then angle is NPM", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NB and deltaE is NM then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NM and deltaE is NM then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NS and deltaE is NM then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is ZE and deltaE is NM then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PS and deltaE is NM then angle is NS1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PM and deltaE is NM then angle is NPM", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PB and deltaE is NM then angle is PM1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NB and deltaE is NS then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NM and deltaE is NS then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NS and deltaE is NS then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is ZE and deltaE is NS then angle is NS1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PS and deltaE is NS then angle is NPM", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PM and deltaE is NS then angle is PM1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PB and deltaE is NS then angle is PM2", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NB and deltaE is ZE then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NM and deltaE is ZE then angle is NM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NS and deltaE is ZE then angle is NS1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is ZE and deltaE is ZE then angle is NPM", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PS and deltaE is ZE then angle is PM1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PM and deltaE is ZE then angle is PM2", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PB and deltaE is ZE then angle is PM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NB and deltaE is PS then angle is NM2", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NM and deltaE is PS then angle is NS1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NS and deltaE is PS then angle is NPM", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is ZE and deltaE is PS then angle is PM1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PS and deltaE is PS then angle is PM2", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PM and deltaE is PS then angle is PM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PB and deltaE is PS then angle is PM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NB and deltaE is PM then angle is NS1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NM and deltaE is PM then angle is NPM", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NS and deltaE is PM then angle is PM1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is ZE and deltaE is PM then angle is PM2", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PS and deltaE is PM then angle is PM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PM and deltaE is PM then angle is PM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PB and deltaE is PM then angle is PM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NB and deltaE is PB then angle is NPM", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NM and deltaE is PB then angle is PM1", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is NS and deltaE is PB then angle is PM2", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is ZE and deltaE is PB then angle is PM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PS and deltaE is PB then angle is PM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PM and deltaE is PB then angle is PM3", engine)); ruleblock->addRule(fl::Rule::parse("if odchylka is PB and deltaE is PB then angle is PM3", engine)); engine->addRuleBlock(ruleblock); // Stuff std::string status; if (not engine->isReady(&status)) throw fl::Exception("Engine not ready. " "The following errors were encountered:\n" + status, FL_AT);
Thanks a lot for your help. 🙂
December 7, 2015 at 02:56 #1986Juan Rada-Vilela (admin)
KeymasterHi,
thank you for your post.
First of all, you should not be using the triangles and trapezoids with infinity values. I understand what you intend to do, but you must use the Ramp term for such cases. If this does not solve your issue, please post the FLL code of the engine to run it through QtFuzzyLite. You can get the code by issuing
FllExporter().toString(engine)
orengine->toString()
.Cheers.
December 7, 2015 at 04:20 #1987Unknown
MemberThanks for the answer I actually resolved the issue by adding this 2 lines in the OutputVariable definition
angle->setDefuzzifier(new fl::Centroid()); angle->fuzzyOutput()->setAccumulation(new fl::Maximum());
And then there were few misspelling problems in the rules.
But thanks anyway. And it works with the infinite triangles, but if it sometimes in the future stop to work I’ll know where to look. 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.