yyzsamplerecognise3.cpp
来自「某个实验事编写粗糙集智能信息处理的程序」· C++ 代码 · 共 2,002 行 · 第 1/3 页
CPP
2,002 行
// Liesamplerecognise.cpp : implementation of the CLieSampleRecognise class
//
#include "stdafx.h"
#include "../Rset.h"
//#include "msflexgrid.h"
//#include "afximpl.h"
#include "yyzsamplerecognise3.h"
#include "fstream.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MAX 30
/////////////////////////////////////////////////////////////////////////////
// CLieSampleRecognise
/////////////////////////////////////////////////////////////////////////////
// CLieSampleRecognise construction/destruction
CLieSampleRecogniseYyz3::CLieSampleRecogniseYyz3()
{
// TODO: add one-time construction code here
pIntTable = NULL;
pFloatTable = NULL;
pStringTable = NULL;
pRuleTable = NULL;
pBlockTable = NULL;
pRecogniseResultTable = NULL;
pAttName = NULL;
pDataType = NULL;
pAttReduce = NULL;
struCutRecord = NULL;
iChar = 0;
iFloat = 0;
iInteger = 0;
iRecordNum = 0;
iAttNum = 0;
iRuleNum = 0;
iBlockNum = 0;
iTestNum = 0;
iStringCol = 0;
iStringRow = 0;
iStage = -1;
iTestConflict = 0;
iTestRight = 0;
iTestError = 0;
iDentifyRight = 0;
iDentifyError = 0;
iDentifyNone = 0;
bDiscrete = FALSE;
bIncompletion = FALSE;
bSaveTempResult = FALSE;
bBatch = FALSE;
bCuts = FALSE;
bTest = FALSE;
bBlock = FALSE;
iCol = 0;
iRow = 0;
atb=0;
}
CLieSampleRecogniseYyz3::~CLieSampleRecogniseYyz3()
{
TRACE("~liesamplerecognise\n");
// TODO: Add your specialized code here and/or call the base class
//释放pStringTable
if(pStringTable != NULL)
{
for(int i = 0;i < iStringRow;i++)
{
for(int j = 0;j < iStringCol;j++)
delete[] pStringTable[i][j];
}//end for
for(i = 0;i < iStringRow;i++)
delete[] pStringTable[i];
delete[] pStringTable;
}//end if
//释放pFloatTable
if(pFloatTable != NULL)
{
for(int i = 0;i < iRecordNum;i++)
delete[] pFloatTable[i];
delete[] pFloatTable;
}//end if
//释放pIntTable
if(pIntTable != NULL)
{
for(int i = 0;i < iRecordNum;i++)
delete[] pIntTable[i];
delete[] pIntTable;
}//end if
//释放pAttName
if(pAttName != NULL)
{
for(int i = 0;i < iAttNum+1;i++)
delete[] pAttName[i];
delete[] pAttName;
}//end if
//释放pDataType
if(pDataType != NULL)
{
for(int i = 0;i < iAttNum+1;i++)
delete[] pDataType[i];
delete[] pDataType;
}
//释放struCutRecord
struct CutRecord* pHead;
while(struCutRecord != NULL)
{
pHead = struCutRecord->p;
for(int i = 0;i < struCutRecord->iCuts;i++)
delete[] struCutRecord->cpCut[i];
delete[] struCutRecord->cpCut;
delete struCutRecord;
struCutRecord = pHead;
}
//释放pRuleTable
if(pRuleTable != NULL)
{
for(int i = 0;i < iRuleNum;i++)
{
for(int j = 0;j < iAttNum+4;j++)
delete[] pRuleTable[i][j];
}//end for
for(i = 0;i < iRuleNum;i++)
delete[] pRuleTable[i];
delete[] pRuleTable;
}//end if
//释放pBlockTable
if(pBlockTable != NULL)
{
for(int i = 0;i < iBlockNum;i++)
{
for(int j = 0;j < iAttNum+1;j++)
delete[] pBlockTable[i][j];
}//end for
for(i = 0;i < iBlockNum;i++)
delete[] pBlockTable[i];
delete[] pBlockTable;
}//end if
if(pRecogniseResultTable!=NULL)
{
for(int i=0;i<iTestNum;i++)
{
delete[] pRecogniseResultTable[i][0];
delete[] pRecogniseResultTable[i][1];
delete[] pRecogniseResultTable[i];
}
delete [] pRecogniseResultTable;
}
if(atb)
delete[] atb;
}
/////////////////////////////////////////////////////////////////////////////
// CLieSampleRecognise serialization
/////////////////////////////////////////////////////////////////////////////
// CLieSampleRecognise diagnostics
#ifdef _DEBUG
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLieSampleRecognise commands
BOOL CLieSampleRecogniseYyz3::LoadRuleFile(LPCTSTR lpszPathName)
{
TRACE("load rule file\n");
FILE* fp;
if((fp = fopen(lpszPathName,"r")) == NULL)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Couldn't open the file",MB_OK|MB_ICONSTOP);
return FALSE;
}//end if
fscanf(fp,"Style:%s\n",cStyle);
fscanf(fp,"Stage:%d\n",&iStage);
fscanf(fp,"Condition attributes number:%d\n",&iAttNum);
fscanf(fp,"The Number of Condition attributes deleted: %d\n",&atbcount);
char p;
fscanf(fp,"%c",&p);
while(p!=':')
fscanf(fp," %c",&p);
if(atbcount!=0)
{
atb=new int[atbcount];
for(int n=0;n<atbcount;n++)
fscanf(fp," %d\n",&atb[n]);
}
//////////////////////////////////
if(_stricmp(cStyle,"rule") == 0)
{
fscanf(fp," Rules number:%d\n",&iRuleNum);
fscanf(fp," Blocks number:%d\n",&iBlockNum);
if(atbcount!=0)
{
if(!SetAttName1(fp,atbcount+iAttNum+1,atb,atbcount))
{
fclose(fp);
return FALSE;
}
if(!SetDataType1(fp,atbcount+iAttNum+1,atb,atbcount))
{
fclose(fp);
return FALSE;
}
iAttNum=iAttNum+atbcount;
SetRuleTable1(fp,iAttNum+4,iRuleNum,atb,atbcount);
char temp[MAX];
if(fscanf(fp,"%s",temp) == -1)
{
fclose(fp);
return TRUE;
}
if(strcmp(temp,"[Blocks]") != 0)
{
fclose(fp);
return TRUE;
}
if(iBlockNum != 0)
{
bBlock = TRUE;
SetBlockTable1(fp,iAttNum+1,iBlockNum,atb,atbcount);
}
iStringCol = iAttNum + 1;
}
else
{
if(!SetAttName(fp,iAttNum+1))
{
fclose(fp);
return FALSE;
}
if(!SetDataType(fp,iAttNum+1))
{
fclose(fp);
return FALSE;
}
SetRuleTable(fp,iAttNum+4,iRuleNum);
char temp[MAX];
if(fscanf(fp,"%s",temp) == -1)
{
fclose(fp);
return TRUE;
}
if(strcmp(temp,"[Blocks]") != 0)
{
fclose(fp);
return TRUE;
}
if(iBlockNum != 0)
{
bBlock = TRUE;
SetBlockTable(fp,iAttNum+1,iBlockNum);
}
iStringCol = iAttNum + 1;
}
}//end if
else
{
AfxMessageBox("not correct rule file!",MB_OK|MB_ICONSTOP);
TRACE("not correct rule file!");
return FALSE;
}//end else
fclose(fp);
return TRUE;
}
BOOL CLieSampleRecogniseYyz3::LoadInputFile(LPCTSTR lpszPathName)
{
TRACE("InitDoc\n");
FILE* fp;
if((fp = fopen(lpszPathName,"r")) == NULL)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Couldn't open the file",MB_OK|MB_ICONSTOP);
return FALSE;
}//end if
fscanf(fp,"Style:%s\n",cStyle);
fscanf(fp,"Stage:%d\n",&iStage);
fscanf(fp,"Condition attributes number:%d\n",&iAttNum);
if(stricmp(cStyle,"input")==0)
{
fscanf(fp,"Tests number:%d\n",&iTestNum);
//释放pStringTable
if(pStringTable != NULL)
{
for(int i = 0;i < iStringRow;i++)
{
for(int j = 0;j < iStringCol;j++)
delete[] pStringTable[i][j];
}//end for
for(i = 0;i < iStringRow;i++)
delete[] pStringTable[i];
delete[] pStringTable;
}//end if
pStringTable = NULL;
if(atbcount!=0)
{
if(!SetAttName1(fp,iAttNum,0,0))
{
fclose(fp);
return FALSE;
}
if(!SetDataType1(fp,iAttNum,0,0))
{
fclose(fp);
return FALSE;
}
SetStringTable(fp,iAttNum,iTestNum);
iStringCol = iAttNum;
iStringRow = iTestNum;
}
else
{
if(!SetAttName(fp,iAttNum))
{
fclose(fp);
return FALSE;
}
if(!SetDataType(fp,iAttNum))
{
fclose(fp);
return FALSE;
}
SetStringTable(fp,iAttNum,iTestNum);
iStringCol = iAttNum;
iStringRow = iTestNum;
}
}
else
{
AfxMessageBox("Line 1 of the file has error!",MB_OK|MB_ICONSTOP);
fclose(fp);
return FALSE;
}//end else
fclose(fp);
return TRUE;
}
BOOL CLieSampleRecogniseYyz3::LoadTestFile(LPCTSTR lpszPathName)
{
TRACE("InitDoc\n");
FILE* fp;
if((fp = fopen(lpszPathName,"r")) == NULL)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Couldn't open the file",MB_OK|MB_ICONSTOP);
return FALSE;
}//end if
fscanf(fp,"Style:%s\n",cStyle);
fscanf(fp,"Stage:%d\n",&iStage);
fscanf(fp,"Condition attributes number:%d\n",&iAttNum);
if(_stricmp(cStyle,"test") == 0)
{
fscanf(fp,"Tests number:%d\n",&iTestNum);
//释放pStringTable
if(pStringTable != NULL)
{
for(int i = 0;i < iStringRow;i++)
{
for(int j = 0;j < iStringCol;j++)
delete[] pStringTable[i][j];
}//end for
for(i = 0;i < iStringRow;i++)
delete[] pStringTable[i];
delete[] pStringTable;
}//end if
pStringTable = NULL;
//改变了函数的数值
if(atbcount!=0)
{
if(!SetAttName1(fp,iAttNum+1,0,0))
{
fclose(fp);
return FALSE;
}
if(!SetDataType1(fp,iAttNum+1,0,0))
{
fclose(fp);
return FALSE;
}
SetStringTable(fp,iAttNum+1,iTestNum);
iStringCol = iAttNum + 1;
iStringRow = iTestNum;
}
else
{
if(!SetAttName(fp,iAttNum+1))
{
fclose(fp);
return FALSE;
}
if(!SetDataType(fp,iAttNum+1))
{
fclose(fp);
return FALSE;
}
SetStringTable(fp,iAttNum+1,iTestNum);
iStringCol = iAttNum + 1;
iStringRow = iTestNum;
}
}
else
{
AfxMessageBox("Line 1 of the file has error!",MB_OK|MB_ICONSTOP);
fclose(fp);
return FALSE;
}//end else
fclose(fp);
return TRUE;
}
BOOL CLieSampleRecogniseYyz3::SetStringTable(FILE* fp, int column, int row)
{
TRACE("SetStringTable\n");
int i,j;
if(pStringTable == NULL)
{
try
{
pStringTable = new char**[row];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory12!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
for(i = 0;i < row;i++)
{
try
{
pStringTable[i] = new char*[column];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory0!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
for(j = 0;j < column;j++)
{
try
{
pStringTable[i][j] = new char[MAX];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory1!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
strcpy(pStringTable[i][j]," ");
}//end for
}//end for
}//end if
for(i = 0;i < row;i++)
for(j = 0;j < column;j++)
fscanf(fp,"%s",pStringTable[i][j]);
return TRUE;
}
BOOL CLieSampleRecogniseYyz3::SetAttName1(FILE* fp, int count,int *att,int atbcount)
{
TRACE("set att name\n");
int i,j,k=0;
if(pAttName == NULL)
{
try
{
pAttName = new char*[count];
}
catch(CMemoryException* e)
{
TRACE("memeory error 1\n");
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of the memory!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
for(i=0;i < count;i++)
{
try
{
pAttName[i]=new char[MAX];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of the memory!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
}//end for
}//end if
for(i=0;i < count;i++)
{
for(j=0;j<atbcount;j++)
{
if(i!=atb[j])
k++;
}
if(k==atbcount)
fscanf(fp,"%s",pAttName[i]);
else
strcpy( pAttName[i],"*");
k=0;
}
return TRUE;
}
BOOL CLieSampleRecogniseYyz3::SetDataType1(FILE *fp, int count,int *att,int atbcount)
{
TRACE("SetDatType\n");
int i,j,k=0;
if(pDataType == NULL)
{
try
{
pDataType = new char*[count];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of the memory!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
for(i = 0;i < count;i++)
{
try
{
pDataType[i]=new char[MAX];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of the memory!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
}//end for
}//end if
//for(i = 0;i < count;i++)
// fscanf(fp,"%s",pDataType[i]);
for(i=0;i < count;i++)
{
for(j=0;j<atbcount;j++)
{
if(i!=atb[j])
k++;
}
if(k==atbcount)
fscanf(fp,"%s",pDataType[i]);
else
strcpy(pDataType[i],"Float");
k=0;
}
return TRUE;
}
int CLieSampleRecogniseYyz3::GetIncompletion()
{
TRACE("GetIncompleteion\n");
for(int i = 0;i < iRecordNum;i++)
{
for(int j = 0;j < iAttNum+1;j++)
{
if(strcmp(pStringTable[i][j],"?") == 0)
return 1;
}
}
return 0;
}
int CLieSampleRecogniseYyz3::GetDiscrete()
{
TRACE("GetDiscrete\n");
for(int i = 0;i < iAttNum;i++)
{
if(_stricmp(pDataType[i],"Float") == 0)
iFloat++;
if(_stricmp(pDataType[i],"Integer") == 0)
iInteger++;
if(_stricmp(pDataType[i],"String") == 0)
iChar++;
}
if(iFloat != 0 || iChar != 0)
return 1;
return 0;
}
BOOL CLieSampleRecogniseYyz3::SetIntegerTable(int column, int row)
{
TRACE("SetInitTable\n");
AfxMessageBox("GHJGHJLGH'JH");
int i,j;
if(pIntTable == NULL)
{
try
{
pIntTable = new int*[row];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory2!",MB_OK|MB_ICONSTOP);
e->Delete();
return FALSE;
}
for(i = 0;i < row;i++)
{
try
{
pIntTable[i] = new int[column];
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?