#5 -- Fix validation
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 1m10s

This commit is contained in:
Anton Romanov 2025-02-21 10:40:47 +04:00
parent c33680fd66
commit 202d8cd0d3
6 changed files with 34 additions and 20 deletions

View File

@ -1,3 +1,4 @@
{ {
"java.configuration.updateBuildConfiguration": "interactive" "java.configuration.updateBuildConfiguration": "interactive",
"java.compile.nullAnalysis.mode": "disabled"
} }

View File

@ -29,7 +29,6 @@ public class RuleController {
(id != null && id != 0) (id != null && id != 0)
? new FuzzyRuleForm(id, ruleService.getById(id)) ? new FuzzyRuleForm(id, ruleService.getById(id))
: new FuzzyRuleForm(id, projectId)); : new FuzzyRuleForm(id, projectId));
return "rule/edit"; return "rule/edit";
} }

View File

@ -25,11 +25,10 @@ public class VariableController {
public String edit(@PathVariable(value = "projectId") Integer projectId, public String edit(@PathVariable(value = "projectId") Integer projectId,
@PathVariable(value = "varId") Integer id, Model model) { @PathVariable(value = "varId") Integer id, Model model) {
model.addAttribute("projectId", projectId); model.addAttribute("projectId", projectId);
model.addAttribute("variableForm", model.addAttribute("variableForm",
new VariableForm(id, (id != null && id != 0) (id != null && id != 0)
? variableService.getById(id).getProject().getId() ? new VariableForm(id, variableService.getById(id))
: projectId)); : new VariableForm(id, projectId));
return "var/edit"; return "var/edit";
} }

View File

@ -6,14 +6,14 @@ import ru.ulstu.fc.core.model.BaseEntity;
@Entity @Entity
public class FuzzyTerm extends BaseEntity { public class FuzzyTerm extends BaseEntity {
private String description; private String description;
private Double value; private Double crispValue;
public FuzzyTerm() { public FuzzyTerm() {
} }
public FuzzyTerm(String description, Double value) { public FuzzyTerm(String description, Double value) {
this.description = description; this.description = description;
this.value = value; this.crispValue = value;
} }
public String getDescription() { public String getDescription() {
@ -24,12 +24,11 @@ public class FuzzyTerm extends BaseEntity {
this.description = description; this.description = description;
} }
public Double getValue() { public Double getCrispValue() {
return value; return crispValue;
} }
public void setValue(Double value) { public void setCrispValue(Double crispValue) {
this.value = value; this.crispValue = crispValue;
} }
} }

View File

@ -10,6 +10,8 @@ public class VariableForm {
@Size(min = 3, max = 250, message = "Длина должна быть от 3 до 250") @Size(min = 3, max = 250, message = "Длина должна быть от 3 до 250")
private String name; private String name;
private boolean isInput = true;
public VariableForm() { public VariableForm() {
} }
@ -18,6 +20,13 @@ public class VariableForm {
this.projectId = projectId; this.projectId = projectId;
} }
public VariableForm(Integer id, Variable variable) {
this.id = id;
this.projectId = variable.getProject().getId();
this.name = variable.getName();
this.isInput = variable.isInput();
}
public Integer getProjectId() { public Integer getProjectId() {
return projectId; return projectId;
} }
@ -42,4 +51,11 @@ public class VariableForm {
this.name = name; this.name = name;
} }
public boolean isInput() {
return isInput;
}
public void setInput(boolean isInput) {
this.isInput = isInput;
}
} }

View File

@ -45,15 +45,15 @@ public class FuzzyInferenceService {
final InputVariable input = new InputVariable(); final InputVariable input = new InputVariable();
input.setName(variable.getName()); input.setName(variable.getName());
input.setDescription(""); input.setDescription("");
input.setRange(0, variable.getFuzzyTerms().get(variable.getFuzzyTerms().size() - 1).getValue()); input.setRange(0, variable.getFuzzyTerms().get(variable.getFuzzyTerms().size() - 1).getCrispValue());
input.setEnabled(true); input.setEnabled(true);
input.setLockValueInRange(false); input.setLockValueInRange(false);
double prev = 0; double prev = 0;
for (int i = 0; i < variable.getFuzzyTerms().size(); i++) { for (int i = 0; i < variable.getFuzzyTerms().size(); i++) {
Triangle term = new Triangle(variable.getFuzzyTerms().get(i).getDescription(), Triangle term = new Triangle(variable.getFuzzyTerms().get(i).getDescription(),
prev, prev,
variable.getFuzzyTerms().get(i).getValue(), variable.getFuzzyTerms().get(i).getCrispValue(),
variable.getFuzzyTerms().get(i).getValue() + variable.getFuzzyTerms().get(i).getValue() - prev); variable.getFuzzyTerms().get(i).getCrispValue() + variable.getFuzzyTerms().get(i).getCrispValue() - prev);
prev = term.getVertexB(); prev = term.getVertexB();
input.addTerm(term); input.addTerm(term);
} }
@ -64,7 +64,7 @@ public class FuzzyInferenceService {
final OutputVariable output = new OutputVariable(); final OutputVariable output = new OutputVariable();
output.setName(variable.getName()); output.setName(variable.getName());
output.setDescription(""); output.setDescription("");
output.setRange(0, variable.getFuzzyTerms().get(variable.getFuzzyTerms().size() - 1).getValue()); output.setRange(0, variable.getFuzzyTerms().get(variable.getFuzzyTerms().size() - 1).getCrispValue());
output.setEnabled(true); output.setEnabled(true);
output.setAggregation(new Maximum()); output.setAggregation(new Maximum());
output.setDefuzzifier(new WeightedAverage()); output.setDefuzzifier(new WeightedAverage());
@ -75,8 +75,8 @@ public class FuzzyInferenceService {
Triangle term = new Triangle( Triangle term = new Triangle(
variable.getFuzzyTerms().get(i).getDescription(), variable.getFuzzyTerms().get(i).getDescription(),
prev, prev,
variable.getFuzzyTerms().get(i).getValue(), variable.getFuzzyTerms().get(i).getCrispValue(),
variable.getFuzzyTerms().get(i).getValue() + variable.getFuzzyTerms().get(i).getValue() - prev); variable.getFuzzyTerms().get(i).getCrispValue() + variable.getFuzzyTerms().get(i).getCrispValue() - prev);
prev = term.getVertexB(); prev = term.getVertexB();
output.addTerm(term); output.addTerm(term);
} }