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

📄 dmdlg.cpp

📁 数据挖掘的算法实现
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					if(flag==1)
					{
						if(cp_in_large1==NULL)
						{
							Large_set[i]->next=cp;
							cp1=cp->next;
							cp->next=cp_in_large;
						}
						else
						{
							cp_in_large1->next=cp;
							cp1=cp->next;
							cp->next=cp_in_large;
						}
						cp_in_large1=cp;
						cp=cp1;
					}
					if(flag==2)
					{
						cp_in_large1=cp_in_large;
						cp_in_large=cp_in_large->next;
					}
				}
			}
			i++;
		}
		k++;
	}
}

void set_zero(int total_count,struct partition_node *Large_set[])
{
	int i=1;
	struct partition_node *p;
	while(Large_set[i]!=NULL)
	{
		p=Large_set[i];
		while(p!=NULL)
		{
			if((p->sup_count)<total_count)
				p->sup_count=0;
			p=p->next;
		}
		i++;
	}
}

void gen_final_counts(FILE *fp,int tuple_number,int attr_number,int total_count,struct partition_node *Large_set[])
{
	struct tidlist_node **arr_tid;
	arr_tid=new struct tidlist_node *[attr_number+1];
	int i=1;
	int TID;
	char ch;
	int j;
	struct tidlist_node *tid_p;
	struct tidlist_node **tail;
	tail=new struct tidlist_node *[attr_number+1];
	while(i<=attr_number)
	{
		arr_tid[i]=NULL;
		i++;
	}
	i=1;
	while(!feof(fp)&&(i<=tuple_number))
	{
		j=1;
		fscanf(fp,"%d\t",&TID);
		while(j<=attr_number)
		{
			ch=fgetc(fp);
			if(ch=='1')
			{
				if(arr_tid[j]!=NULL)
				{
					tid_p=(struct tidlist_node*)malloc(sizeof(struct tidlist_node));
					tail[j]->next=tid_p;
					tid_p->tid=TID;
					tid_p->next=NULL;
					tail[j]=tid_p;
				}
				else
				{
					tid_p=(struct tidlist_node*)malloc(sizeof(struct tidlist_node));
					arr_tid[j]=tid_p;
					tid_p->tid=TID;
					tid_p->next=NULL;
					tail[j]=tid_p;
				}
			}
			ch=fgetc(fp);
			j++;
		}
		i++;
	}
	i=1;
	struct partition_node *p;
	struct attribute *p_attr;
	struct tidlist_node *temp_head;
	struct tidlist_node *temp_cp;
	struct tidlist_node *temp_cp1;
	int temp_count;
	int a1,a2;
	while(Large_set[i]!=NULL)
	{
		p=Large_set[i];
		while(p!=NULL)
		{
			if((p->sup_count)<total_count)
			{
				p_attr=p->attr_name;
				tid_p=arr_tid[p_attr->attr_no];
				temp_head=NULL;
				temp_count=0;
				if(tid_p!=NULL)
				{
					temp_cp=(struct tidlist_node*)malloc(sizeof(struct tidlist_node));
					temp_cp->next=NULL;
					temp_cp->tid=tid_p->tid;
					temp_head=temp_cp;
					tid_p=tid_p->next;
					temp_count+=1;
				}
				while(tid_p!=NULL)
				{
					temp_cp->next=(struct tidlist_node*)malloc(sizeof(struct tidlist_node));
					temp_cp->next->next=NULL;
					temp_cp->next->tid=tid_p->tid;
					temp_cp=temp_cp->next;
					tid_p=tid_p->next;
					temp_count+=1;
				}
				p_attr=p_attr->next;
				while(p_attr!=NULL)
				{
					tid_p=arr_tid[p_attr->attr_no];
					temp_cp=temp_head;
					while(temp_cp!=NULL)
					{
						if(tid_p==NULL)
						{
							if(temp_cp==temp_head)
							{
								temp_head=temp_cp->next;
								free(temp_cp);
								temp_cp=temp_head;
							}
							else
							{
								temp_cp1->next=temp_cp->next;
								free(temp_cp);
								temp_cp=temp_cp1->next;
							}
							temp_count--;
						}
						else
						{						
							a1=tid_p->tid;
							a2=temp_cp->tid;
							if(a1<a2)
							{
								tid_p=tid_p->next;
							}
							if(a1==a2)
							{
								tid_p=tid_p->next;
								temp_cp1=temp_cp;
								temp_cp=temp_cp->next;
							}
							if(a1>a2)
							{
								if(temp_cp==temp_head)
								{
									temp_head=temp_cp->next;
									free(temp_cp);
									temp_cp=temp_head;
								}
								else
								{
									temp_cp1->next=temp_cp->next;
									free(temp_cp);
									temp_cp=temp_cp1->next;
								}
								temp_count--;
							}
						}
					}
					p_attr=p_attr->next;
				}
				p->sup_count+=temp_count;
				temp_cp=temp_head;
				while(temp_cp!=NULL)
				{
					temp_cp1=temp_cp->next;
					free(temp_cp);
					temp_cp=temp_cp1;
				}
			}
			p=p->next;
		}
		i++;
	}
	j=1;
	struct tidlist_node *pt;
	struct tidlist_node *pt1;
	while(j<=attr_number)
	{
		pt=arr_tid[j];
		while(pt!=NULL)
		{
			pt1=pt->next;
			free(pt);
			pt=pt1;
		}
		j++;
	}
	delete[] arr_tid;
	delete[] tail;
}



void CDMDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDMDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDMDlg, CDialog)
	//{{AFX_MSG_MAP(CDMDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDMDlg message handlers

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

	// 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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CDMDlg::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 CDMDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDMDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CFileDialog filedlg(TRUE);
	CString path;
	if(IDOK==filedlg.DoModal())
	{
		path=filedlg.GetPathName();
		SetDlgItemText(IDC_EDIT3,path);
	}
}

void CDMDlg::OnButton3() 
{
	CString s;
	GetDlgItemText(IDC_EDIT3,s);
	FILE *fp;
	if((fp=fopen(s,"rb"))==NULL)
		exit(0);
	DWORD dwStart,dwStop;
	int attr_number;
	int offset;
	attr_number=init_attribute(fp,offset);
	float min_sup;
	int sup=GetDlgItemInt(IDC_EDIT1);
	min_sup=(float)sup/100;
	int tuple_number;
	tuple_number=GetDlgItemInt(IDC_EDIT2);
	int total_number=0;
	struct partition_node **partition[MAX_PARTITION_NUMBER]={NULL};
	struct partition_node *Large_set[20]={NULL};
	int b=1;
	dwStart=GetTickCount();//计时开始
	while(!feof(fp))
		partition[b++]=gen_large_itemsets(fp,tuple_number,min_sup,attr_number,total_number);
	Merge_partition(partition,Large_set);
	int total_count;
	total_count=(int)(min_sup*total_number)+1;
	set_zero(total_count,Large_set);
	rewind(fp);
	fseek(fp,offset,0);
	while(!feof(fp))
		gen_final_counts(fp,tuple_number,attr_number,total_count,Large_set);
	dwStop=GetTickCount();//计时结束
	int i=1;
	struct partition_node *p;
	struct attribute *p_attr;
	int attr;
	CString result="";
	int length;
	while(Large_set[i]!=NULL)
	{
		result=result+(char)(i+48);
		result=result+"-itemsets:";
		result=result+"\r\n";
		p=Large_set[i];
		while(p!=NULL)
		{
			if((p->sup_count)>total_count)
			{
				result=result+"{ ";
				p_attr=p->attr_name;
				while(p_attr!=NULL)
				{
					attr=p_attr->attr_no;
					result=result+A[attr];
					result=result+" , ";
					p_attr=p_attr->next;
				}
				length=result.GetLength();
				result.Delete(length);
				result.Delete(length-1);
				result.Delete(length-2);
				result=result+"} , ";
			}
			p=p->next;
		}
		length=result.GetLength();
		result.Delete(length);
		result.Delete(length-1);
		result.Delete(length-2);	
		result=result+"   ";
		i++;
		length=result.GetLength();
		result.Delete(length);
		result.Delete(length-1);
		result.Delete(length-2);
		result=result+"\r\n";
		result=result+"\r\n";
	}
	length=result.GetLength();
	result.Delete(length);
	result.Delete(length-1);
	result.Delete(length-2);
	result.Delete(length-3);
	SetDlgItemText(IDC_EDIT4,result);
	double costtime=dwStop-dwStart;
	int cost_time=(int)costtime;
	SetDlgItemInt(IDC_EDIT5,cost_time);
}

void CDMDlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	SetDlgItemText(IDC_EDIT1,"");
	SetDlgItemText(IDC_EDIT2,"");
	SetDlgItemText(IDC_EDIT3,"");
	SetDlgItemText(IDC_EDIT4,"");
	SetDlgItemText(IDC_EDIT5,"");
}

⌨️ 快捷键说明

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