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

📄 proto.cpp

📁 信息增益C++程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    if (node->on == NULL) 
    {
        if (node->idx == ON)
			AfxMessageBox("ON");
			////////////
            //printf("ON");
		//////////////////////////
        else if (node->idx == OFF)
			AfxMessageBox("OFF");
            //printf("OFF");
        return;
    }

    else
	{
	
	tree.Format("if { %s >= %1.2f then ",tag_names[node->idx], node->threshold);
	AfxMessageBox(tree);
	
	}
        //printf("if { %s >= %1.2f then ", tag_names[node->idx], node->threshold);

    print_tree ( node->on, tag_names );
    printf(" else ");
    print_tree ( node->off, tag_names );
    printf( " } " );
}

void PROTO::read_matrix (CHAR filename[], MATRIX *matrix)

{

    UINT i, j;
    UINT height = matrix->height;
    UINT width  = matrix->width;
    REAL **data = matrix->data;
    FILE *f;

    /* Open price file */
    if ((f = fopen(filename, "r")) == NULL) 
    {
        printf("\n File not found : %s\n", filename);
        err_exit (__FILE__, __LINE__);
    }

    for (i=0; i<height; i++)
        for (j=0; j<width; j++)
        {
            fscanf(f, "%lf\n", &data[i][j] );
        }

    fclose(f);

}
CHAR **PROTO::read_tags (CHAR *tag_file, UINT width)
{
    FILE *f;
    CHAR **_varname;
    UINT i;
    CHAR buffer[0xFF];

    f = fopen(tag_file, "r");
    if (f == NULL)
    {
        printf("\n File not found : %s\n", tag_file);
        err_exit (__FILE__, __LINE__);
    }

    _varname = (CHAR**) malloc (width * sizeof (CHAR*));
    for (i=0; i<width; i++)
        _varname[i] = (CHAR*) malloc (0xFF * sizeof (CHAR));

    i = 0;
    while (!feof(f))
    {
        if (fgets(buffer, 0xFF, f) != NULL)
        {
            if (strlen(buffer) > strlen("\n"))
            {
                if (i>width-1)
                {
                    printf("\nMore variable names were detected than data items.");
                    printf("\nPlease correct this problem before proceeding");
                    exit(0);
                }
                sscanf (buffer, "%[a-zA-Z0-9-_;:!@#$%^&*(){}[]]", _varname[i]);
                i++;
            }
        }
    }

    if (i<width) 
    {
        printf("\nFewer variable names than data items were detected.");
        printf("\nPlease correct this problem before proceeding");
        exit(0);
    }

    fclose (f);

    return _varname;

}
void PROTO::free_matrix (MATRIX *_matrix)
{
    UINT i;
    for (i=0; i<_matrix->height; i++)
        free (_matrix->data[i]);

    free (_matrix->data);
    free (_matrix);
}

/*-------------------------------------------------------------------*/

void PROTO::free_tags ( CHAR** varname, UINT width)
{
    UINT i;
    for (i=0; i<width; i++)
        free(varname[i]);
    free (varname);
}

/*-------------------------------------------------------------------*/

void PROTO::free_tree ( NODE  *node )
{
    /*
     *  Frees the memory allocated to a tree structure
     */

    if (node == NULL)
        return;
    else
    {
        free_tree (node->on);
        free_tree (node->off);
        free(node);
    }

}

void PROTO::bubble(Mysort *buff, int len)
{
	int i,j;
    REAL temp;
	int tempindex;
     for( i=len;i>0;i--)
     {
          for(j=len-1;j>0;j--)
          {
               if(buff[j].genedata > buff[j-1].genedata)
               {
                   temp = buff[j].genedata;
				   tempindex=buff[j].index;
                   buff[j].genedata = buff[j-1].genedata;
				   buff[j].index= buff[j-1].index;
                   buff[j-1].genedata = temp;
				   buff[j-1].index=tempindex;
               }
          }
     }

	//////////////////////////////////////////
	FILE *m_fp1;
	m_fp1=fopen("c:\\lihui.txt","w+");
	
	////////////////////////////////////////////////////////////////
	fprintf(m_fp1,"基因个数=%d\n",len);
	for( i=len-1;i>0;i--)
	{
	   // j+=1;
		fprintf(m_fp1,"%d",buff[i].index+1);
		fprintf(m_fp1,"		");
		fprintf(m_fp1,"%f",buff[i].genedata);
	//	fprintf(m_fp1,"		");
	//	if(j>9)
	//	{
			fprintf(m_fp1,"\n");
	//		j=0;
	//	}

	
	}
	
	fclose(m_fp1);


}

MATRIX * PROTO::ReadFormExcel(CString filename,UINT *width, UINT *height)
{ 
	MATRIX *_matrix;
//	HWND hwnd;
//	HWND hwnd1;
	//(CProgressCtrl*)::
//	hwnd=::GetDlgItem(NULL,IDC_PROGRESS1);
	if (::CoInitialize( NULL ) == E_INVALIDARG)
	{
		AfxMessageBox(_T("初始化Com失败!"));
    }
    if ( !this->m_ExcelApp.CreateDispatch(_T("Excel.Application"), NULL))
	{
        AfxMessageBox(_T("创建Excel2000服务失败!"));
        ::CoUninitialize();
    }
	Range range;
	///////////////////////////////////////////////
	this->m_wbsBooks.AttachDispatch(this->m_ExcelApp.GetWorkbooks(), TRUE);
	this->m_wbBook.AttachDispatch(m_wbsBooks.Add(COleVariant(filename)), TRUE );
	this->m_wssSheets.AttachDispatch(m_wbBook.GetWorksheets(),TRUE);
	this->m_wsSheet.AttachDispatch(m_wssSheets.GetItem(_variant_t("Sheet1")),TRUE);
	range.AttachDispatch(m_wsSheet.GetCells()); 
	range.AttachDispatch(range.GetItem (COleVariant((long)1),COleVariant((long)1)).pdispVal );
	COleVariant vResult =range.GetValue2();
	CString str;
	Range usedRange;
	CString mm=m_wsSheet.Get_CodeName();
	usedRange.AttachDispatch(m_wsSheet.GetUsedRange());
	range.AttachDispatch(usedRange.GetRows());
	long iRowNum=range.GetCount();                   //已经使用的行数
		//range.GetColumns
	range.AttachDispatch(usedRange.GetColumns());
	long iColNum=range.GetCount(); 
		//已经使用的列数
	long iStartRow=usedRange.GetRow();               //已使用区域的起始行,从1开始
	long iStartCol=usedRange.GetColumn();
	///////////////////////////////////////////
	UINT i;

    _matrix = (MATRIX*) malloc (sizeof (MATRIX));
    if (!_matrix)
       AfxMessageBox("asdf"); //err_exit (__FILE__, __LINE__);
	/////////////行列转置

    _matrix->width  = iRowNum;
    _matrix->height = iColNum;
	///////////////////////////////////////////////

    _matrix->data = (REAL**) malloc (iRowNum * sizeof (REAL*));
    if (_matrix->data == NULL)
        AfxMessageBox("asdf");//err_exit(__FILE__, __LINE__);

    for (i=0; i<iRowNum; i++)
    {
        _matrix->data[i] = (REAL*) malloc (iColNum * sizeof(REAL));
        if (_matrix->data[i] == NULL)
            AfxMessageBox("asdf");//err_exit(__FILE__, __LINE__);
    }
   ////////////////////////////////////////////////////////////////////////////////////////
   REAL **data = _matrix->data;
   *width=iRowNum;
   *height=iColNum;
   ::progress->SetRange(0,iRowNum*iColNum);
   int temp=iRowNum*iColNum;
   
  // int pos=temp/1000;
   /////////////////////////////////////////////////////////////////////
   int j;
   for( i=iStartCol;i<=iColNum;i++)
		for( j=iStartRow;j<=iRowNum;j++)
		{
				range.AttachDispatch(m_wsSheet.GetCells());
				range.AttachDispatch(range.GetItem (COleVariant((long)j),COleVariant((long)i)).pdispVal );
				COleVariant vResult =range.GetValue2();
			//	pos+=pos;
				progress->StepIt();
				if(vResult.vt == VT_BSTR)       //字符串
				{
					str=vResult.bstrVal;
				
				}
				else if (vResult.vt==VT_R8)     //8字节的数字 
				{
					str.Format("%f",vResult.dblVal);
					data[j-1][i-1]=vResult.dblVal;
					if(str=="1.000000")
					{
						
					
					
					}
					else if(str=="0.000000")
					{
						
					
					}
			
					
				}
				else if (vResult.vt==VT_R4)           //var is float type
				{
					str.Format("%10.6f",(double)vResult.fltVal);
					AfxMessageBox("VT_R4");
				}
				else if (vResult.vt==VT_CY) 
				{
        
					str=COleCurrency(vResult).Format();
			
				}
				else if (vResult.vt==VT_I2)  
				{
					str.Format("%d",(int)vResult.iVal);
			

				}
				else if (vResult.vt==VT_BOOL)     //var is  VARIANT_BOOL
				{
					str= (vResult.boolVal==0) ?"FALSE": "TRUE";
					AfxMessageBox("VT_BOOL");
				}

				else if(vResult.vt==VT_DATE)    //时间格式
				{
					SYSTEMTIME st;
					VariantTimeToSystemTime(vResult.date, &st);
				}
				else if(vResult.vt==VT_EMPTY)   //单元格空的
				{
					data[j-1][i-1]=10.00;
					str="";
				}  
		
		
			
		
		
		}
   
	//////////////////////////////////////////////////////////////////////////////////////////
    return _matrix;
}

⌨️ 快捷键说明

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