Beispiel #1
0
        //KMeans
        #region
        /// <summary>
        /// Search the nearest cluster
        /// </summary>
        /// <param name="cluster">List of cluster considered</param>
        public void SearchCluster(SyncronisedList <UICluster> cluster, out Cluster finded)
        {
            // If parameters is equal to null
            if (cluster == null || cluster.Count == 0)
            {
                throw new InvalidOperationException("There's no cluster");
            }

            double  distance = double.MaxValue;
            Cluster min      = cluster[0].Element;

            // Find the real nearest cluster
            for (int index = 0; index < cluster.Count; index++)
            {
                double tmp = Math.Sqrt(Math.Pow(cluster[index].Element.X - X, 2) + Math.Pow(cluster[index].Element.Y - Y, 2));
                if (tmp < distance)
                {
                    min      = cluster[index].Element;
                    distance = tmp;
                }
            }

            //Saves the cluster nearest
            if (Member != min)
            {
                finded = min;
            }
            else
            {
                finded = null;
            }
        }
Beispiel #2
0
 public Cluster(double x, double y, UICluster element)
 {
     X       = x;
     Y       = y;
     Points  = new SyncronisedList <Point>();
     Element = element;
 }
Beispiel #3
0
 internal Scope(SyncronisedList <U> owner, bool write)
 {
     _owner = owner;
     _write = write;
     if (_write)
     {
         _owner._threadLock.EnterWriteLock();
     }
     else
     {
         _owner._threadLock.EnterReadLock();
     }
 }
Beispiel #4
0
        public void SearchCluster(SyncronisedList <UICluster> cluster, SyncronisedList <UIPoint> points)
        {
            Cluster finded = null;

            if (Element.Typology == Point.Type.KMEANS)
            {
                Element.SearchCluster(cluster, out finded);
            }
            else if (Element.Typology == Point.Type.KNN)
            {
                Element.SearchType(points.ToArray(), out finded);
            }

            if (finded != null)
            {
                if (Element.Member != null)
                {
                    Element.Member.Points.Remove(Element);
                }
                Element.Member = finded;
                Element.Member.Points.Add(Element);
            }
        }
Beispiel #5
0
 public Cluster()
 {
     Points = new SyncronisedList <Point>();
 }