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

📄 liedoc.cpp

📁 某个实验事编写粗糙集智能信息处理的程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
   	if(pCmdUI->m_pSubMenu!=NULL )
	 pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex,MF_BYPOSITION|
			((stricmp(m_strStyle,"train")==0 &&
			m_iStage<=1 && IsComplete() )?MF_ENABLED:MF_GRAYED));
}
void CLieDoc::OnUpdateRsDiscreteMini(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(stricmp(m_strStyle,"train")==0 && m_iStage<=1 && IsComplete());		
}
void CLieDoc::OnUpdateRsDiscreteMydis(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(stricmp(m_strStyle,"train")==0 && m_iStage<=1 && IsComplete());	
}

void CLieDoc::OnUpdateRsCompleteDel(CCmdUI* pCmdUI) 
{
	if(pCmdUI->m_pSubMenu!=NULL)
		pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex,MF_BYPOSITION|
		((stricmp(m_strStyle,"train")==0 
		&& m_iStage==0 && !IsComplete())?MF_ENABLED:MF_GRAYED));
}

void CLieDoc::OnUpdateRsCompleteMet(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(stricmp(m_strStyle,"train")==0 && m_iStage==0 && !IsComplete());
}

void CLieDoc::OnUpdateRsBatch(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(stricmp(m_strStyle,"train")==0 );
	
}

void CLieDoc::OnFileSaveAs() 
{
	CString tmp=GetPathName();
    CFileDialog dlg(false,".txt",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
			"RS files(*.txt)|*.txt|all files(*.*)|*.*||",NULL);	
    if(dlg.DoModal()==IDOK)
	{
		::CopyFile(tmp,dlg.GetPathName(),FALSE);
		SetPathName(dlg.GetPathName());	
	}
}

void CLieDoc::OpenWithNotepad(const CString& target)
{
	WinExec("notepad.exe "+target,SW_SHOW);
}

void CLieDoc::OnNotpad() 
{
	OpenWithNotepad(GetPathName());	
}


void CLieDoc::OnRsBatch() 
{//批处理
	CMyPropertySheet sheet;
	sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;//Removes the Apply button. 
	// initialize the sheet
	int tmpStage;
	if(m_iStage==0 && IsComplete())
		tmpStage=1;
	else tmpStage=m_iStage;
	sheet.SetStage(tmpStage);
	if(sheet.DoModal()!=IDOK)
		return ;
	//  else --if above
	//completion file save name
	if(!sheet.m_Page1.m_bSaveFile)
		sheet.m_Page1.m_strPathName.Empty();
	//discretion
	if(!sheet.m_Page2.m_bSaveFile)
		sheet.m_Page2.m_strPathName.Empty();
	//attribute reduction
	if(!sheet.m_Page3.m_bSaveFile)
		sheet.m_Page3.m_strPathName.Empty();
	//value reduction
	if(!sheet.m_Page4.m_bSaveFile)
		sheet.m_Page4.m_strPathName.Empty();

	//-------------begin process
	bDoBatch=true;
	CString strFileIn="";
	strFileIn=GetPathName();
	if(tmpStage==0)
	{
		if( BatchRunAlgorithm(sheet.m_Page1.m_iAlgorithm+11,
							strFileIn,
							sheet.m_Page1.m_strPathName,
							sheet.m_Page1.m_bOpenFile))
		{
			strFileIn=sheet.m_Page1.m_strPathName;
		}
		else
		{
			bDoBatch=false;
			return;
		}
	}
    
	if(tmpStage==1)
	{
		if( BatchRunAlgorithm(sheet.m_Page2.m_iAlgorithm+21,
							strFileIn,
							sheet.m_Page2.m_strPathName,
							sheet.m_Page2.m_bOpenFile))
		{
			strFileIn=sheet.m_Page2.m_strPathName;
		}
		else
		{
			bDoBatch=false;
			return;
		}
	}
	if(tmpStage==2)
	{

		if( BatchRunAlgorithm(sheet.m_Page3.m_iAlgorithm+31,
							strFileIn,
							sheet.m_Page3.m_strPathName,
							sheet.m_Page3.m_bOpenFile))
		{
			strFileIn=sheet.m_Page3.m_strPathName;
		}
		else
		{
			bDoBatch=false;
 			return;
		}
	}
	if(tmpStage==3)
	{
	
		if( BatchRunAlgorithm(sheet.m_Page4.m_iAlgorithm+41,
							strFileIn,
							sheet.m_Page4.m_strPathName,
							sheet.m_Page4.m_bOpenFile))
		{
			strFileIn=sheet.m_Page4.m_strPathName;
		}
		else
		{
			bDoBatch=false;
			return;
		}
	}

	AfxMessageBox("处理完毕!");
	bDoBatch=false;
	g_bOpenNotShow=false;
	return;
}
 
