示例#1
0
        private void BuildNeighbors()
        {
            using (var status = StatusWrapper.NewStatus("Building Neighbors", this.Data.Count))
            {
                var heap = new EasyHeapSmallFixedSize <NearestNeighbor>(HeapType.MinHeap, withTop, x => x.Distance);

                var rangeList = TimeCalculator.GetIndexRangeByTimeInterval(this.Data.Select(x => x.TimeTick).ToList(), Convert.ToInt64(kDisDiameter.TotalSeconds));

                for (int i = 0; i < this.Data.Count; i++)
                {
                    this.Data.GetRange(rangeList[i].Item1, rangeList[i].Item2 - rangeList[i].Item1)
                    .ForEach(x =>
                    {
                        var g = VectorPointHelper.GetDistance(this.Data[i], x, MathDistance);
                        if (g > 0)
                        {
                            heap.Push(new NearestNeighbor {
                                Distance = g, NeighborIndex = x.Id
                            });
                        }
                    });

                    this.Neighbors.Add(heap.GetList().ToList());
                    status.PushProgress();
                }
            }
        }
示例#2
0
        private List <int> InnerClustering(int index)
        {
            //var start = Math.Max(0, target.Id - (RangeDiameter>>1));
            //var range = Math.Min(RangeDiameter, this.Data.Count - start);
            //var start = target.TimeTick - RangeRadius;
            //var end = target.TimeTick + RangeRadius;

            var neighbors = this.Data
                            .GetRange(this.RangeList[index].Item1, this.RangeList[index].Item2 - this.RangeList[index].Item1)
                            .AsParallel()
                            //.Where(x => x.ClusterId == 0 && x.TimeTick > start && x.TimeTick < end && VectorPoint.Distance(target, x, this.GetDistance) < this.Radius)
                            .Where(x => x.ClusterId == 0 && VectorPointHelper.GetDistance(this.Data[index], x, GetDistance) < this.Radius)
                            .Select(x => x.Id)
                            .ToList();

            if (neighbors.Any())
            {
                if (this.Data[index].ClusterId > 0)
                {
                    neighbors.ForEach(x =>
                    {
                        this.Data[x].ClusterId = this.Data[index].ClusterId;
                        this.Data[x].LinkingId = this.Data[index].Id;
                    });
                }
                else
                {
                    ClusterCount++;
                    this.Data[index].ClusterId = ClusterCount;
                    neighbors.ForEach(x =>
                    {
                        this.Data[x].ClusterId = ClusterCount;
                        this.Data[x].LinkingId = this.Data[index].Id;
                    });
                }
                //this.StatusController.SetCurrentProgress(neighbors.Count());

                //foreach (var item in neighbors)
                //{
                //    this.InnerClustering(item);
                //}
            }

            return(neighbors);
        }