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

📄 rddlg.cpp

📁 Clusting using aco with Visual C
💻 CPP
字号:
// RDDlg.cpp : implementation file
//

#include "stdafx.h"
#include "antclusting.h"
#include "RDDlg.h"
#include "ArrayData.h"
#include "math.h"

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

extern CArrayData *m_pAd;
extern DataObject *dataObj;
/////////////////////////////////////////////////////////////////////////////
// CRDDlg dialog


CRDDlg::CRDDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRDDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRDDlg)
	m_nPropNum = 4;
	m_nDataNum = 150;
	m_sFileName = _T("iris.data");
	m_sMSG = _T("");
	//}}AFX_DATA_INIT
}


void CRDDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRDDlg)
	DDX_Text(pDX, IDC_EDIT_T_PROPERTY, m_nPropNum);
	DDX_Text(pDX, IDC_EDIT_T_DATA, m_nDataNum);
	DDX_Text(pDX, IDC_EDIT_FILENAME, m_sFileName);
	DDX_Text(pDX, IDC_MSG, m_sMSG);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRDDlg, CDialog)
	//{{AFX_MSG_MAP(CRDDlg)
	ON_BN_CLICKED(IDC_RD, OnRd)
	ON_BN_CLICKED(IDC_CHECK, OnCheck)
	ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRDDlg message handlers

void CRDDlg::OnRd() 
{
	// TODO: Add your control notification handler code here

    UpdateData(TRUE);
    int nLine=0,nRow=0,nTotal=0;
	CString strFilePathName="";
	CString strMsg;
    int nShowTotal;
   
	m_pAd = new CArrayData(strFilePathName);
    nShowTotal=m_pAd->Read(m_nDataNum,m_nPropNum,m_sFileName);
	m_pAd->GetInfo(nLine,nRow,nTotal);
	if(-1 == nShowTotal)
	{
		m_sMSG = m_pAd->GetLastError();
		GetDlgItem(IDC_MSG)->SetWindowText(m_sMSG);
	
		GetDlgItem(IDC_CHECK)->EnableWindow(FALSE);
     	GetDlgItem(IDC_EDIT_LINE)->EnableWindow(FALSE);
	    GetDlgItem(IDC_EDIT_ROW)->EnableWindow(FALSE);

	}
	else if(nShowTotal!=m_nDataNum*m_nPropNum)
    {	m_sMSG ="错误!输入行、列号与数据文件不相符!";
	    GetDlgItem(IDC_MSG)->SetWindowText(m_sMSG);

		GetDlgItem(IDC_CHECK)->EnableWindow(FALSE);
     	GetDlgItem(IDC_EDIT_LINE)->EnableWindow(FALSE);
	    GetDlgItem(IDC_EDIT_ROW)->EnableWindow(FALSE);

	}
   
    else
	{	

    m_sMSG="数据读取完毕!";
   	GetDlgItem(IDC_MSG)->SetWindowText(m_sMSG);
	char te[16];
	wsprintf(te,"%d",nLine);
	GetDlgItem(IDC_EDIT_LINE)->SetWindowText(te);
	wsprintf(te,"%d",nRow);
	GetDlgItem(IDC_EDIT_ROW)->SetWindowText(te);


	GetDlgItem(IDC_CHECK)->EnableWindow(TRUE);
	GetDlgItem(IDC_EDIT_LINE)->EnableWindow(TRUE);
	GetDlgItem(IDC_EDIT_ROW)->EnableWindow(TRUE);

	InitDataObj();
}
	

  }

void CRDDlg::OnCheck() 
{
    int nLine = -1;
	int nRow = -1;
	double fValue = -1;
	char te[16];
	CString strMsg;
	CString strTe;

	GetDlgItem(IDC_EDIT_LINE)->GetWindowText(te,15);
	nLine = atoi(te);
	GetDlgItem(IDC_EDIT_ROW)->GetWindowText(te,15);
	nRow = atoi(te);

	fValue = m_pAd->GetValueByXY(nLine,nRow);
	if(-1 == fValue)	//failed
	{
		strMsg = m_pAd->GetLastError();
		GetDlgItem(IDC_MSG)->SetWindowText(strMsg);
	}
	else
	{
		sprintf(te,"%8f",fValue);
		GetDlgItem(IDC_EDIT_VALUE)->SetWindowText(te);
		fValue = (double)atof(te);
		GetDlgItem(IDC_MSG)->SetWindowText("");
	}		
}


void CRDDlg::OnButtonCancel() 
{
	// TODO: Add your control notification handler code here
	UpdateData(FALSE);
	CDialog::OnCancel();

	
}




void CRDDlg::InitDataObj()
{
	double* pfa;
    pfa=m_pAd->GetData();
dataObj=new DataObject[m_nDataNum];
int XSize = (int)(sqrt(9*(int)m_nDataNum));    //// grid space size x=y=sqrt(9*N_objects)
int YSize = XSize;
for(int i=0;i<m_nDataNum;i++)
{ 
	   (dataObj+i)->m_pfa =new double[m_nPropNum];
	   for(int j=0;j<m_nPropNum;j++)
		   *((dataObj+i)->m_pfa+j)=*(pfa+i*m_nPropNum+j);
}

for(i=0;i<m_nDataNum;i++)
{
	(dataObj+i)->x = (float)(XSize*(rand()%100))/100;
	(dataObj+i)->y = (float)(YSize*(rand()%100))/100;
	(dataObj+i)->clusterNo = 0;
	///      dataObj[i].isUsed =false;
	(dataObj+i)->isMoved =false;
}

}

⌨️ 快捷键说明

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