#3 -- Config of fuzzy engine

This commit is contained in:
Anton Romanov 2023-09-11 18:22:00 +04:00
parent f3710b6680
commit 1c8eabfc08
2 changed files with 24 additions and 10 deletions

View File

@ -0,0 +1,16 @@
package ru.ulstu.fc.config;
import com.fuzzylite.Engine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FuzzyEngine {
@Bean
public Engine getFuzzyEngine() {
Engine engine = new Engine();
engine.setName("Fuzzy rules");
engine.setDescription("");
return engine;
}
}

View File

@ -30,6 +30,7 @@ public class FuzzyInferenceService {
+ OUTPUT_VARIABLE_NAME
+ " is %s";
private final static String NO_RESULT = "Нет результата";
private final Engine fuzzyEngine;
private Map<String, List<Entry<String, Integer>>> inputFuzzyTerms = Map.of(
"возраст",
@ -48,6 +49,10 @@ public class FuzzyInferenceService {
new AbstractMap.SimpleEntry("средний", 100000),
new AbstractMap.SimpleEntry("большой", 1000000)));
public FuzzyInferenceService(Engine fuzzyEngine) {
this.fuzzyEngine = fuzzyEngine;
}
private List<String> getDemoRules() {
return List.of(
String.format(RULE_TEMPLATE, "возраст", "молодой", "доход", "высокий", "большой"),
@ -112,13 +117,6 @@ public class FuzzyInferenceService {
return mamdani;
}
private Engine getFuzzyEngine() {
Engine engine = new Engine();
engine.setName("Fuzzy rules");
engine.setDescription("");
return engine;
}
private Map<String, Double> getConsequent(Engine engine, Map<String, Double> variableValues) {
OutputVariable outputVariable = engine.getOutputVariable(OUTPUT_VARIABLE_NAME);
for (Map.Entry<String, Double> variableValue : variableValues.entrySet()) {
@ -135,9 +133,9 @@ public class FuzzyInferenceService {
}
public Map<String, Double> getFuzzyInference() {
Engine engine = getFuzzyEngine();
engine.addRuleBlock(getRuleBlock(engine, getDemoRules()));
return getConsequent(engine, Map.of("возраст", 20.0, "доход", 250000.0));
fuzzyEngine.getRuleBlocks().clear();
fuzzyEngine.addRuleBlock(getRuleBlock(fuzzyEngine, getDemoRules()));
return getConsequent(fuzzyEngine, Map.of("возраст", 20.0, "доход", 250000.0));
}
}