This commit is contained in:
marcin-szczepanski 2022-07-27 19:11:50 +02:00
parent c3324c0b75
commit d9b7260030
3 changed files with 6 additions and 0 deletions

View File

@ -100,6 +100,9 @@ class FunctionBlock_tipper {
sum_tip += this.defuzzify_tip[i]; sum_tip += this.defuzzify_tip[i];
wsum_tip += x * this.defuzzify_tip[i]; wsum_tip += x * this.defuzzify_tip[i];
} }
if (sum_tip == 0) {
sum_tip = 1.0;
}
this.tip = wsum_tip / sum_tip; this.tip = wsum_tip / sum_tip;
} }

View File

@ -68,6 +68,9 @@ public class DefuzzifierCenterOfGravity extends DefuzzifierContinuous {
out.append("\t\t\t" + sumName + " += this." + defuzzName + "[i];\n"); out.append("\t\t\t" + sumName + " += this." + defuzzName + "[i];\n");
out.append("\t\t\t" + wsumName + " += x * this." + defuzzName + "[i];\n"); out.append("\t\t\t" + wsumName + " += x * this." + defuzzName + "[i];\n");
out.append("\t\t}\n"); out.append("\t\t}\n");
out.append("\t\tif (" + sumName + " == 0) {\n");
out.append("\t\t\t" + sumName + " = 1.0;\n");
out.append("\t\t}\n");
out.append("\t\tthis." + variable.getName() + " = " + wsumName + " / " + sumName + ";\n"); out.append("\t\tthis." + variable.getName() + " = " + wsumName + " / " + sumName + ";\n");
return out.toString(); return out.toString();
} }