📄 lietestdlg.cpp
字号:
{
strcpy(pRuleTable[i][j],"-");
k++;
}
else
fscanf(fp,"%s",pRuleTable[i][j]);
}
}
return TRUE;
}
BOOL CLieTestDlg::SetBlockTable(FILE *fp, int column, int row)
{
int i,j;
if(pBlockTable == NULL)
{
try
{
pBlockTable = new char**[row];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
for(i = 0;i < row;i++)
{
try
{
pBlockTable[i] = new char*[column];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
for(j = 0;j < column;j++)
{
try
{
pBlockTable[i][j] = new char[MAX];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
strcpy(pBlockTable[i][j]," ");
}//end for
}//end for
}//end if
for(i = 0;i < row;i++)
{
int k=0;
for(j=0;j < column;j++)
{
if(j==pReductedAttr[k])
{
strcpy(pBlockTable[i][j],"-");
k++;
}
else
fscanf(fp,"%s",pBlockTable[i][j]);
}
}
return TRUE;
}
void CLieTestDlg::SampleRecogniseMany()
{//多数优先策略
int j,k;
int* temp=NULL;
int temp1 = -1;
float reliability;
int totalnum;
int coveragenum;
int n = 0;
int pos;
char* d=NULL;
if((d = new char[MAX])==0){
AfxMessageBox("Out of Memory!");
return;
}
if((temp = new int[iRuleNum])==0){
AfxMessageBox("Out of Memory!");
return;
}
int MaxMatch=0;
CString tempstring;
CString trimstring;
CString compstring;
for(j = 0;j < iRuleNum;j++)
temp[j] = 0;//匹配规则序号初始化
for(j = 0;j < iRuleNum;j++)
{
if ( IsRuleAttAllNull(j) )
{//规则j为空
if( IsTestAttAllNull() )
{//测试样本为空
temp[j]=1;//匹配成功
temp1=j;//匹配规则序号
n++;//n初始化为0
// 此处continue已经没有意义
//因为规则集中已经不再有全为空的情况.
//而其余的规则肯定和该测试(识别)数据不匹配
}
break;
}
temp[j]=Match(j);
if ( temp[j]>=1 )
n++;//统计匹配成功数目
if(temp[j]> MaxMatch)//统计最大匹配数目
{
MaxMatch=temp[j];
temp1=j;
}
}//end for(j)
if(n>0)
{
for(int x=0;x<iRuleNum;x++)
{//去除掉非最大匹配度的规则
if(temp[x]!=0 && MaxMatch>0 && temp[x]<MaxMatch )
{
temp[x]=0;
n--;//
}
if(temp[x]>=1)//temp[x]==MaxMatch
temp[x]=1;
}
}
if(n != 0 && bBlock)
{//还有规则并且有封锁事实
for(j = 0;j < iBlockNum;j++)
{
for(k = 0;k < iAttNum;k++)
{
if(strcmp(pBlockTable[j][k],"-") == 0)
continue;
tempstring = pBlockTable[j][k];
if(tempstring[0] == '[')
{
pos = tempstring.Find(',');
trimstring = tempstring.Left(pos);
trimstring.Remove('[');//得到下界
if(strcmp(trimstring,"*") != 0)
{//下界不为'*'时,如果下界大于测试属性,则退出
if(atof(trimstring) > atof(pTestData[k]))
break;
}//end if
trimstring = tempstring;
trimstring.Delete(0,pos+1);
trimstring.Remove(')');
trimstring.Remove(']');
if(strcmp(trimstring,"*") != 0)//上界不为'*'时,如果上界小于测试属性值,则退出
if(atof(trimstring) <= atof(pTestData[k]))
break;
}//end if
/* else if(tempstring[0] == '{')
{//?
int m = 0;
trimstring = tempstring;
trimstring.Delete(0,1);
pos = trimstring.Find(',');
while(pos != -1)
{
compstring = trimstring.Left(pos);
trimstring.Delete(0,pos+1);
if(strcmp(compstring,pTestData[k]) == 0)
{
m =1;
break;
}//end if
pos = trimstring.Find(',');
}//end while
if(m == 0)
{
trimstring.Remove('}');
if(strcmp(trimstring,pTestData[k]) != 0)
break;
}//end if
}//end if
*/
else
if(strcmp(pDataType[k],"String")==0)
{ //对字符串属性比较
if(strcmp(pTestData[k],pBlockTable[j][k])!=0)
break;
}
else//为离散化的值
if(atof(pBlockTable[j][k]) != atof(pTestData[k]))
break;//不等,不匹配
}//end for(k)
if(k == iAttNum)
{//对此第j条封锁事实匹配测试样本
trimstring = pBlockTable[j][iAttNum];// ~规则x
trimstring.Delete(0,5);//删除了" ~规则 "
if(temp[atoi(trimstring)] == 1)
{//如果此时对应的规则为匹配规则,则去除该规则
temp[atoi(trimstring)] = 0;
n--;
}//end if(temp[atoi(trimstring)] == 1)
}//end if(k == iAttNum)
}//end for(j)
}//end if(n != 0 && bBlock)
if(n == 0)
{//此时没有匹配规则
m_strResult = "未识别";
m_strRule = " ";
delete[] temp;
delete[] d;
return;
}//end if
if(n == 1)
{//只有一条规则匹配样例
for(j = 0;j < iRuleNum;j++)
{//找到改规则
if(temp[j] == 1)
{
temp1=j;
break;
}
}//end for
m_strResult = pRuleTable[j][iAttNum];//得到决策
m_strRule.Format("%d",temp1+1);//规则序号
delete[] temp;
delete[] d;
return;
}//end if
temp1 = -1;
for(j = 0;j < iRuleNum;j++)//此时存在好几种匹配.采用多数优先策略,见书165页
{
if(temp[j] == 1)
{
if(temp1 == -1)
{//第一个
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);//信任度
coveragenum = atoi(pRuleTable[j][iAttNum+2]);//覆盖样例数:a
totalnum = atoi(pRuleTable[j][iAttNum+3]);//条件覆盖数目:b
strcpy(d,pRuleTable[j][iAttNum]);//决策
}//end if
else
if(atof(d)==atof(pRuleTable[j][iAttNum])) //一致规则
{//一致的就选择覆盖度最大的
if(coveragenum<atoi(pRuleTable[j][iAttNum+2]))
{
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
}
else //对不一致的规则才处理,
{//以后
if(reliability == atof(pRuleTable[j][iAttNum+1]))
{//信任度相等
if(totalnum < atoi(pRuleTable[j][iAttNum+3]))
{//前一条规则的b值小于这条规则的b.重新赋值
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
}//end if
else
{//信任度不等
if(totalnum == atoi(pRuleTable[j][iAttNum+3]))
{//(1)
if(reliability < atof(pRuleTable[j][iAttNum+1]))
{//选取可信度大的规则
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
}//end if
else
{//(2)
if(totalnum < atoi(pRuleTable[j][iAttNum+3]))
{
if(reliability < atof(pRuleTable[j][iAttNum+1]))
{// //(2)中1. b小,信任度也小.选取后面一条规则
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
else
{//信任度大,
// if(coveragenum/(totalnum*totalnum) >
// atoi(pRuleTable[j][iAttNum+2])/(atoi(pRuleTable[j][iAttNum+3])*atoi(pRuleTable[j][iAttNum+3])))
if((float)(coveragenum*coveragenum)/totalnum <
(float)(atoi(pRuleTable[j][iAttNum+2])*atoi(pRuleTable[j][iAttNum+2]))/(float)atoi(pRuleTable[j][iAttNum+3]))
{
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
}//end else
}//end if
else
{//b大..(2)中2
if(reliability < atof(pRuleTable[j][iAttNum+1]))
{//信任度小
if((float)(coveragenum*coveragenum)/totalnum <
(float)(atoi(pRuleTable[j][iAttNum+2])*atoi(pRuleTable[j][iAttNum+2]))/(float)atoi(pRuleTable[j][iAttNum+3]))
{
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
}//end if
}//end else
}//end else
}//end else
}//end else
}//end if
}//end for(j)
m_strResult = d;
m_strRule.Format("%d",temp1+1);
delete[] temp;
delete[] d;
}
void CLieTestDlg::SampleRecogniseFew()
{//少数优先策略
int j,k;
int* temp=NULL;
int temp1 = -1;
float reliability;
int totalnum;
int coveragenum;
int n = 0;
int pos;
char* d=NULL;
d = new char[MAX];
if((temp = new int[iRuleNum])==0)
{
AfxMessageBox("Out of Memory!");
return;
}
int MaxMatch=0;
CString tempstring;
CString trimstring;
CString compstring;
for(j = 0;j < iRuleNum;j++)
temp[j] = 0;
for(j = 0;j < iRuleNum;j++)
{
if ( IsRuleAttAllNull(j) )
{//规则为空,测试的数据属性也为空
if( IsTestAttAllNull() )
{
temp[j]=1;
temp1=j;
n++;
// 此处continue已经没有意义
//因为规则集中已经不再有全为空的情况.
//而其余的规则肯定和该测试(识别)数据不匹配
}
break;
}
temp[j]=Match(j);
if ( temp[j]>=1 )
n++;
if(temp[j]> MaxMatch)
{
MaxMatch=temp[j];
temp1=j;
}
//end for
}//end for
if(n>0)
{
for(int x=0;x<iRuleNum;x++)
{
if(temp[x]!=0 && MaxMatch>0 && temp[x]<MaxMatch )
{
temp[x]=0;//考虑最长匹配
n--;
}
if(temp[x]>=1)
temp[x]=1;
}
}
if(n != 0 && bBlock)
{
for(j = 0;j < iBlockNum;j++)
{
for(k = 0;k < iAttNum;k++)
{
if(strcmp(pBlockTable[j][k],"-") == 0)
continue;
tempstring = pBlockTable[j][k];
if(tempstring[0] == '[')
{
pos = tempstring.Find(',');
trimstring = tempstring.Left(pos);
trimstring.Remove('[');
if(strcmp(trimstring,"*") != 0)
{
if(atof(trimstring) > atof(pTestData[k]))
break;
}//end if
trimstring = tempstring;
trimstring.Delete(0,pos+1);
trimstring.Remove(')');//去掉)
trimstring.Remove(']');//去掉]
if(strcmp(trimstring,"*") != 0)
if(atof(trimstring) <= atof(pTestData[k]))
break;
}//end if
/* else if(tempstring[0] == '{')
{
int m = 0;
trimstring = tempstring;
trimstring.Delete(0,1);
pos = trimstring.Find(',');
while(pos != -1)
{
compstring = trimstring.Left(pos);
trimstring.Delete(0,pos+1);
if(strcmp(compstring,pTestData[k]) == 0)
{
m =1;
break;
}//end if
pos = trimstring.Find(',');
}//end while
if(m == 0)
{
trimstring.Remove('}');
if(strcmp(trimstring,pTestData[k]) != 0)
break;
}//end if
}//end if
*/
else
if(strcmp(pDataType[k],"String")==0)
{
if(strcmp(pTestData[k],pBlockTable[j][k])!=0)
{//对字符串属性比较
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -