資源簡介
C#實(shí)現(xiàn)KD樹建立,最近鄰點(diǎn)搜索,采用BBF進(jìn)行了K近鄰搜索優(yōu)化
代碼片段和文件信息
//
//******************************************************************
//使用說明:
//1.必須先建立KD樹,List類型作為CreatKDTree()的輸入?yún)?shù)
//2.可以使用KD或BBF查找最近鄰點(diǎn)KDTreeFindNearest()、BBFFindNearest()
//3.使用BBf查找k個(gè)最近鄰點(diǎn)KNNByBBF()
//
//代碼是對(duì)?http://download.csdn.net/detail/jjp837661103/5874937?進(jìn)行的
//修改,增加了K近鄰搜索,感謝jjp837661103的專欄附上其博客地址:
//http://blog.csdn.net/jjp837661103/article/details/9768751
//申明:若侵權(quán),請(qǐng)留言,以刪除?---2016.2
//******************************************************************
//
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
namespace?outlineExtract
{
????///?
????///?樹類
????///?
????public?class?Node
????{
????????///?
????????///?節(jié)點(diǎn)信息
????????///?
????????public?Train?point{get;set;}
????????///?
????????///?左子樹
????????///?
????????public?Node?leftNode?{?get;?set;?}??
????????///?
????????///?右子樹?
????????///?
????????public?Node?righNode?{?get;?set;?}
????????///?
????????///?分割的方向軸序號(hào)
????????///?
????????public?int?split?{?get;?set;?}?
????????///?
????????///?父節(jié)點(diǎn)
????????///?
????????public?Node?parent?{?get;?set;?}
????????///?
????????///?空間節(jié)點(diǎn)
????????///?
????????public?List?range?{?get;?set;?}
????}
????///?
????///?節(jié)點(diǎn)類
????///?
????public?class?Train
????{
????????public?double?positionX?{?get;?set;?}
????????public?double?positionY?{?get;?set;?}
????????public?double?positionZ?{?get;?set;?}
????????public?Int32?AvgRssi?{?set;?get;?}
????}
????///?
????///節(jié)點(diǎn)優(yōu)先?
????///?
????public?class?PriorityList
????{
????????public?Node?node?{?get;?set;?}
????????public?double?priority?{?get;?set;?}
????}
????///?
????///?k最近鄰點(diǎn)
????///?
????public?class?KNearestPoint
????{
????????public?Node?node?{?get;?set;?}
????????public?double?distance?{?get;?set;?}
????}
????///?
????///?KD樹
????///?
????public?class?KDTree
????{
????????private?Dictionary?clientRSSI;
????????private?List?priorityList?=?new?List();?//優(yōu)先隊(duì)列
????????public?List?kNearestList?=?new?List();//K最近鄰點(diǎn)
????????public?KDTree()
????????{
????????????clientRSSI?=?new?Dictionary();
????????????clientRSSI.Add(“0060B3139D94“?-34);
????????????clientRSSI.Add(“002389B9AE6A“?-46);
????????????clientRSSI.Add(“0060B313A299“?-67);
????????????priorityList.Clear();???????//清空隊(duì)列??????????
????????}
????????#region?創(chuàng)建KD樹
????????///?
????????///?創(chuàng)建KD樹
????????///?
????????///?點(diǎn)集
????????///?KD樹
????????public?Node?CreatKDTree(List?train)
????????{
????????????//創(chuàng)建節(jié)點(diǎn)
????????????Node?node?=?new?Node();
????????????node.range?=?train;
????????????if?(
評(píng)論
共有 條評(píng)論