//+++++++++++++++++++++++++++++++++++++++++++++++++++++
// File automatically generated by Xfuzzy - DO NOT EDIT
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
package pkg.xfl.defuz;
import xfuzzy.lang.*;
public class MeanOfMaxima extends DefuzMethod {
public MeanOfMaxima() {
super("xfl","MeanOfMaxima");
Parameter single[] = new Parameter[0];
setSingleParameters(single);
}
public double compute(AggregateMemFunc mf) {
double min = mf.min();
double max = mf.max();
double step = mf.step();
double out = min, maximum = 0;
int counter = 1;
for(double x=min; x<=max; x+=step) {
double m = mf.compute(x);
if(m == maximum) { out+=x; counter++; }
if(m > maximum) { maximum = m; out = x; counter = 1; }
}
return out/counter;
}
public boolean test () {
return true;
}
public boolean test(AggregateMemFunc mf) {
return true;
}
public String getJavaCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " double out = min, maximum = 0;"+eol;
code += " int counter = 1;"+eol;
code += " for(double x=min; x<=max; x+=step) {"+eol;
code += " double m = mf.compute(x);"+eol;
code += " if(m == maximum) { out+=x; counter++; }"+eol;
code += " if(m > maximum) { maximum = m; out = x; counter = 1; }"+eol;
code += " }"+eol;
code += " return out/counter;"+eol;
return code;
}
public String getCCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " double x, m, out=min, maximum=0;"+eol;
code += " int counter = 1;"+eol;
code += " for(x=min; x<=max; x+=step) {"+eol;
code += " m = compute(mf,x);"+eol;
code += " if(m == maximum) { out+=x; counter++; }"+eol;
code += " if(m > maximum) { maximum = m; out = x; counter = 1; }"+eol;
code += " }"+eol;
code += " return out/counter;"+eol;
return code;
}
public String getCppCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " double out=min, maximum=0;"+eol;
code += " int counter = 1;"+eol;
code += " for(double x=min; x<=max; x+=step) {"+eol;
code += " double m = mf.compute(x);"+eol;
code += " if(m == maximum) { out+=x; counter++; }"+eol;
code += " if(m > maximum) { maximum = m; out = x; counter = 1; }"+eol;
code += " }"+eol;
code += " return out/counter;"+eol;
return code;
}
}