home Forums # Technical Support jfuzzylite with two input values Reply To: jfuzzylite with two input values

#1637
Unknown
Member

Hi Juan,

I have another class with the same problem of class above, sometimes the return value is NaN. I tried to switch to ramp, but does not work.

import com.fuzzylite.*; 
import com.fuzzylite.defuzzifier.*;
import com.fuzzylite.norm.s.*; 
import com.fuzzylite.norm.t.*; 
import com.fuzzylite.rule.*; 
import com.fuzzylite.term.*; 
import com.fuzzylite.variable.*; 

public class IndDisp {
	
	public String CalcIndDisp(double crit, double availability){
		
		Engine engine = new Engine();
		engine.setName("Ind-Disp");

		InputVariable inputVariable1 = new InputVariable();
		inputVariable1.setEnabled(true);
		inputVariable1.setName("Criticallity");
		inputVariable1.setRange(0.000, 5.000);
		inputVariable1.addTerm(new Triangle("Low", 0.000, 1.000, 2.000));
		inputVariable1.addTerm(new Triangle("Average", 1.000, 2.000, 3.000));
		inputVariable1.addTerm(new Triangle("High", 2.000, 3.000, 4.000));
		inputVariable1.addTerm(new Triangle("Very_High", 3.000, 4.000, 5.000));
		engine.addInputVariable(inputVariable1);

		InputVariable inputVariable2 = new InputVariable();
		inputVariable2.setEnabled(true);
		inputVariable2.setName("Availability");
		inputVariable2.setRange(90.000, 100.000); //inputVariable2.setRange(85.000, 100.000);
		inputVariable2.addTerm(new Ramp("Limit", 95.000, 90.000));  //inputVariable2.addTerm(new Triangle("Limit", 90.000, 90.000, 95.000));
		inputVariable2.addTerm(new Triangle("Very_Low", 90.000, 95.000, 98.000));
		inputVariable2.addTerm(new Triangle("Low", 95.000, 98.000, 99.000));
		inputVariable2.addTerm(new Triangle("Average", 98.000, 99.000, 99.900));
		inputVariable2.addTerm(new Triangle("High", 99.000, 99.900, 100.000));
		inputVariable2.addTerm(new Ramp("Perfect", 99.900, 100.000));  //inputVariable2.addTerm(new Triangle("Perfect", 99.900, 100.000, 100.000));
		engine.addInputVariable(inputVariable2);

		OutputVariable outputVariable = new OutputVariable();
		outputVariable.setEnabled(true);
		outputVariable.setName("IndDisp");
		outputVariable.setRange(-3.000, 13.000);
		outputVariable.fuzzyOutput().setAccumulation(new Maximum());
		outputVariable.setDefuzzifier(new Centroid(200));
		outputVariable.setDefaultValue(Double.NaN);
		outputVariable.setLockValidOutput(false);
		outputVariable.setLockOutputRange(false);
		outputVariable.addTerm(new Triangle("Worst", -3.000, 0.000, 3.000));
		outputVariable.addTerm(new Triangle("Bad", 0.000, 3.000, 5.000));
		outputVariable.addTerm(new Triangle("Average", 3.000, 5.000, 7.000));
		outputVariable.addTerm(new Triangle("Good", 5.000, 7.000, 10.000));
		outputVariable.addTerm(new Triangle("Best", 7.000, 10.000, 13.000));
		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 Criticallity is Low and Availability is Limit then IndDisp is Worst", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Low and Availability is Very_Low then IndDisp is Bad", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Low and Availability is Low then IndDisp is Average", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Low and Availability is Average then IndDisp is Good", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Low and Availability is High then IndDisp is Best", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Low and Availability is Perfect then IndDisp is Best", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Average and Availability is Limit then IndDisp is Worst", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Average and Availability is Very_Low then IndDisp is Worst", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Average and Availability is Low then IndDisp is Bad", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Average and Availability is Average then IndDisp is Average", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Average and Availability is High then IndDisp is Good", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Average and Availability is Perfect then IndDisp is Best", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is High and Availability is Limit then IndDisp is Worst", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is High and Availability is Very_Low then IndDisp is Worst", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is High and Availability is Low then IndDisp is Bad", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is High and Availability is Average then IndDisp is Average", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is High and Availability is High then IndDisp is Best", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is High and Availability is Perfect then IndDisp is Best", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Very_High and Availability is Limit then IndDisp is Worst", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Very_High and Availability is Very_Low then IndDisp is Worst", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Very_High and Availability is Low then IndDisp is Bad", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Very_High and Availability is Average then IndDisp is Bad", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Very_High and Availability is High then IndDisp is Good", engine));
		ruleBlock.addRule(Rule.parse("if Criticallity is Very_High and Availability is Perfect then IndDisp is Best", engine));
		engine.addRuleBlock(ruleBlock);
		
		StringBuilder status = new StringBuilder();
		if (!engine.isReady(status))
		throw new RuntimeException("Nao foi possivel gerar o arquivo. "
		+ "O seguintes erros foram encontrados:\n"
		+ status.toString());
				
		engine.setInputValue("Criticallity", crit);
		engine.setInputValue("Availability", availability);
		engine.process();

		return String.valueOf(engine.getOutputValue("IndDisp"));
	} 
}

I appreciate any help.