3-parse-rule #10
16
src/main/java/ru/ulstu/fc/config/FuzzyEngine.java
Normal file
16
src/main/java/ru/ulstu/fc/config/FuzzyEngine.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user