home › Forums › # Technical Support › How to set list boolean type for input variables › Reply To: How to set list boolean type for input variables
Thank 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
lock-previous: false
lock-range: 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
2017-01-17 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
`