⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdlg.cpp

📁 某个实验事编写粗糙集智能信息处理的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//

#include "stdafx.h"
#include "RSet.h"
#include "SpecialFileDialog.h"
#include "TestDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog


CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestDlg)
	strPathName = _T("");
	m_nFew = -1;
	m_nHand = -1;
	m_strResult = _T("");
	m_strRule = _T("");
	//}}AFX_DATA_INIT
}


void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestDlg)
	DDX_Text(pDX, IDC_EDIT_PATHNAME, strPathName);
	DDX_Control(pDX, IDC_MSFLEXGRID1, m_FlexGrid);
	DDX_Radio(pDX, IDC_RADIO_FEW, m_nFew);
	DDX_Radio(pDX, IDC_RADIO_HAND, m_nHand);
	DDX_Text(pDX, IDC_EDIT_RESULT, m_strResult);
	DDX_Text(pDX, IDC_EDIT_RULE, m_strRule);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
	//{{AFX_MSG_MAP(CTestDlg)
	ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
	ON_BN_CLICKED(IDC_RADIO_FILE, OnRadioFile)
	ON_BN_CLICKED(IDC_RADIO_HAND, OnRadioHand)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers

BOOL CTestDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	int col;
	int length;
	if(bTest)
		SetWindowText("测试");
	else
		SetWindowText("识别");
	
	m_nHand = 0;
	m_nFew = 0;
	UpdateData(FALSE);

	m_FlexGrid.SetRows(2);
	if(bTest)
		col = iAttNum+1;
	else
		col = iAttNum;

	m_FlexGrid.SetCols(col);
	
	
	for(int i = 0;i < col;i++)
	{
		m_FlexGrid.SetColAlignment(i,4);
		length = strlen(pAttName[i]);
		if((120*length+280) < 900)
			length = 900;
		m_FlexGrid.SetTextMatrix(0,i,pAttName[i]);
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTestDlg::OnButtonBrowse() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CSpecialFileDialog m_FileDlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		                    "Roughset Files (*.rs)|*.rs|All Files (*.*)|*.*||");
	m_FileDlg.m_ofn.lpstrTitle="浏览";
	if(m_FileDlg.DoModal()==IDOK)
	{
		strPathName = m_FileDlg.GetPathName();
        UpdateData(FALSE);
	}
}

void CTestDlg::OnOK() 
{
	// TODO: Add extra validation here
	m_FlexGrid.OnUpdateGrid();
	UpdateData(TRUE);
	if(m_nHand == 0)
	{
		pTestData = new char*[iAttNum];
		for(int i = 0;i < iAttNum;i++)
		{
			pTestData[i] = new char[MAX];
			strcpy(pTestData[i],m_FlexGrid.GetTextMatrix(1,i));
		}
		if(m_nFew == 0)
			SampleRecogniseFew();
		else
			SampleRecogniseMany();
		UpdateData(FALSE);
	}
	else
		CDialog::OnOK();
}

BEGIN_EVENTSINK_MAP(CTestDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CTestDlg)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()



void CTestDlg::OnRadioFile() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_EDIT_PATHNAME)->EnableWindow(TRUE);
	GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(TRUE);
	GetDlgItem(IDC_EDIT_RESULT)->EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_RULE)->EnableWindow(FALSE);
	m_FlexGrid.SetEnabled(FALSE);
}

void CTestDlg::OnRadioHand() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_EDIT_PATHNAME)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON_BROWSE)->EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_RESULT)->EnableWindow(TRUE);
	GetDlgItem(IDC_EDIT_RULE)->EnableWindow(TRUE);
	m_FlexGrid.SetEnabled(TRUE);
}

void CTestDlg::SampleRecogniseMany()
{
	int j,k;
	int* temp;
	int temp1 = -1;
	float reliability;
	int totalnum;
	int coveragenum;
	int n = 0;
	int pos;
	char* d;

	d = new char[MAX];
	
	temp = new int[iRuleNum];

	CString tempstring;
	CString trimstring;
	CString compstring;
		
	for(j = 0;j < iRuleNum;j++)
		temp[j] = 0;
	for(j = 0;j < iRuleNum;j++)
	{
		for(k = 0;k < iAttNum;k++)
		{
			if(strcmp(pRuleTable[j][k],"-") == 0)
				continue;
			
			tempstring = pRuleTable[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(')');
				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(atoi(pRuleTable[j][k]) != atoi(pTestData[k]))
					break;
			}//end else
		}//end for
	
		if(k == iAttNum)
		{
			temp[j] = 1;
			temp1 = j;
			n++;
		}//end if
	}//end for

	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(')');
					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(atoi(pBlockTable[j][k]) != atoi(pTestData[k]))
						break;
			}//end for
	
			if(k == iAttNum)
			{
				trimstring = pBlockTable[j][iAttNum];
				trimstring.Delete(0,5);
				if(temp[atoi(trimstring)] == 1)
				{
					temp[atoi(trimstring)] = 0;
					n--;
				}//end if
			}//end if
		}//end for
	}//end if

	if(n == 0)
	{
		m_strResult = "未识别";
		m_strRule = " ";
		return;
	}//end if
	if(n == 1)
	{
		for(j = 0;j < iRuleNum;j++)
		{
			if(temp[j] == 1)
				break;
		}//end for

		m_strResult = pRuleTable[j][iAttNum];
		m_strRule.Format("%d",temp1+1);
		return;
	}//end if

	temp1 = -1;
	for(j = 0;j < iRuleNum;j++)
	{
		if(temp[j] == 1)
		{
			if(temp1 == -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
			else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -