From 93141932d640787d43b0cb9a1529b5628b246fdb Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 7 Sep 2023 18:16:40 +0400 Subject: [PATCH] #8 -- final of the demo --- .../controller/InferenceMvcController.java | 2 +- .../rule/service/FuzzyInferenceService.java | 25 +++++-------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/main/java/ru/ulstu/fc/rule/controller/InferenceMvcController.java b/src/main/java/ru/ulstu/fc/rule/controller/InferenceMvcController.java index 1875bc8..7267da1 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/InferenceMvcController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/InferenceMvcController.java @@ -34,7 +34,7 @@ public class InferenceMvcController { model.addAttribute("ageAntecedents", getAgeAntecedents()); model.addAttribute("incomeAntecedents", getIncomeAntecedents()); model.addAttribute("inferenceForm", inferenceForm); - model.addAttribute("response", fuzzyInferenceService.getFuzzyInference().get(0)); + model.addAttribute("response", fuzzyInferenceService.getFuzzyInference()); return "index"; } diff --git a/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java b/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java index 0c16b4c..518a9e5 100644 --- a/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java +++ b/src/main/java/ru/ulstu/fc/rule/service/FuzzyInferenceService.java @@ -17,7 +17,6 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import java.util.AbstractMap; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -45,7 +44,7 @@ public class FuzzyInferenceService { new AbstractMap.SimpleEntry("высокий", 500000))); private Map>> outputFuzzyTerms = Map.of( - "кредит", List.of(new AbstractMap.SimpleEntry("небольшой", 200000), + "кредит", List.of(new AbstractMap.SimpleEntry("небольшой", 20000), new AbstractMap.SimpleEntry("средний", 100000), new AbstractMap.SimpleEntry("большой", 1000000))); @@ -66,6 +65,7 @@ public class FuzzyInferenceService { final InputVariable input = new InputVariable(); input.setName(name); input.setDescription(""); + input.setRange(0, terms.get(terms.size() - 1).getValue()); input.setEnabled(true); input.setLockValueInRange(false); double prev = 0; @@ -81,9 +81,10 @@ public class FuzzyInferenceService { final OutputVariable output = new OutputVariable(); output.setName(name); output.setDescription(""); + output.setRange(0, terms.get(terms.size() - 1).getValue()); output.setEnabled(true); output.setAggregation(new Maximum()); - output.setDefuzzifier(new Centroid(10)); + output.setDefuzzifier(new Centroid(terms.get(terms.size() - 1).getValue())); output.setDefaultValue(Double.NaN); output.setLockValueInRange(false); double prev = 0; @@ -133,24 +134,10 @@ public class FuzzyInferenceService { : outputVariable.fuzzyOutput().getTerms().stream().collect(Collectors.toMap(t -> t.getTerm().getName(), Activated::getDegree)); } - public List getFuzzyInference() { - //variableValues.entrySet().forEach(e -> System.out.println(e.getKey() + " " + e.getValue())); + public Map getFuzzyInference() { Engine engine = getFuzzyEngine(); - //List consequentValues = dbRules.stream().map(DbRule::getId).collect(Collectors.toList()); engine.addRuleBlock(getRuleBlock(engine, getDemoRules())); - Map consequents = getConsequent(engine, Map.of("возраст", 20.0, "доход", 250000.0)); - if (consequents.containsKey(NO_RESULT)) { - return new ArrayList<>(); - } - /*List assessments = new ArrayList<>(); - for (Map.Entry consequent : consequents.entrySet()) { - for (DbRule dbRule : dbRules) { - if (dbRule.getId().equals(Integer.valueOf(consequent.getKey()))) { - assessments.add(new Assessment(dbRule, consequent.getValue())); - } - } - }*/ - return List.of(0.0); + return getConsequent(engine, Map.of("возраст", 20.0, "доход", 250000.0)); } }