資源簡介
該程序主要使用C#實現了KD樹的構造,同時利用構造的KD樹,查找距離目標點的最近鄰節點,還有在此基礎之上改進的BBF搜索算法,當然同時在此之上進一步改進K近鄰的搜索算法

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Data.SqlClient;
namespace?AlgorithmKNN
{
????public?partial?class?Form1?:?DevComponents.DotNetBar.Office2007Form
????{
????????private?Dictionary?clientRSSI;
????????private?List?lsTrain?=?new?List();
????????private?List?priorityList?=?new?List();?//優先隊列
????????public?Form1()
????????{
????????????InitializeComponent();
????????????clientRSSI?=?new?Dictionary();
????????????clientRSSI.Add(“0060B3139D94“?-34);
????????????clientRSSI.Add(“002389B9AE6A“?-46);
????????????clientRSSI.Add(“0060B313A299“?-67);
????????????priorityList.Clear();???????//清空隊列
????????}
????????private?void?buttonX1_Click(object?sender?EventArgs?e)
????????{
????????????//GetTrainCollection();
????????????GenerareData();
????????????Node?root?=?CreatKDTree(lsTrain);
????????????Train?target?=?new?Train()?{?positionX?=?2.1f?positionY?=?3.1f?positionZ?=?0?};
????????????this.KDTreeFindNearest(root?target);
????????????this.BBFFindNearest(root?target);
????????}
????????private?void?GetTrainCollection()
????????{
????????????lsTrain.Clear();
????????????//獲取訓練集
????????????string?sql?=?string.Format(“select?positionXpositionYAVG(rssi)?as?AvgRssi?from?FigRSSIApMana?“?+
????????????????????????????????????????“where?ApMana.id=FigRSSI.apid?and?apname=‘0060B3139D94‘?“?+
????????????????????????????????????????“group?by?positionXpositionY“);
????????????SqlConnection?connectioin?=?new?SqlConnection();
????????????connectioin.ConnectionString?=?@“Data?Source=202.200.119.1661433\SQLEXPRESS;Initial?Catalog=PositionSystem;User?ID=sa;Password=sasasa“;
????????????SqlCommand?cmd?=?new?SqlCommand();
????????????cmd.Connection?=?connectioin;
????????????cmd.CommandText?=?sql;
????????????connectioin.Open();
????????????SqlDataReader?reader?=?cmd.ExecuteReader();
????????????while?(reader.Read())
????????????{
????????????????lsTrain.Add(new?Train()
????????????????{
????????????????????positionX?=?Int32.Parse(reader[0].ToString())
????????????????????positionY?=?Int32.Parse(reader[1].ToString())
????????????????????positionZ?=?0????????//默認值
????????????????????AvgRssi?=?Int32.Parse(reader[2].ToString())
????????????????});
????????????}
????????????reader.Close();
????????????connectioin.Close();
????????}
????????private?void?GenerareData()
????????{
????????????lsTrain.Add(new?Train()?{?positionX?=?2?positionY?=?3?positionZ?=?0?});
????????????lsTrain.Add(new?Train()?{?positionX?=?5?positionY?=?4?positionZ?=?0?});
????????????lsTrain.Add(new?Train()?{?positionX?=?9?positionY?=?6?positionZ?=?0?});
????????????lsTrain.Add(new?Train()?{?positionX?=?9?positionY?=?8?positionZ?=?0?});
????????????lsTrain.Add(new?Train()?{
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3868??2013-08-05?21:15??AlgorithmKNN\AlgorithmKNN\AlgorithmKNN.csproj
?????文件??????47104??2013-08-04?17:02??AlgorithmKNN\AlgorithmKNN\bin\Debug\AlgorithmKNN.exe
?????文件??????48640??2013-08-04?17:02??AlgorithmKNN\AlgorithmKNN\bin\Debug\AlgorithmKNN.pdb
?????文件??????11600??2013-08-05?21:14??AlgorithmKNN\AlgorithmKNN\bin\Debug\AlgorithmKNN.vshost.exe
?????文件????????490??2010-03-17?22:39??AlgorithmKNN\AlgorithmKNN\bin\Debug\AlgorithmKNN.vshost.exe.manifest
?????文件??????25242??2013-08-05?21:14??AlgorithmKNN\AlgorithmKNN\Form1.cs
?????文件???????2287??2013-08-01?14:54??AlgorithmKNN\AlgorithmKNN\Form1.Designer.cs
?????文件???????5817??2013-08-01?14:54??AlgorithmKNN\AlgorithmKNN\Form1.resx
?????文件????????885??2013-08-03?17:06??AlgorithmKNN\AlgorithmKNN\Node.cs
?????文件???????1392??2013-08-05?21:14??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\AlgorithmKNN.csproj.FileListAbsolute.txt
?????文件??????47104??2013-08-04?17:02??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\AlgorithmKNN.exe
?????文件????????180??2013-08-04?16:39??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\AlgorithmKNN.Form1.resources
?????文件??????13911??2013-08-04?17:01??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\AlgorithmKNN.Form2.resources
?????文件??????48640??2013-08-04?17:02??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\AlgorithmKNN.pdb
?????文件????????180??2013-08-04?16:39??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\AlgorithmKNN.Properties.Resources.resources
?????文件???????9817??2013-08-02?15:30??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6396??2013-08-05?21:14??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????622??2013-08-04?17:01??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\GenerateResource.read.1.tlog
?????文件???????2160??2013-08-04?17:01??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\GenerateResource.write.1.tlog
?????文件??????12635??2013-08-02?15:38??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\ResolveAssemblyReference.cache
?????文件????????493??2013-08-04?16:39??AlgorithmKNN\AlgorithmKNN\Program.cs
?????文件???????1364??2013-07-31?14:25??AlgorithmKNN\AlgorithmKNN\Properties\AssemblyInfo.cs
?????文件???????2874??2013-07-31?14:25??AlgorithmKNN\AlgorithmKNN\Properties\Resources.Designer.cs
?????文件???????5612??2013-07-31?14:25??AlgorithmKNN\AlgorithmKNN\Properties\Resources.resx
?????文件???????1097??2013-07-31?14:25??AlgorithmKNN\AlgorithmKNN\Properties\Settings.Designer.cs
?????文件????????249??2013-07-31?14:25??AlgorithmKNN\AlgorithmKNN\Properties\Settings.settings
?????文件????????878??2013-07-31?14:25??AlgorithmKNN\AlgorithmKNN.sln
????..A..H.?????26624??2013-08-05?21:15??AlgorithmKNN\AlgorithmKNN.suo
?????目錄??????????0??2013-08-05?21:14??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug\TempPE
?????目錄??????????0??2013-08-05?21:14??AlgorithmKNN\AlgorithmKNN\obj\x86\Debug
............此處省略11個文件信息
評論
共有 條評論