|
|
@ -19,7 +19,10 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class FuzzyInferenceService {
|
|
|
|
public class FuzzyInferenceService {
|
|
|
|
private final static String RULE_TEMPLATE = "if %s is %s AND %s is %s then state is %s";
|
|
|
|
private final static String OUTPUT_VARIABLE_NAME = "state";
|
|
|
|
|
|
|
|
private final static String RULE_TEMPLATE = "if %s is %s and %s is %s then "
|
|
|
|
|
|
|
|
+ OUTPUT_VARIABLE_NAME
|
|
|
|
|
|
|
|
+ " is %s";
|
|
|
|
private final RuleService ruleService;
|
|
|
|
private final RuleService ruleService;
|
|
|
|
private final AntecedentValueService antecedentValueService;
|
|
|
|
private final AntecedentValueService antecedentValueService;
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +52,7 @@ public class FuzzyInferenceService {
|
|
|
|
input.setName(key);
|
|
|
|
input.setName(key);
|
|
|
|
input.setDescription("");
|
|
|
|
input.setDescription("");
|
|
|
|
input.setEnabled(true);
|
|
|
|
input.setEnabled(true);
|
|
|
|
input.setRange(0.000, 1.000);
|
|
|
|
input.setRange(0.000, antecedentValues.size() + 1);
|
|
|
|
input.setLockValueInRange(false);
|
|
|
|
input.setLockValueInRange(false);
|
|
|
|
for (int i = 0; i < antecedentValues.size(); i++) {
|
|
|
|
for (int i = 0; i < antecedentValues.size(); i++) {
|
|
|
|
input.addTerm(new Triangle(antecedentValues.get(i).getAntecedentValue(), i, i + 2));
|
|
|
|
input.addTerm(new Triangle(antecedentValues.get(i).getAntecedentValue(), i, i + 2));
|
|
|
@ -57,6 +60,16 @@ public class FuzzyInferenceService {
|
|
|
|
engine.addInputVariable(input);
|
|
|
|
engine.addInputVariable(input);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OutputVariable output = new OutputVariable();
|
|
|
|
|
|
|
|
output.setName(OUTPUT_VARIABLE_NAME);
|
|
|
|
|
|
|
|
output.setDescription("");
|
|
|
|
|
|
|
|
output.setEnabled(true);
|
|
|
|
|
|
|
|
output.setRange(0.000, antecedentValues.size() + 1);
|
|
|
|
|
|
|
|
output.setLockValueInRange(false);
|
|
|
|
|
|
|
|
for (int i = 0; i < antecedentValues.size(); i++) {
|
|
|
|
|
|
|
|
output.addTerm(new Triangle(antecedentValues.get(i).getAntecedentValue(), i, i + 2));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
engine.addOutputVariable(output);
|
|
|
|
|
|
|
|
|
|
|
|
RuleBlock mamdani = new RuleBlock();
|
|
|
|
RuleBlock mamdani = new RuleBlock();
|
|
|
|
mamdani.setName("mamdani");
|
|
|
|
mamdani.setName("mamdani");
|
|
|
@ -81,17 +94,19 @@ public class FuzzyInferenceService {
|
|
|
|
Engine engine = getFuzzyEngine();
|
|
|
|
Engine engine = getFuzzyEngine();
|
|
|
|
List<AntecedentValue> antecedentValues = antecedentValueService.getList();
|
|
|
|
List<AntecedentValue> antecedentValues = antecedentValueService.getList();
|
|
|
|
Map<String, Double> variableValues = new HashMap<>();
|
|
|
|
Map<String, Double> variableValues = new HashMap<>();
|
|
|
|
|
|
|
|
variableValues.put("COMMITS", 10.0);
|
|
|
|
|
|
|
|
variableValues.put("AUTHORS", 10.0);
|
|
|
|
engine.addRuleBlock(getRuleBlock(engine, variableValues, antecedentValues));
|
|
|
|
engine.addRuleBlock(getRuleBlock(engine, variableValues, antecedentValues));
|
|
|
|
return getConsequent(engine, variableValues);
|
|
|
|
return getConsequent(engine, variableValues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getConsequent(Engine engine, Map<String, Double> variableValues) {
|
|
|
|
private String getConsequent(Engine engine, Map<String, Double> variableValues) {
|
|
|
|
OutputVariable outputVariable = engine.getOutputVariable("state");
|
|
|
|
OutputVariable outputVariable = engine.getOutputVariable(OUTPUT_VARIABLE_NAME);
|
|
|
|
for (Map.Entry<String, Double> variableValue : variableValues.entrySet()) {
|
|
|
|
for (Map.Entry<String, Double> variableValue : variableValues.entrySet()) {
|
|
|
|
InputVariable inputVariable = engine.getInputVariable(variableValue.getKey());
|
|
|
|
InputVariable inputVariable = engine.getInputVariable(variableValue.getKey());
|
|
|
|
inputVariable.setValue(variableValue.getValue());
|
|
|
|
inputVariable.setValue(variableValue.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
engine.process();
|
|
|
|
engine.process();
|
|
|
|
return outputVariable.highestMembership(outputVariable.getValue()).getSecond().getName();
|
|
|
|
return outputVariable == null ? "" : outputVariable.fuzzyOutputValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|