home › Forums › # Technical Support › JAVA API › Reply To: JAVA API
September 2, 2014 at 17:51
#1411
Member
hello i’m trying to use the java api but always gets NaN as a result can anyone help me?
there is the setup of the engine
engine = new Engine("simple-dimmer");
InputVariable personas = new InputVariable();
personas.setName("PERSONAS");
personas.setRange(0, 30);
personas.addTerm(new Trapezoid("POCAS", 0, 0, 5, 10));
personas.addTerm(new Trapezoid("LEVE", 5,10,15,20));
personas.addTerm(new Trapezoid("MUCHAS", 15,20,30,30));
engine.addInputVariable(personas);
InputVariable temp=new InputVariable();
temp.setName("TEMPERATURA");
temp.setRange(12,28);
temp.addTerm(new Trapezoid("BAJA",12,12,18,20));
temp.addTerm(new Trapezoid("MEDIA", 18,20,24,26));
temp.addTerm(new Trapezoid("ALTA", 24,26,28,29));
engine.addInputVariable(temp);
OutputVariable outputVariable = new OutputVariable();
outputVariable.setEnabled(true);
outputVariable.setName("RPM");
outputVariable.setRange(0, 5000);
outputVariable.fuzzyOutput().setAccumulation(new Maximum());
outputVariable.setDefuzzifier(new Centroid(200));
outputVariable.setDefaultValue(Double.NaN);
outputVariable.addTerm(new Trapezoid("LENTO",0, 0,1500,2000));
outputVariable.addTerm(new Trapezoid("INTERMEDIO",1000,2500,3000,4500));
outputVariable.addTerm(new Trapezoid("RAPIDO", 3500,4000,5000,5000));
engine.addOutputVariable(outputVariable);
RuleBlock ruleBlock = new RuleBlock();
ruleBlock.setEnabled(true);
ruleBlock.setName("");
ruleBlock.setConjunction(new Minimum());
ruleBlock.setDisjunction(new Maximum());
ruleBlock.setActivation(new Minimum());
ruleBlock.addRule(Rule.parse("if PERSONAS is POCAS and TEMPERATURA is BAJA then RPM is LENTO",engine));
ruleBlock.addRule(Rule.parse("if PERSONAS is POCAS and TEMPERATURA is MEDIA then RPM is INTERMEDIO", engine));
ruleBlock.addRule(Rule.parse("if PERSONAS is POCAS and TEMPERATURA is ALTA then RPM is RAPIDO",engine));
ruleBlock.addRule(Rule.parse("if PERSONAS is LEVE and TEMPERATURA is BAJA then RPM is INTERMEDIO",engine));
ruleBlock.addRule(Rule.parse("if PERSONAS is LEVE and TEMPERATURA is MEDIA then RPM is INTERMEDIO", engine));
ruleBlock.addRule(Rule.parse("if PERSONAS is LEVE and TEMPERATURA is ALTA then RPM is RAPIDO",engine));
ruleBlock.addRule(Rule.parse("if PERSONAS is MUCHAS and TEMPERATURA is BAJA then RPM is INTERMEDIO",engine));
ruleBlock.addRule(Rule.parse("if PERSONAS is MUCHAS and TEMPERATURA is MEDIA then RPM is RAPIDO", engine));
ruleBlock.addRule(Rule.parse("if PERSONAS is MUCHAS and TEMPERATURA is ALTA then RPM is RAPIDO",engine));
engine.addRuleBlock(ruleBlock);
StringBuilder status = new StringBuilder();
if (!engine.isReady(status))
throw new RuntimeException("no se pdo arrancar el motor difuso se encontraron las siguientes fallas \n"+ status.toString());
and there is where i try to use it in another part of my code
engine.setInputValue("PERSONAS", sldPERSONAS.getValue());
engine.setInputValue("TEMPERATURA",sldTEMP.getValue());
engine.process();
System.out.println(engine.getOutputVariable("RPM").getLastValidOutput());