#include #include #include #include struct Fzb { int yyz; //语言之 int ly; //论域 float lsd; //隶属值 struct Fzb *next; }; class Fuzzy { private: int g[49][3]; //定义了规则库,用于函数间调用 float R[169][13]; //定义了关系矩阵,用于函数间调用 float H[13][13]; //定义了查询表矩阵,用于函数间的调用 public: struct Fzb * Creatfzb(); //建立赋值表函数 void Printfzb(struct Fzb *head1); //输出赋值表 void Inputgzk(); //导入规则库 void jlgx(struct Fzb*E,struct Fzb*EC,struct Fzb*U); //建立关系矩阵 void jlcxb(struct Fzb*E,struct Fzb*EC,struct Fzb*U); //建立查询表 }; struct Fzb *Fuzzy::Creatfzb() { float f[8][14]={ {0,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6}, {-3,1,0.5,0,0,0,0,0,0,0,0,0,0,0}, {-2,0,0.5,1,0.5,0,0,0,0,0,0,0,0,0}, {-1,0,0,0,0.5,1,0.5,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0.5,1,0.5,0,0,0,0,0}, {1,0,0,0,0,0,0,0,0.5,1,0.5,0,0,0}, {2,0,0,0,0,0,0,0,0,0,0.5,1,0.5,0}, {3,0,0,0,0,0,0,0,0,0,0,0,0.5,1}}; //默认输入赋值表 int i,k,j; fstream in,out; struct Fzb *head,*p1,*p2; int n=0; head=NULL; p1=new(Fzb); for(k=1;k<8;k++) for(j=1;j<14;j++) { n++; p1->lsd=f[k][j]; p1->yyz=(int)f[k][0]; p1->ly=(int)f[0][j]; if(1==n) head=p1; p2=p1; p1=new(Fzb); p2->next=p1; } p2->next=NULL; int m=0; return (head); } void Fuzzy::Inputgzk() { int G[49][3]={ {-3,-3,-3},{-3,-2,-3},{-3,-1,-3},{-3,0,-3}, {-3,1,-2},{-3,2,0},{-3,3,0},{-2,-3,-3}, {-2,-2,-3},{-2,-1,-3},{-2,0,-3},{-2,1,-2}, {-2,2,0},{-2,3,0},{-1,-3,-2},{-1,-2,-2}, {-1,-1,-2},{-1,0,-2},{-1,1,0},{-1,2,1}, {-1,3,1},{0,-3,-2},{0,-2,-2},{0,-1,-1}, {0,0,0},{0,1,1},{0,2,2},{0,3,2},{1,-3,-1}, {1,-2,-1},{1,-1,0},{1,0,2},{1,1,2},{1,2,2}, {1,3,2},{2,-3,0},{2,-2,0},{2,-1,2},{2,0,3}, {2,1,3},{2,2,3},{2,3,3},{3,-3,0},{3,-2,0}, {3,-1,2},{3,0,3},{3,1,3},{3,2,3},{3,3,3}}; //默认输入规则库 int i,j; int n=0; for(i=0;i<49;i++) for(j=0;j<3;j++) { n++; g[i][j]=G[i][j]; cout<yyz+4][p->ly+7]=p->lsd; p=p->next; } p=head1; while (NULL!=p) { a[0][p->ly+7]=p->ly; p=p->next; } p=head1; while (NULL!=p) { a[p->yyz+4][0]=p->yyz; p=p->next; } a[0][0]=0; int k; for(i=0;i<8;i++) //用于输出标准形式的赋值表 { n=0; for(j=0;j<14;j++) { n++; if(0==j&&0!=i) { switch((int)a[i][j]) { case -3: cout<yyz==g[i][0]) a[k++]=p1->lsd; p1=p1->next; } while(NULL!=p2) { if(p2->yyz==g[i][1]) b[m++]=p2->lsd; p2=p2->next; } while(NULL!=p3) { if(p3->yyz==g[i][2]) c[n++]=p3->lsd; p3=p3->next; } for(j=0;j<13;j++) for(l=0;l<13;l++) { if(a[j]>b[l]) R1[z++]=b[l]; else R1[z++]=a[j]; } for(j=0;j<169;j++) for(l=0;l<13;l++) { if(R1[j]>c[l]) R2[j][l]=c[l]; else R2[j][l]=R1[j]; } if(0==i) for(j=0;j<169;j++) //以下于对所有规则对应的关系矩阵作加法 for(l=0;l<13;l++) { R[j][l]=R2[j][l]; } for(j=0;j<169;j++) for(l=0;l<13;l++) { if(R2[j][l]>R[j][l]) R[j][l]=R2[j][l]; } } i=0; for(j=0;j<169;j++) for(l=0;l<13;l++) { i++; cout<ly&&mlsd) { n=p1->yyz; m=p1->lsd; } } else { if(e==p1->ly&&m<=p1->lsd) { n=p1->yyz; m=p1->lsd; } } p1=p1->next; } p1=E; while (NULL!=p1) { if(n==p1->yyz) a[l++]=p1->lsd; p1=p1->next; } m=0; while (NULL!=p2) { if(ec<0) { if(ec==p2->ly&&mlsd) { n=p2->yyz; m=p2->lsd; } } else { if(ec==p2->ly&&m<=p2->lsd) { n=p2->yyz; m=p2->lsd; } } p2=p2->next; } p2=EC; l=0; while (NULL!=p2) { if(n==p2->yyz) b[l++]=p2->lsd; p2=p2->next; } /* cout< "; cin>>jg; switch(jg) { case 1: cout<<"*************************************************************"<