BOOL CLieDoc::BatchRunAlgorithm(int flag, 
								const CString &inputfile, 
								/*inout*/ CString &outputfile,
								BOOL bOpenOutputFile)
{
///*
	g_strFileToRead=inputfile;
	CWinThread* thread;
	CWaitDlg dlg;
	switch(flag/10)
	{
	case 1:
		dlg.m_strStrToShow="正在进行数据补齐处理,请稍候...";
		break;
	case 2:
		dlg.m_strStrToShow="正在进行数据离散化处理,请稍候...";
		break;
	case 3:
		dlg.m_strStrToShow="正在进行属性约简处理,请稍候...";
		break;
	case 4:
		dlg.m_strStrToShow="正在进行值约简处理,请稍候...";
		break;
	default:
		dlg.m_strStrToShow="正在处理,请稍候...";
		break;
	}

	g_iFlag=flag;		//flag to indicate which algorithm should be run
	thread=AfxBeginThread(PerformFunc,AfxGetMainWnd()->GetSafeHwnd());
	((CRSetApp*)AfxGetApp())->g_handle=thread->m_hThread;
	
	((CRSetApp*)AfxGetApp()) ->g_bKilled=false;
	dlg.Create();
	g_strFileToSave.Format("~RS~tmp~%d.tmp",((CRSetApp*)AfxGetApp())->iIndex++);
	//if user press "cancel" of this dialog ,
	//then the variable g_bKilled will be TRUE
	if( ((CRSetApp*)AfxGetApp()) ->g_bKilled)
		return false;
	else
	{
		if(outputfile.IsEmpty())
		{
			outputfile=g_strFileToSave;
		}
		else
		{
			CopyFile(g_strFileToSave,outputfile,FALSE);
			DeleteFile(g_strFileToSave);
		}
	//	if(bOpenOutputFile)
//			((CRSetApp*)AfxGetApp())->OpenFile(outputfile);

		return true;
	}
//*/
	return true;
}

