//+++++++++++++++++++++++++++++++++++++++++++++++++++++ // File automatically generated by Xfuzzy - DO NOT EDIT //+++++++++++++++++++++++++++++++++++++++++++++++++++++ package pkg.xfl.family; import xfuzzy.lang.*; public class triangular extends Family { public triangular() { super("xfl","triangular"); Parameter single[] = new Parameter[0]; setSingleParameters(single); setParamListName("p"); setParamList(new Parameter[0]); } public int members() { double[] p = getParamListValues(); return p.length+2; } public double compute(int i, double x) { double min = this.min(); double max = this.max(); double[] p = getParamListValues(); double a = (i==0? min-1 : (i==1 ? min : p[i-2])); double b = (i==0? min : (i==p.length+1? max : p[i-1])); double c = (i==p.length? max : (i==p.length+1? max+1 : p[i])); 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 max = this.max(); double[] p = getParamListValues(); double a = (i==0? min-1 : (i==1 ? min : p[i-2])); double b = (i==0? min : (i==p.length+1? max : p[i-1])); return (x<a? 0 : (x>b? 1 : (x-a)/(b-a) )); } public double smallereq(int i, double x) { double min = this.min(); double max = this.max(); double[] p = getParamListValues(); double b = (i==0? min : (i==p.length+1? max : p[i-1])); double c = (i==p.length? max : (i==p.length+1? max+1 : p[i])); 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(); double b = (i==0? min : (i==p.length+1? max : p[i-1])); return b; } public double basis(int i) { double min = this.min(); double max = this.max(); double[] p = getParamListValues(); double a = (i<=1 ? min : p[i-2]); double c = (i>=p.length? max : p[i]); 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-1 : (i==1 ? min : p[i-2])); double b = (i==0? min : (i==p.length+1? max : p[i-1])); double c = (i==p.length? max : (i==p.length+1? max+1 : p[i])); if(i>=2) { if(a<x && x<b) deriv[i-2] = (x-b)/((b-a)*(b-a)); else if(x==a) deriv[i-2] = 0.5/(a-b); else deriv[i-2] = 0; } if(i>=1 && i<=p.length) { if(a<x && x<b) deriv[i-1] = (a-x)/((b-a)*(b-a)); else if(b<x && x<c) deriv[i-1] = (c-x)/((c-b)*(c-b)); else if(x==b) deriv[i-1] = 0.5/(a-b) + 0.5/(c-b); else deriv[i-1] = 0; } if(i<p.length) { if(b<x && x<c) deriv[i] = (x-b)/((c-b)*(c-b)); else if(x==c) deriv[i] = 0.5/(c-b); else deriv[i] = 0; } return deriv; } public double[] deriv_greq(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-1 : (i==1 ? min : p[i-2])); double b = (i==0? min : (i==p.length+1? max : p[i-1])); if(i>=2) { if(a<x && x<b) deriv[i-2] = (x-b)/((b-a)*(b-a)); else if(x==a) deriv[i-2] = 0.5/(a-b); else deriv[i-2] = 0; } if(i>=1 && i<=p.length) { if(a<x && x<b) deriv[i-1] = (a-x)/((b-a)*(b-a)); else if(x==b) deriv[i-1] = 0.5/(a-b); else deriv[i-1] = 0; } return deriv; } public double[] deriv_smeq(int i, double x) { double[] deriv = new double[getNumberOfParameters()]; double min = this.min(); double max = this.max(); double[] p = getParamListValues(); double b = (i==0? min : (i==p.length+1? max : p[i-1])); double c = (i==p.length? max : (i==p.length+1? max+1 : p[i])); if(i>=1 && i<=p.length) { if(b<x && x<c) deriv[i-1] = (c-x)/((c-b)*(c-b)); else if(x==b) deriv[i-1] = 0.5/(c-b); else deriv[i-1] = 0; } if(i<p.length) { if(b<x && x<c) deriv[i] = (x-b)/((c-b)*(c-b)); else if(x==c) deriv[i] = 0.5/(c-b); else deriv[i] = 0; } return deriv; } public double[] deriv_center(int i) { double[] deriv = new double[getNumberOfParameters()]; double[] p = getParamListValues(); if(i>=1 && i<=p.length) deriv[i-1] = 1; return deriv; } public double[] deriv_basis(int i) { double[] deriv = new double[getNumberOfParameters()]; double[] p = getParamListValues(); if(i>1) deriv[i-2] = -1; if(i<p.length) deriv[i] = 1; return deriv; } public boolean test () { double min = this.min(); double max = this.max(); double[] p = getParamListValues(); return ( p.length==0 || (p.length>0 && 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(); if(p.length == 0) return; 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 += " double a = (i==0? min-1 : (i==1 ? min : p[i-2]));"+eol; code += " double b = (i==0? min : (i==p.length+1? max : p[i-1]));"+eol; code += " double c = (i==p.length? max : (i==p.length+1? max+1 : p[i]));"+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 += " double a = (i==0? min-1 : (i==1 ? min : p[i-2]));"+eol; code += " double b = (i==0? min : (i==p.length+1? max : p[i-1]));"+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 += " double b = (i==0? min : (i==p.length+1? max : p[i-1]));"+eol; code += " double c = (i==p.length? max : (i==p.length+1? max+1 : p[i]));"+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 += " double b = (i==0? min : (i==p.length+1? max : p[i-1]));"+eol; code += " return b;"+eol; return code; } public String getBasisJavaCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " double a = (i<=1 ? min : p[i-2]);"+eol; code += " double c = (i>=p.length? max : p[i]);"+eol; code += " return (c-a);"+eol; return code; } public String getEqualCCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " double a = (i==0? min-1 : (i==1 ? min : p[i-2]));"+eol; code += " double b = (i==0? min : (i==length+1? max : p[i-1]));"+eol; code += " double c = (i==length? max : (i==length+1? max+1 : p[i]));"+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 += " double a = (i==0? min-1 : (i==1 ? min : p[i-2]));"+eol; code += " double b = (i==0? min : (i==length+1? max : p[i-1]));"+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 += " double b = (i==0? min : (i==length+1? max : p[i-1]));"+eol; code += " double c = (i==length? max : (i==length+1? max+1 : p[i]));"+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 += " double b = (i==0? min : (i==length+1? max : p[i-1]));"+eol; code += " return b;"+eol; return code; } public String getBasisCCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " double a = (i<=1 ? min : p[i-2]);"+eol; code += " double c = (i>=length? max : p[i]);"+eol; code += " return (c-a);"+eol; return code; } public String getEqualCppCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " double a = (i==0? min-1 : (i==1 ? min : p[i-2]));"+eol; code += " double b = (i==0? min : (i==length+1? max : p[i-1]));"+eol; code += " double c = (i==length? max : (i==length+1? max+1 : p[i]));"+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 += " double a = (i==0? min-1 : (i==1 ? min : p[i-2]));"+eol; code += " double b = (i==0? min : (i==length+1? max : p[i-1]));"+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 += " double b = (i==0? min : (i==length+1? max : p[i-1]));"+eol; code += " double c = (i==length? max : (i==length+1? max+1 : p[i]));"+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 += " double b = (i==0? min : (i==length+1? max : p[i-1]));"+eol; code += " return b;"+eol; return code; } public String getBasisCppCode() { String eol = System.getProperty("line.separator", "\n"); String code = ""; code += " double a = (i<=1 ? min : p[i-2]);"+eol; code += " double c = (i>=length? max : p[i]);"+eol; code += " return (c-a);"+eol; return code; } }