• 大小: 107KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-25
  • 语言: C#
  • 标签: KD树构造  KNN  BBF搜索  C#  

资源简介

该程序主要使用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个文件信息

评论

共有 条评论