home › Forums › # Technical Support › How to set list boolean type for input variables
 This topic has 4 replies, 2 voices, and was last updated 5 years, 10 months ago by Juan RadaVilela (admin).

AuthorPosts

January 17, 2017 at 04:35 #2284UnknownMember
Hi everyone,
i’m new bie,
I have many boolean type input variables (truefalse).
I applied fuzzylite following code:Engine engine = new Engine(); setName("System Fuzzy"); //Input// B = new InputVariable(); setEnabled(true); setName("B"); setRange(0.000, 20); addTerm(new Trapezoid("TRUE", 0, 2,8, 10)); addTerm(new Trapezoid("FALSE", 10,12,18,20)); addInputVariable(B); //Output// OutputVariable power = new OutputVariable(); setName("Power"); setRange(0.000, 20); setDefaultValue(0.000); addTerm(new Trapezoid("1", 0,1,3, 4)); addTerm(new Trapezoid("2a", 4,5,7, 8)); addTerm(new Trapezoid("2b", 8,9,11, 12)); addTerm(new Trapezoid("3", 12,13,15, 16)); addTerm(new Trapezoid("4", 16,17, 19, 20)); engine.addOutputVariable(power); RuleBlock ruleBlock = new RuleBlock(); ruleBlock.addRule(Rule.parse("if B is TRUE and C is >2 and D is TRUE and E is TRUE and F is C and G is TRUE and H is TRUE and L is TRUE and M is TRUE then Power is 4", engine));//1 ruleBlock.addRule(Rule.parse("if B is TRUE and C is >2 and D is TRUE and E is TRUE and F is C and G is TRUE and H is TRUE and L is TRUE and M is FALSE then Power is 3", engine));//2 addRule(Rule.parse("if B is TRUE and C is >2 and D is TRUE and E is TRUE or F is C and G is TRUE and H is TRUE and L is FALSE and M is TRUE then Power is 4", engine));//3 addRule(Rule.parse("if B is TRUE and C is >2 and D is TRUE and E is TRUE or F is C and G is TRUE and H is TRUE and L is FALSE and M is FALSE then Power is 1", engine));//3 engine.addRuleBlock(ruleBlock); configure("Minimum", "Maximum", "Minimum", "Maximum", "Centroid");
if i set 3 rules, the result seems to be right. But when i have more than 3 rules, the result is wrong.
What could be the problem?January 17, 2017 at 07:44 #2285Juan RadaVilela (admin)KeymasterHi,
thank you for your post.
Could you please post the FLL code for the engine? You can get that by using
FL_LOG(FllExporter().toString(engine))
.Have you tried using the FLL code in QtFuzzyLite to see the behaviour of the controller?
You should not be using
>2
in your rules. The symbol>
is not processed in rules.Cheers,
Juan.
January 17, 2017 at 21:31 #2286UnknownMemberThank you for your reply.
I don’t know what should i use in my case (input variables are boolean type. Which is a range of values before.)
This is my whole code and FLL code:
In my code
`Engine engine = new Engine();
engine.setName(“System Fuzzy”);InputVariable B = new InputVariable();
B.setEnabled(true);
B.setName(“B”);
B.setRange(0.000, 20);
B.addTerm(new Trapezoid(“TRUE”, 0, 2,8, 10));
B.addTerm(new Trapezoid(“FALSE”, 10,12,18,20));
engine.addInputVariable(B);InputVariable C = new InputVariable();
C.setEnabled(true);
C.setName(“C”);
C.setRange(0.000, 20);
C.addTerm(new Trapezoid(“2”, 0, 2,8, 10));
C.addTerm(new Trapezoid(“3”, 10,12,18,20));
engine.addInputVariable(C);InputVariable D = new InputVariable();
D.setEnabled(true);
D.setName(“D”);
D.setRange(0.000, 20);
D.addTerm(new Trapezoid(“TRUE”, 0, 2,8, 10));
D.addTerm(new Trapezoid(“FALSE”, 10,12,18,20));
engine.addInputVariable(D);InputVariable E = new InputVariable();
E.setEnabled(true);
E.setName(“E”);
E.setRange(0.000, 20);
E.addTerm(new Trapezoid(“TRUE”, 0, 2,8, 10));
E.addTerm(new Trapezoid(“FALSE”, 10,12,18,20));
engine.addInputVariable(E);InputVariable F = new InputVariable();
F.setEnabled(true);
F.setName(“F”);
F.setRange(0.000, 300);
F.addTerm(new Triangle(“C”, 0, 130));
F.addTerm(new Triangle(“BT”, 150, 170));
F.addTerm(new Triangle(“N”, 170, 300));/// neu >70 truyen 170
engine.addInputVariable(F);InputVariable G = new InputVariable();
G.setEnabled(true);
G.setName(“G”);
G.setRange(0.000, 20);
G.addTerm(new Trapezoid(“TRUE”, 0, 2,8, 10));
G.addTerm(new Trapezoid(“FALSE”, 10,12,18,20));
engine.addInputVariable(G);InputVariable H = new InputVariable();
H.setEnabled(true);
H.setName(“H”);
H.setRange(0.000, 20);
H.addTerm(new Trapezoid(“TRUE”, 0, 2,8, 10));
H.addTerm(new Trapezoid(“FALSE”, 10,12,18,20));
engine.addInputVariable(H);InputVariable L = new InputVariable();
L.setEnabled(true);
L.setName(“L”);
L.setRange(0.000, 20);
L.addTerm(new Trapezoid(“TRUE”, 0, 2,8, 10));
L.addTerm(new Trapezoid(“FALSE”, 10,12,18,20));
engine.addInputVariable(L);InputVariable M = new InputVariable();
M.setEnabled(true);
M.setName(“M”);
M.setRange(0.000, 20);
M.addTerm(new Trapezoid(“TRUE”, 0, 2,8, 10));
M.addTerm(new Trapezoid(“FALSE”, 10,12,18,20));
engine.addInputVariable(M);
////—————–OUTPUT
OutputVariable power = new OutputVariable();
power.setName(“Power”);
power.setRange(0.000, 20);
power.setDefaultValue(0.000);
power.addTerm(new Trapezoid(“1”, 0,1,3, 4));
power.addTerm(new Trapezoid(“2a”, 4,5,7, 8));
power.addTerm(new Trapezoid(“2b”, 8,9,11, 12));
power.addTerm(new Trapezoid(“3”, 12,13,15, 16));
power.addTerm(new Trapezoid(“4”, 16,17, 19, 20));engine.addOutputVariable(power);
RuleBlock ruleBlock = new RuleBlock();
ruleBlock.addRule(Rule.parse(“if B is TRUE and C is 2 and D is TRUE and E is TRUE and F is C and G is TRUE and H is TRUE and L is TRUE and M is TRUE then Power is 4”, engine));//1
ruleBlock.addRule(Rule.parse(“if B is TRUE and C is 2 and D is TRUE and E is TRUE and F is C and G is TRUE and H is TRUE and L is TRUE and M is FALSE then Power is 3”, engine));//2
ruleBlock.addRule(Rule.parse(“if B is TRUE and C is 2 and D is TRUE and E is TRUE or F is C and G is TRUE and H is TRUE and L is FALSE and M is TRUE then Power is 4”, engine));//3
// ruleBlock.addRule(Rule.parse(“if B is TRUE and C is 2 and D is TRUE and E is TRUE or F is C and G is TRUE and H is TRUE and L is FALSE and M is FALSE then Power is 1”, engine));//3
engine.addRuleBlock(ruleBlock);
engine.configure(“Minimum”, “Maximum”, “Minimum”, “Maximum”, “Centroid”);
StringBuilder status = new StringBuilder();
if (!engine.isReady(status)) {
throw new RuntimeException(“Engine not ready. ”
+ “The following errors were encountered:\n” + status.toString());
}
engine.setInputValue(“B”, 5);
engine.setInputValue(“C”, 5);
engine.setInputValue(“D”, 5);
engine.setInputValue(“E”, 5);
engine.setInputValue(“F”, 120);
engine.setInputValue(“G”, 5);
engine.setInputValue(“H”, 5);
engine.setInputValue(“L”, 5);
engine.setInputValue(“M”, 5);
engine.process();String result = String.format(
“B = %s and C = %s and D = %s and E = %s and F = %s and G = %s and H = %s and L = %s and M = %s> Power.output = %s”,
Op.str(B.getInputValue()),Op.str(C.getInputValue()),Op.str(D.getInputValue()),Op.str(E.getInputValue()),Op.str(F.getInputValue()),Op.str(G.getInputValue()),Op.str(H.getInputValue()),Op.str(L.getInputValue()),Op.str(M.getInputValue()), Op.str(power.getOutputValue())
);System.out.println(new FllExporter().toString(engine));
FuzzyLite.logger().info(result);<strong>This is my output: </strong>
Engine: System Fuzzy
InputVariable: B
enabled: true
range: 0.000 20.000
term: TRUE Trapezoid 0.000 2.000 8.000 10.000
term: FALSE Trapezoid 10.000 12.000 18.000 20.000
InputVariable: C
enabled: true
range: 0.000 20.000
term: 2 Trapezoid 0.000 2.000 8.000 10.000
term: 3 Trapezoid 10.000 12.000 18.000 20.000
InputVariable: D
enabled: true
range: 0.000 20.000
term: TRUE Trapezoid 0.000 2.000 8.000 10.000
term: FALSE Trapezoid 10.000 12.000 18.000 20.000
InputVariable: E
enabled: true
range: 0.000 20.000
term: TRUE Trapezoid 0.000 2.000 8.000 10.000
term: FALSE Trapezoid 10.000 12.000 18.000 20.000
InputVariable: F
enabled: true
range: 0.000 300.000
term: C Triangle 0.000 65.000 130.000
term: BT Triangle 150.000 160.000 170.000
term: N Triangle 170.000 235.000 300.000
InputVariable: G
enabled: true
range: 0.000 20.000
term: TRUE Trapezoid 0.000 2.000 8.000 10.000
term: FALSE Trapezoid 10.000 12.000 18.000 20.000
InputVariable: H
enabled: true
range: 0.000 20.000
term: TRUE Trapezoid 0.000 2.000 8.000 10.000
term: FALSE Trapezoid 10.000 12.000 18.000 20.000
InputVariable: L
enabled: true
range: 0.000 20.000
term: TRUE Trapezoid 0.000 2.000 8.000 10.000
term: FALSE Trapezoid 10.000 12.000 18.000 20.000
InputVariable: M
enabled: true
range: 0.000 20.000
term: TRUE Trapezoid 0.000 2.000 8.000 10.000
term: FALSE Trapezoid 10.000 12.000 18.000 20.000
OutputVariable: Power
enabled: true
range: 0.000 20.000
accumulation: Maximum
defuzzifier: Centroid 200
default: 0.000
lockprevious: false
lockrange: false
term: 1 Trapezoid 0.000 1.000 3.000 4.000
term: 2a Trapezoid 4.000 5.000 7.000 8.000
term: 2b Trapezoid 8.000 9.000 11.000 12.000
term: 3 Trapezoid 12.000 13.000 15.000 16.000
term: 4 Trapezoid 16.000 17.000 19.000 20.000
RuleBlock:
enabled: true
conjunction: Minimum
disjunction: Maximum
activation: Minimum
rule: if B is TRUE and C is 2 and D is TRUE and E is TRUE and F is C and G is TRUE and H is TRUE and L is TRUE and M is TRUE then Power is 4
rule: if B is TRUE and C is 2 and D is TRUE and E is TRUE and F is C and G is TRUE and H is TRUE and L is TRUE and M is FALSE then Power is 3
rule: if B is TRUE and C is 2 and D is TRUE and E is TRUE or F is C and G is TRUE and H is TRUE and L is FALSE and M is TRUE then Power is 4
20170117 14:57:04 INFO com.fuzzy.controller.Test main : B = 5.000 and C = 5.000 and D = 5.000 and E = 5.000 and F = 120.000 and G = 5.000 and H = 5.000 and L = 5.000 and M = 5.000> Power.output = 18.000`
January 17, 2017 at 21:50 #2287UnknownMemberSorry about my format in my reply. Because i’m on mobile,format code is wrong.
January 17, 2017 at 22:51 #2288Juan RadaVilela (admin)KeymasterHi,
you have an issue with your logic. You should be familiar with the logic AND. Given the input variables A and B, and an output variable Z, the result of A AND B is the following:
A B Z
0 0 0
0 1 0
1 0 0
1 1 1Now, consider Z to be the activation degree of your rules. The problem that you have is that some rules are all joined by AND, and if there is only one variable that is FALSE, then the activation degree of the whole rule is zero.
My suggestion is to try to reduce the number of variables that you use in your rules. And if not possible, at least use variables with more meaningful names that would help you better identify the problems.
Lastly, when in doubt, the best you can do is to use QtFuzzyLite to assign values to the input variables and see how the system behaves.
Cheers,
Juan.

AuthorPosts
 You must be logged in to reply to this topic.