//+++++++++++++++++++++++++++++++++++++++++++++++++++++
// File automatically generated by Xfuzzy - DO NOT EDIT
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
package pkg.xfsg.family;
import xfuzzy.lang.*;
public class sh_triangular extends Family {
public sh_triangular() {
super("xfsg","sh_triangular");
Parameter single[] = new Parameter[0];
setSingleParameters(single);
setParamListName("p");
setParamList(new Parameter[0]);
}
public int members() {
double[] p = getParamListValues();
return p.length;
}
public double compute(int i, double x) {
double min = this.min();
double max = this.max();
double[] p = getParamListValues();
if(i==0 && x<p[0]) return 1;
if(i==p.length-1 && x>p[p.length-1]) return 1;
double a = (i==0? min : p[i-1]);
double b = p[i];
double c = (i==p.length-1? max : p[i+1]);
return (a<x && x<=b? (x-a)/(b-a) : (b<x && x<c? (c-x)/(c-b) : 0));
}
public double greatereq(int i, double x) {
double min = this.min();
double[] p = getParamListValues();
if(i==0) return 1;
double a = (i==0? min : p[i-1]);
double b = p[i];
return (x<a? 0 : (x>b? 1 : (x-a)/(b-a) ));
}
public double smallereq(int i, double x) {
double max = this.max();
double[] p = getParamListValues();
if(i==p.length-1) return 1;
double b = p[i];
double c = (i==p.length-1? max : p[i+1]);
return (x<b? 1 : (x>c? 0 : (c-x)/(c-b) ));
}
public double center(int i) {
double min = this.min();
double max = this.max();
double[] p = getParamListValues();
return (i==0? (min+p[0])/2 : (i==p.length-1? (max+p[p.length-1])/2 : p[i]));
}
public double basis(int i) {
double min = this.min();
double max = this.max();
double[] p = getParamListValues();
double a = (i==0 ? min : p[i-1]);
double c = (i==p.length-1? max : p[i+1]);
return (c-a);
}
public double[] deriv_eq(int i, double x) {
double[] deriv = new double[getNumberOfParameters()];
double min = this.min();
double max = this.max();
double[] p = getParamListValues();
double a = (i==0? min : p[i-1]);
double b = p[i];
double c = (i==p.length-1? max : p[i+1]);
if(i>0) {
if(x<b) deriv[i-1] = (x-b)/((b-a)*(b-a));
else if(x==a) deriv[i-1] = 0.5/(a-b);
else deriv[i-1] = 0;
}
if(i==0) {
if(b<x && x<c) deriv[i] = (c-x)/((c-b)*(c-b));
else if(x==b) deriv[i] = 0.5/(c-b);
else deriv[i] = 0;
} else if(i==p.length-1) {
if(a<x && x<b) deriv[i] = (a-x)/((b-a)*(b-a));
else if(x==b) deriv[i] = 0.5/(a-b);
else deriv[i] = 0;
} else {
if(a<x && x<b) deriv[i] = (a-x)/((b-a)*(b-a));
else if(b<x && x<c) deriv[i] = (c-x)/((c-b)*(c-b));
else if(x==b) deriv[i] = 0.5/(a-b) + 0.5/(c-b);
else deriv[i] = 0;
}
if(i<p.length-1) {
if(b<x && x<c) deriv[i+1] = (x-b)/((c-b)*(c-b));
else if(x==c) deriv[i+1] = 0.5/(c-b);
else deriv[i+1] = 0;
}
return deriv;
}
public double[] deriv_greq(int i, double x) {
double[] deriv = new double[getNumberOfParameters()];
double min = this.min();
double[] p = getParamListValues();
double a = (i==0? min : p[i-1]);
double b = p[i];
if(i>0) {
if(a<x && x<b) deriv[i-1] = (x-b)/((b-a)*(b-a));
else if(x==a) deriv[i-1] = 0.5/(a-b);
else deriv[i-1] = 0;
if(a<x && x<b) deriv[i] = (a-x)/((b-a)*(b-a));
else if(x==b) deriv[i] = 0.5/(a-b);
else deriv[i] = 0;
}
return deriv;
}
public double[] deriv_smeq(int i, double x) {
double[] deriv = new double[getNumberOfParameters()];
double max = this.max();
double[] p = getParamListValues();
double b = p[i];
double c = (i==p.length-1? max : p[i+1]);
if(i<p.length-1) {
if(b<x && x<c) deriv[i] = (c-x)/((c-b)*(c-b));
else if(x==b) deriv[i] = 0.5/(c-b);
else deriv[i] = 0;
if(b<x && x<c) deriv[i+1] = (x-b)/((c-b)*(c-b));
else if(x==c) deriv[i+1] = 0.5/(c-b);
else deriv[i+1] = 0;
}
return deriv;
}
public double[] deriv_center(int i) {
double[] deriv = new double[getNumberOfParameters()];
double[] p = getParamListValues();
if(i==0 || i==p.length-1) deriv[i] = 0.5;
else deriv[i] = 1;
return deriv;
}
public double[] deriv_basis(int i) {
double[] deriv = new double[getNumberOfParameters()];
double[] p = getParamListValues();
if(i>0) deriv[i-1] = -1;
if(i<p.length-1) deriv[i+1] = 1;
return deriv;
}
public boolean test () {
double min = this.min();
double max = this.max();
double[] p = getParamListValues();
return ( p.length>1 && p[0]>min && p[p.length-1]<max && sorted(p)
);
}
public void update() {
if(!isAdjustable()) return;
double[] pos = get();
double[] desp = getDesp();
boolean[] adj = getAdjustable();
double min = this.min();
double max = this.max();
double step = this.step();
double[] p = getParamListValues();
pos = sortedUpdate(pos,desp,adj);
if(pos[0]<=min) {
pos[0]=min+step;
for(int i=1;i<p.length; i++) {
if(pos[i]<=pos[i-1]) pos[i] = pos[i-1]+step;
else break;
}
}
if(pos[p.length-1]>=max) {
pos[p.length-1]=max-step;
for(int i=p.length-2; i>=0; i--) {
if(pos[i]>=pos[i+1]) pos[i] = pos[i+1]-step;
else break;
}
}
updateValues(pos);
}
public String getEqualJavaCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " if(i==0 && x<p[0]) return 1;"+eol;
code += " if(i==p.length-1 && x>p[p.length-1]) return 1;"+eol;
code += " double a = (i==0? min : p[i-1]);"+eol;
code += " double b = p[i];"+eol;
code += " double c = (i==p.length-1? max : p[i+1]);"+eol;
code += " return (a<x && x<=b? (x-a)/(b-a) : (b<x && x<c? (c-x)/(c-b) : 0));"+eol;
return code;
}
public String getGreqJavaCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " if(i==0) return 1;"+eol;
code += " double a = (i==0? min : p[i-1]);"+eol;
code += " double b = p[i];"+eol;
code += " return (x<a? 0 : (x>b? 1 : (x-a)/(b-a) ));"+eol;
return code;
}
public String getSmeqJavaCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " if(i==p.length-1) return 1;"+eol;
code += " double b = p[i];"+eol;
code += " double c = (i==p.length-1? max : p[i+1]);"+eol;
code += " return (x<b? 1 : (x>c? 0 : (c-x)/(c-b) ));"+eol;
return code;
}
public String getCenterJavaCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " return (i==0? (min+p[0])/2 : (i==p.length-1? (max+p[p.length-1])/2 : p[i]));"+eol;
return code;
}
public String getBasisJavaCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " double a = (i==0 ? min : p[i-1]);"+eol;
code += " double c = (i==p.length-1? max : p[i+1]);"+eol;
code += " return (c-a);"+eol;
return code;
}
public String getEqualCCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " if(i==0 && x<p[0]) return 1;"+eol;
code += " if(i==length-1 && x>p[length-1]) return 1;"+eol;
code += " double a = (i==0? min : p[i-1]);"+eol;
code += " double b = p[i];"+eol;
code += " double c = (i==length-1? max : p[i+1]);"+eol;
code += " return (a<x && x<=b? (x-a)/(b-a) : (b<x && x<c? (c-x)/(c-b) : 0));"+eol;
return code;
}
public String getGreqCCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " if(i==0) return 1;"+eol;
code += " double a = (i==0? min : p[i-1]);"+eol;
code += " double b = p[i];"+eol;
code += " return (x<a? 0 : (x>b? 1 : (x-a)/(b-a) ));"+eol;
return code;
}
public String getSmeqCCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " if(i==length-1) return 1;"+eol;
code += " double b = p[i];"+eol;
code += " double c = (i==length-1? max : p[i+1]);"+eol;
code += " return (x<b? 1 : (x>c? 0 : (c-x)/(c-b) ));"+eol;
return code;
}
public String getCenterCCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " return (i==0? (min+p[0])/2 : (i==length-1? (max+p[length-1])/2 : p[i]));"+eol;
return code;
}
public String getBasisCCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " double a = (i==0 ? min : p[i-1]);"+eol;
code += " double c = (i==length-1? max : p[i+1]);"+eol;
code += " return (c-a);"+eol;
return code;
}
public String getEqualCppCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " if(i==0 && x<p[0]) return 1;"+eol;
code += " if(i==length-1 && x>p[length-1]) return 1;"+eol;
code += " double a = (i==0? min : p[i-1]);"+eol;
code += " double b = p[i];"+eol;
code += " double c = (i==length-1? max : p[i+1]);"+eol;
code += " return (a<x && x<=b? (x-a)/(b-a) : (b<x && x<c? (c-x)/(c-b) : 0));"+eol;
return code;
}
public String getGreqCppCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " if(i==0) return 1;"+eol;
code += " double a = (i==0? min : p[i-1]);"+eol;
code += " double b = p[i];"+eol;
code += " return (x<a? 0 : (x>b? 1 : (x-a)/(b-a) ));"+eol;
return code;
}
public String getSmeqCppCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " if(i==length-1) return 1;"+eol;
code += " double b = p[i];"+eol;
code += " double c = (i==length-1? max : p[i+1]);"+eol;
code += " return (x<b? 1 : (x>c? 0 : (c-x)/(c-b) ));"+eol;
return code;
}
public String getCenterCppCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " return (i==0? (min+p[0])/2 : (i==length-1? (max+p[length-1])/2 : p[i]));"+eol;
return code;
}
public String getBasisCppCode() {
String eol = System.getProperty("line.separator", "\n");
String code = "";
code += " double a = (i==0 ? min : p[i-1]);"+eol;
code += " double c = (i==length-1? max : p[i+1]);"+eol;
code += " return (c-a);"+eol;
return code;
}
}