BOOL CLieDoc::ReadFileHeader(ifstream& in)
{
	char buf[256];
	int i;
	//----------------- read style ----------------------------------
	in.getline(buf,256,':');
	in>>m_strStyle;

	if (stricmp(m_strStyle,"rule")!=0 &&
		stricmp(m_strStyle,"result")!=0 &&
		stricmp(m_strStyle,"input")!=0 &&
		stricmp(m_strStyle,"test")!=0 &&
		stricmp(m_strStyle,"train")!=0  )
	{
		// read style error!
		AfxMessageBox("Read file error in line 1,\nUnknown data style!");
		return FALSE;
	}

	m_bHasBlock= (stricmp(m_strStyle,"rule")==0) ? TRUE : FALSE;
	m_bHasRule=(stricmp(m_strStyle,"rule")==0) ? TRUE : FALSE;
	    //rule文件时存在block

	in.getline(buf,256);	//filter helpless characters

	//-----------------------read stage--------------------------------
	in.getline(buf,256,':');
	in>>m_iStage;
	if(m_iStage>3||m_iStage<0)
	{
		AfxMessageBox("Read file error,\n Unknown data stage!");
		return FALSE;
	}
	in.getline(buf,256);

	//--------------------read condition attributes number--------------
	in.getline(buf,256,':');
	in>>m_iAttrNum;
	if(m_iAttrNum<0 )
	{
		AfxMessageBox("Read file error in line 3. ");
		return FALSE;
	}
	in.getline(buf,256);
///*
    if(m_bHasBlock ||stricmp(m_strStyle,"train")==0 &&  m_iStage==3)
//	 if(stricmp(m_strStyle,"train")==0 &&  m_iStage==3)//当train为3或者为规则时,此时存在删除属性等
   {
	in.getline(buf,256,':');
	in>>m_iReductedNum;//读入删除了的属性数目
	TRACE("m_iReductedNum     %d\n",m_iReductedNum);
	if(m_ipReductedAttr==0)
	{
		try
		{
			m_ipReductedAttr=new int[m_iReductedNum];
		}	
		catch(CMemoryException* e)
		{
			::MessageBeep(MB_ICONHAND);
			AfxMessageBox("Out of the memory!",MB_OK|MB_ICONSTOP);
			e->Delete();
			return FALSE;
		}
	}
		in.getline(buf,256);
		in.getline(buf,256,':');
		for(int i=0;i<m_iReductedNum;i++)
			in>>m_ipReductedAttr[i];
		TRACE("m_iReductedAttribute position   %d\n",m_ipReductedAttr[0]);
		in.getline(buf,256);
   }
//*/
	//----------------- read records number-----------------------------
	in.getline(buf,256,':');
	m_sRecNum=new char[256];
	strcpy(m_sRecNum,buf);
	in>>m_iRecordNum;
	if(m_bHasRule)
        m_iRuleNum=m_iRecordNum;
	if(m_iRecordNum<0 || m_iRecordNum>2000000000)
	{
		AfxMessageBox("Line 6:Records Number is below Zero or too large");
		return FALSE;
	}
	m_iTestNum=m_iRecordNum;	//tests number

	//--------------- read blocks number--------------------------------
	if(HasBlock())
	{
		in.getline(buf,256);
		in.getline(buf,256,':');
		in>>m_iBlockNum;
		if(m_iBlockNum<0)
		{
			AfxMessageBox("Blocks Number is below 0 ");
			return FALSE;
		}
	}

	//--------------------read condition attributes name -------------------
	//allocate mormory first
	if(m_pstrAttrName==0)
	{
			try
		{
			m_pstrAttrName=new char*[m_iAttrNum+1];
		}	
		catch(CMemoryException* e)
		{
	 		::MessageBeep(MB_ICONHAND);
			AfxMessageBox("Out of the memory!",MB_OK|MB_ICONSTOP);
			e->Delete();
			return FALSE;
		}
		for(i=0;i<m_iAttrNum+1;i++)
		{
			try
			{
				m_pstrAttrName[i]=new char[20];//分配属性名称空间
			}	
			catch(CMemoryException* e)
			{
				::MessageBeep(MB_ICONHAND);
				AfxMessageBox("Out of the memory!",MB_OK|MB_ICONSTOP);
				e->Delete();
				return FALSE;
			}
		}
	}
	//read 
	for(i=0;i<m_iAttrNum;i++)
	{
		in>>m_pstrAttrName[i];//读入条件属性名称
	}
	if(stricmp(m_strStyle,"input")!=0)	//not regnise input file
	{
		in>>m_pstrAttrName[m_iAttrNum];//读入决策属性名称
	}

	//--------------datatype line-------------------------s
	if(stricmp(m_strStyle,"result")==0)	//测试文件没有数据类型
	{
		in.getline(buf,256);
		return true;
	}
	if(m_pstrAttrType==0)//还没有分配空间
		{
		try
		{
			m_pstrAttrType=new char*[m_iAttrNum+1];//分配空间
		}	
		catch(CMemoryException* e)
		{
			::MessageBeep(MB_ICONHAND);
			AfxMessageBox("Out of the memory!",MB_OK|MB_ICONSTOP);
			e->Delete();
			return FALSE;
		}
		for(i=0;i<m_iAttrNum+1;i++)
		{
			try
			{
				m_pstrAttrType[i]=new char[20];//分配空间
			}	
			catch(CMemoryException* e)
			{
				::MessageBeep(MB_ICONHAND);
				AfxMessageBox("Out of the memory!",MB_OK|MB_ICONSTOP);
				e->Delete();
				return FALSE;
			}
		}
	}
//	in.getline(buf,256);
	for(i=0;i<m_iAttrNum;i++)		// conditon attributes 
	{
		in>>m_pstrAttrType[i];
		if(strcmp(m_pstrAttrType[i],"Integer")==0)
			iInt++;
		else if(strcmp(m_pstrAttrType[i],"Float")==0)
			iFloat++;
		else if(strcmp(m_pstrAttrType[i],"String")==0)
			iString++;
		else
		{
			TRACE(m_pstrAttrType[i]);
			TRACE(" error datatype\n");
			AfxMessageBox("Error when reading data type,\nmaybe lack of data names or data type!");
			return FALSE;
		}
	}

	if(stricmp(m_strStyle,"input")!=0)	//not regnise input file
	{
		in>>m_pstrAttrType[m_iAttrNum];
		if(strcmp(m_pstrAttrType[m_iAttrNum],"Integer")!=0)
		{
			AfxMessageBox("Error when reading decision type.\nIt should be 'Integer'!");
			return FALSE;
		}
	}
	
	m_bHasFloat= (iFloat>0)?TRUE:FALSE;
	return TRUE;

}




void CLieDoc::OnUpdateRsTest(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(stricmp(m_strStyle,"rule")==0);
}

void CLieDoc::OnUpdateRsRecognise(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(stricmp(m_strStyle,"rule")==0);
}


void CLieDoc::OnUpdateRsAttrReduEntropy2(CCmdUI* pCmdUI) 
{
pCmdUI->Enable(	m_iStage==1&&GetIntAttNum()==m_iAttrNum
		||m_iStage==2||m_iStage==0&&GetIntAttNum()==m_iAttrNum&&
		IsComplete());	}


void CLieDoc::OnUpdateRsAttrReduMibark(CCmdUI* pCmdUI) 
{
pCmdUI->Enable(	m_iStage==1&&GetIntAttNum()==m_iAttrNum
		||m_iStage==2||m_iStage==0&&GetIntAttNum()==m_iAttrNum&&
		IsComplete());	}
void CLieDoc::OnUpdateRsAttrReduEntropy1(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(	m_iStage==1&&GetIntAttNum()==m_iAttrNum
		||m_iStage==2||m_iStage==0&&GetIntAttNum()==m_iAttrNum&&
		IsComplete());	
}


void CLieDoc::OnUpdateToolMissvalue(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(stricmp(m_strStyle,"train")==0 && 
		m_iStage<=2 && IsComplete());

}

void CLieDoc::OnUpdateRsSpecIncmplRecognise(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(stricmp(m_strStyle,"rule")==0);
	
}

void CLieDoc::OnUpdateRsSpecIncmplTest(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(stricmp(m_strStyle,"rule")==0);
	
}

void CLieDoc::OnUpdateRsSpecIncmpl2Recognise(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(stricmp(m_strStyle,"rule")==0);
	
}

void CLieDoc::OnUpdateRsSpecIncmpl2Test(CCmdUI* pCmdUI)//样本测试 
{
	pCmdUI->Enable(stricmp(m_strStyle,"rule")==0);
	
}

void CLieDoc::OnUpdateRsSpecIncmpl3Recognise(CCmdUI* pCmdUI) //样本识别
{

⌨️ 快捷键说明

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