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

📄 fpgrowthtestdlg.cpp

📁 FP-Growth算法
💻 CPP
字号:
// FPGrowthTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FPGrowthTest.h"
#include "FPGrowthTestDlg.h"
#include "MinSupportDlg.h"
#include <iostream>
using namespace std;
#include <stdlib.h>
#include <time.h>

#include "data.h" 
#include "item.h"
#include "fptree.h"
#include "fpgrowth.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern FILE *ResultOut;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFPGrowthTestDlg dialog

CFPGrowthTestDlg::CFPGrowthTestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFPGrowthTestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFPGrowthTestDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFPGrowthTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFPGrowthTestDlg)
	DDX_Control(pDX, IDC_LIST, m_ListBox);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFPGrowthTestDlg, CDialog)
	//{{AFX_MSG_MAP(CFPGrowthTestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_MENU_Open, OnMENUOpen)
	ON_BN_CLICKED(IDC_BUTTON_FPGrowth, OnBUTTONFPGrowth)
	ON_COMMAND(ID_MENU_MinSup, OnMENUMinSup)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFPGrowthTestDlg message handlers

BOOL CFPGrowthTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	GetCurrentDirectory(_MAX_DIR,FilePath.GetBuffer(_MAX_DIR));
//	GetModuleFileName(NULL,FilePath.GetBuffer(_MAX_DIR),_MAX_DIR);
	m_ListBox.InsertColumn(0,"频繁模式",LVCFMT_LEFT,200);//插入列表头标题
	m_ListBox.InsertColumn(1,"支持度计数",LVCFMT_LEFT,100);
   	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFPGrowthTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CFPGrowthTestDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CFPGrowthTestDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CFPGrowthTestDlg::OnMENUOpen() 
{
	// TODO: Add your command handler code here
	CString TXTName;
	CFileDialog dlg(true,"*.txt","*.txt",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"txt文件(*.txt)|*.txt||",NULL);
	if(dlg.DoModal()==IDCANCEL)
		return;
	else
		TXTName=dlg.GetPathName();
	FileName=dlg.GetFileName();  
	FilePath=StringManage(TXTName);
	delete dlg;
//	MessageBox(TXTName);
	
}
void CFPGrowthTestDlg::OnBUTTONFPGrowth() 
{
	// TODO: Add your control notification handler code here
	clock_t start,stop,tick;//计算用时
	if(FilePath=="")
	{
		AfxMessageBox("数据文件路径出错!");
	}
	else
	{
		CString sPath,ResultFile,str1="\\Result\\Data.txt",str2="\\Result\\Result_Data.txt";
		sPath.Format("%s%s",FilePath,str1);
		ResultFile.Format("%s%s",FilePath,str2);
		CString DataPath=StringManage(sPath);
	    CString ResultDataPath=StringManage(ResultFile);
		

		start=clock();
		FPgrowth *fpgrowth1 = new FPgrowth();
 		fpgrowth1->setData((LPSTR)(LPCTSTR)DataPath,4);
		if(MinSup<=0)
		{
			AfxMessageBox("设定最小支持数!");
		}
		else
		{
			fpgrowth1->setMinsup(MinSup);
			fpgrowth1->setOutput((LPSTR)(LPCTSTR)ResultDataPath);
			clock_t start = clock();
			int added = fpgrowth1->mine();
			delete fpgrowth1;
//  		fflush(ResultOut);
		    fclose(ResultOut);//关闭文件
			//计算用时
			stop=clock();
			tick=stop-start;
			double timeused=(double)tick/CLK_TCK;
			CString strTime;
			strTime.Format("用时:%f s",timeused);
			MessageBox(strTime);	
			
			//读取结果文件
			CString FileString,str1,str2;
			CStdioFile File;
			File.Open(ResultDataPath,CFile::modeRead); //以读模式打开文本文件
			m_ListBox.DeleteAllItems();
			while(File.ReadString(FileString))
			{
				UpdateData(true);
				int k;
				k=FileString.Find(":");
				if(k!=-1)
				{
					str1=FileString.Left(k);
					str2=FileString.Right(FileString.GetLength()-k-1);
				}
				
//  				Separate(FileString,str1,str2);
				//添加新行
				m_ListBox.InsertItem(0,str1);
                m_ListBox.SetItemText(0,1,str2);
			}
		}
	}
}

void CFPGrowthTestDlg::OnMENUMinSup() 
{
	// TODO: Add your command handler code here
	CMinSupportDlg dlg;
	if(dlg.DoModal()==IDOK)
	{
		MinSup=dlg.m_MinSup;
	}
	delete dlg;
}

CString CFPGrowthTestDlg::StringManage(CString str)
{
	int i,j;
	CString strNew="";
	while((i=str.Find('\\'))!=-1)
	{
		strNew=strNew+str.Left(i)+"\\\\";
		j=str.GetLength();
		str=str.Right(j-i-1);
	}
	strNew=strNew+str;
	return strNew;
}




void CFPGrowthTestDlg::Separate(CString str0, CString str1, CString str2)
{
	int k;
	k=str0.Find(":");
	if(k!=-1)
	{
		str1=str0.Left(k);
		str2=str0.Right(str0.GetLength()-k-1);
	}

}

⌨️ 快捷键说明

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