主函数
//https://www.cnblogs.com/realjimmy/p/12990630.html
int gscAction( void )
{
double THE;
double x_ff[4]={0,50,100,150};
double y_ff[4]={0,0.12,0.24,0.36};
double z_ff[7]={0,0.1,0.2,0.3,0.4,0.5,0.6};
int *R2tmp[7];
int R2[7][7] = {{ 6, 5, 4, 3, 2, 0, 0,},
{ 5, 4, 3, 2, 0, 0, 0,},
{ 4, 3, 2, 1, 0, 0, -2,},
{ 3, 2, 1, 0, -1, -3, -4,},
{ 2, 0, 0, -1, -2, -3, -4,},
{ 0, 0, 0, -2, -3, -4, -5,},
{ 0, 0, -2, -3, -4, -5, -6}};
int i;
for (i = 0; i < 7; i++)
{
R2tmp[i] = R2[i];
}
THE = THEfuzzy(GetTagDouble("CBRE"),GetTagDouble("CBRTRK"),x_ff,y_ff,z_ff,R2tmp,50,0.6,1);
SetTagDouble("CBINI",THE);
return 0;
}
子函数
/*模糊运算引擎*/
double THEfuzzy(double x,double y,double *x_ff,double *y_ff,double *z_ff,int **R2,double dea,double lmn,BOOL b)
{
double t1=0,t2=0,t3=0,t4=0,temp1=0,temp2=0;
double z,rst;
double x_f[2],y_f[2],z_f[4];
int x_n,y_n,z_n[4];
double f_max =100;
//函数调用方法
int rule[7][7];
int i = 0, j = 0;
printf("\r\n");
for (i = 0; i < 7; i++) {
for (j = 0; j < 7; j++) {
rule[i][j]=R2[i][j];
//printf("*%4d*", R2[i][j]);
}
//printf("\r\n");
}
//快调
if((x> x_ff[3])||(x<-x_ff[3]))
y=0;
if(x>-x_ff[3] && x=x_ff[3])
{
x_n=3; x_f[0]=0;
}
x_f[1]=f_max-x_f[0];
if(y>-y_ff[3] && y=y_ff[3])
{
y_n=3;
y_f[0]=0;
}
y_f[1]=f_max-y_f[0];
z_n[0]=rule[x_n-1+3][y_n-1+3];
z_n[1]=rule[x_n+3][y_n-1+3];
z_n[2]=rule[x_n-1+3][y_n+3];
z_n[3]=rule[x_n+3][y_n+3];
if(x_f[0]<=y_f[0])
z_f[0]=x_f[0];
else
z_f[0]=y_f[0];
if(x_f[1]<=y_f[0])
z_f[1]=x_f[1];
else
z_f[1]=y_f[0];
if(x_f[0]<=y_f[1])
z_f[2]=x_f[0];
else
z_f[2]=y_f[1];
if(x_f[1]<=y_f[1])
z_f[3]=x_f[1];
else
z_f[3]=y_f[1];
if(z_n[0]==z_n[1])
{
if(z_f[0]>z_f[1])
z_f[1]=0;
else
z_f[0]=0;
}
if(z_n[0]==z_n[2])
{
if(z_f[0]>z_f[2])
z_f[2]=0;
else
z_f[0]=0;
}
if(z_n[0]==z_n[3])
{
if(z_f[0]>z_f[3])
z_f[3]=0;
else
z_f[0]=0;
}
if(z_n[1]==z_n[2])
{
if(z_f[1]>z_f[2])
z_f[2]=0;
else
z_f[1]=0;
}
if(z_n[1]==z_n[3])
{
if(z_f[1]>z_f[3])
z_f[3]=0;
else
z_f[1]=0;
}
if(z_n[2]==z_n[3])
{
if(z_f[2]>z_f[3])
z_f[3]=0;
else
z_f[2]=0;
}
//printf("z_n1:%4.4f,z_n2:%4.4f,z_n3:%4.4f,z_n4:%4.4f \r\n",z_n[0],z_n[1],z_n[2],z_n[3]);
if(z_n[0]>=0)
t1= z_f[0]*z_ff[ z_n[0]];
else
t1=-z_f[0]*z_ff[-z_n[0]];
if(z_n[1]>=0)
t2= z_f[1]*z_ff[ z_n[1]];
else
t2=-z_f[1]*z_ff[-z_n[1]];
if(z_n[2]>=0)
t3= z_f[2]*z_ff[ z_n[2]];
else
t3=-z_f[2]*z_ff[-z_n[2]];
if(z_n[3]>=0)
t4= z_f[3]*z_ff[ z_n[3]];
else
t4=-z_f[3]*z_ff[-z_n[3]];
//printf("t1:%4.4f,t2:%4.4f,t3:%4.4f,t4:%4.4f \r\n",t1,t2,t3,t4);
temp1=t1+t2+t3+t4;
temp2=z_f[0]+z_f[1]+z_f[2]+z_f[3];
//printf("temp1:%4.4f,temp2:%4.4f \r\n",temp1,temp2);
if(temp2!=0)
z=temp1/temp2;
else
z=0;
//死区
if(x< dea && x>-dea)
z=0;
//printf("z:%4.4f \r\n",z);
if(b==1)
rst = lmn +z;
else
rst = lmn;
return rst;
}