我在大学里为一项作业制作了一台FuzzyLogic空调器,我需要让它在Java中运行。我已将JFuzzyLogic jar文件添加到我的eclipse项目中,但每次运行代码时它都会立即终止。有人能指出我正确的方向让这个工作。提前谢谢。
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 Lab1{
public static void main(String[] args){
Engine engine = new Engine();
engine.setName("Air Conditioner");
InputVariable inputVariable1 = new InputVariable();
inputVariable1.setInputValue(15.000);
inputVariable1.setEnabled(true);
inputVariable1.setName("temperature");
inputVariable1.setRange(-10.000, 40.000);
inputVariable1.addTerm(new Trapezoid("toocold", -10.000, -10.000, 0.000, 5.000));
inputVariable1.addTerm(new Trapezoid("cold", 0.000, 5.000, 10.000, 15.000));
inputVariable1.addTerm(new Trapezoid("warm", 10.000, 15.000, 20.000, 25.000));
inputVariable1.addTerm(new Trapezoid("hot", 20.000, 25.000, 30.000, 35.000));
inputVariable1.addTerm(new Trapezoid("toohot", 30.000, 35.000, 40.000, 40.000));
engine.addInputVariable(inputVariable1);
InputVariable inputVariable2 = new InputVariable();
inputVariable2.setInputValue(30.000);
inputVariable2.setEnabled(true);
inputVariable2.setName("target");
inputVariable2.setRange(15.000, 35.000);
inputVariable2.addTerm(new Trapezoid("cold", 15.000, 15.000, 20.000, 25.000));
inputVariable2.addTerm(new Triangle("warm", 20.000, 25.000, 30.000));
inputVariable2.addTerm(new Trapezoid("hot", 25.000, 30.000, 35.000, 35.000));
engine.addInputVariable(inputVariable2);
OutputVariable outputVariable = new OutputVariable();
outputVariable.setEnabled(true);
outputVariable.setName("command");
outputVariable.setRange(0.000, 1.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("cool", 0.000, 0.250, 0.500));
outputVariable.addTerm(new Triangle("nochange", 0.250, 0.500, 0.750));
outputVariable.addTerm(new Triangle("heat", 0.500, 0.750, 1.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 (temperature is toocold) then command is heat", engine));
ruleBlock.addRule(Rule.parse("if (temperature is toohot) then command is cool", engine));
ruleBlock.addRule(Rule.parse("if (temperature is toocold or temperature is cold) and (target is warm) then command is heat", engine));
ruleBlock.addRule(Rule.parse("if (temperature is toohot or temperature is hot) and (target is warm) then command is cool", engine));
ruleBlock.addRule(Rule.parse("if (temperature is warm) and (target is warm) then command is nochange", engine));
ruleBlock.addRule(Rule.parse("if (temperature is cold) and (target is cold) then command is nochange", engine));
ruleBlock.addRule(Rule.parse("if (temperature is hot) and (target is hot) then command is nochange", engine));
engine.addRuleBlock(ruleBlock);
}
}