📄 apriori_mbdlg.cpp
字号:
// Apriori_MBDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Apriori_MB.h"
#include "Apriori_MBDlg.h"
#include "Apriori.h"
#include "ItemDlg.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CApriori_MBDlg dialog
CApriori_MBDlg::CApriori_MBDlg(CWnd* pParent /*=NULL*/)
: CDialog(CApriori_MBDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CApriori_MBDlg)
m_score = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
//m_DBListBox.AddString(_T("1"));
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CApriori_MBDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CApriori_MBDlg)
DDX_Control(pDX, IDC_LIST_DATABASE, m_DBListBox);
DDX_Text(pDX, IDC_EDIT_SCORE, m_score);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CApriori_MBDlg, CDialog)
//{{AFX_MSG_MAP(CApriori_MBDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_FINDITEMSET, OnFinditemset)
ON_BN_CLICKED(IDC_ADDITEM, OnAdditem)
ON_BN_CLICKED(IDC_DELETEITEM, OnDeleteitem)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CApriori_MBDlg message handlers
BOOL CApriori_MBDlg::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
// m_DBListBox.AddString(_T("1 2 5 8"));
// m_DBListBox.AddString(_T("1 3 5 7"));
ifstream input=ifstream("transction.txt");
vector< vector<char> > transaction;
if (input==0) //文件打开失败
{
AfxMessageBox("事务文件transction.txt不存在!");
}
else
{
while(input)
{
string str;
getline(input,str,'\n'); //得到一行事务项集
if(str!="")//最后有一空行,所以在此用if消除
{
vector<char> cvec;
for(int i=0;i<str.size();++i)
{
if (str[i]!=' ')
cvec.push_back(str[i]);
}
m_DBListBox.AddString(str.c_str());
m_transaction.push_back(cvec);
}
}
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CApriori_MBDlg::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 CApriori_MBDlg::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 CApriori_MBDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CApriori_MBDlg::OnFinditemset()
{
// TODO: Add your control notification handler code here
Apriori apriori;
apriori.FindItemSet(m_transaction);
m_freqresults=apriori.GetResults();
m_score="";
for (int i=0;i<m_freqresults.size();++i)
{
m_score+="含";//+(i+1)+个元素的频繁项集为:\r\n";
stringstream ss;
ss << i+1;
m_score+=ss.str().c_str();
m_score+="个元素的频繁项集为:\r\n";
for (int j=0;j<m_freqresults[i].size();++j)
{ for (int k=0;k<m_freqresults[i][j].size();++k)
{
//m_score" %d",m_freqresults[i][j][k]);
stringstream ss;
ss << m_freqresults[i][j][k];
m_score+=ss.str().c_str();
m_score+=" ";
}
m_score+="\r\n";
}
m_score+="\r\n";
}
UpdateData(FALSE);
}
void CApriori_MBDlg::OnAdditem()
{
// TODO: Add your control notification handler code here
CItemDlg cItemdlg;
if (cItemdlg.DoModal())
{
vector<char> cvec;
//string str=cItemdlg.m_item.
string str=cItemdlg.m_item.GetBuffer(cItemdlg.m_item.GetLength());
if(str!="")
{
vector<char> cvec;
for(int i=0;i<str.size();++i)
{
if (str[i]!=' ')
cvec.push_back(str[i]);
}
m_DBListBox.AddString(str.c_str());
m_transaction.push_back(cvec);
}
}
UpdateData(FALSE);
}
void CApriori_MBDlg::OnDeleteitem()
{
// TODO: Add your control notification handler code here
int index=m_DBListBox.GetCurSel();
if (index!=-1)
{
CString str;
m_DBListBox.GetText(index,str);
vector<vector<char> >::iterator theIterator;
vector<char>::iterator innerIterator;
bool deleteIt=true;
int i=0;
for (theIterator=m_transaction.begin();theIterator!=m_transaction.end();++theIterator)
{
for (innerIterator=(*theIterator).begin(),i=0;innerIterator!=(*theIterator).end();++innerIterator)
{
while(str[i]==' ')
++i;//跳过空格
if( (*innerIterator) != str[i])
{
deleteIt=false;
break;
}
++i;
}
if(deleteIt)
{
m_transaction.erase(theIterator);
break;
}else{
deleteIt=true;
}
}
m_DBListBox.DeleteString(index);
//////////////////////////////////////////////////////////////////////////
// m_score="";
// for (int m=0;m<m_transaction.size();++m)
// {
// for (int n=0;n<m_transaction[m].size();++n)
// {
// m_score+=m_transaction[m][n];
// }
// m_score+="\r\n";
// }
// UpdateData(FALSE);
}else
{
AfxMessageBox("请选择一项删除!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -