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

📄 lbtreedoc.cpp

📁 用VC。NET2005实现优秀的最近邻搜索算法LB-TREE的模拟和图形显示。具有建立优良数据结构和搜索功能
💻 CPP
字号:
// LBTreeDoc.cpp : implementation of the CLBTreeDoc class
//

#include "stdafx.h"
#include "LBTree.h"

#include "LBTreeDoc.h"
#include "Random.h"
#include "NPoint.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CLBTreeDoc

IMPLEMENT_DYNCREATE(CLBTreeDoc, CDocument)

BEGIN_MESSAGE_MAP(CLBTreeDoc, CDocument)
END_MESSAGE_MAP()


// CLBTreeDoc construction/destruction

CLBTreeDoc::CLBTreeDoc()
: DataAmount(100)
, DataDim(2)
, Upper(1)
, Lower(-1)
, Mean(0)
, Deviation(0.1)
{
	// TODO: add one-time construction code here

}

CLBTreeDoc::~CLBTreeDoc()
{
	PointArray.RemoveAll();
}

BOOL CLBTreeDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}

// CLBTreeDoc serialization

void CLBTreeDoc::Serialize(CArchive& ar)
{
    PointArray.Serialize(ar);
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		ar<<DataAmount<<DataDim<<Upper<<Lower<<Mean<<Deviation;
	}
	else
	{
		// TODO: add loading code here
		ar>>DataAmount>>DataDim>>Upper>>Lower>>Mean>>Deviation;
	}
}


// CLBTreeDoc diagnostics

#ifdef _DEBUG
void CLBTreeDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CLBTreeDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG


// 生成随机的新数据集

void CLBTreeDoc::ProduceNewData(void)
{
	Random NewRandon;
    for(int i=0;i<DataAmount;i++)
	{
		NPoint* NewPoint=new NPoint(DataDim);
		double x=NewRandon.AverageRandom(Lower,Upper);
		NewPoint->SetValueAt(0,x);
		for(int j=1;j<DataDim;j++)
		{
			double y=x+NewRandon.NormalRandom(Mean,Deviation);
			
			if(y>Upper)  //如果y超过最大值
				y=2*Upper-y;
			else if(y<Lower)  //如果y低于最小值
				y=2*Lower-y;

			x=y;
			NewPoint->SetValueAt(j,y);
		}
		PointArray.Add(NewPoint);
	}
}

⌨️ 快捷键说明

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