Beispiel #1
0
        }          // of AnnexCluster()

        public static UnitCluster MergeClusters(UnitCluster p_C1, UnitCluster p_C2)
        {
            if (p_C2.ListPoints.Count > 0)
            {
                p_C1.AnnexCluster(p_C2);
            }

            return(p_C1);
        }          // of MergeClusters()
Beispiel #2
0
        public static List <UnitCluster> RunKmeans <T>(List <T> objList, double distance) where T : CacheObject
        {
            List <UnitCluster> LC_ = new List <UnitCluster>();

            if (objList.Count == 0)
            {
                return(LC_);
            }

            List <CacheObject> l_ListUnits = new List <CacheObject>(objList.ToArray());

            if (l_ListUnits.Count == 0)
            {
                return(LC_);
            }



            // for starters, take a point to create one cluster
            CacheUnit l_P1 = (CacheUnit)l_ListUnits[0];

            l_ListUnits.RemoveAt(0);

            // so far, we have a one-point cluster
            LC_.Add(new UnitCluster(distance, l_P1));

            #region Main Loop
            // the algorithm is inside this loop
            List <UnitCluster> l_ListAttainableClusters;
            UnitCluster        l_c;
            foreach (CacheUnit p in l_ListUnits)
            {
                l_ListAttainableClusters = new List <UnitCluster>();
                l_ListAttainableClusters = LC_.FindAll(x => x.IsPointReachable(p.PointPosition));
                LC_.RemoveAll(x => x.IsPointReachable(p.PointPosition));
                l_c = new UnitCluster(distance, p);
                // merge point's "reachable" clusters
                if (l_ListAttainableClusters.Count > 0)
                {
                    l_c.AnnexCluster(l_ListAttainableClusters.Aggregate((c, x) =>
                                                                        c = MergeClusters(x, c)));
                }
                LC_.Add(l_c);
                //Logger.DBLog.InfoFormat("Cluster Found: Total Points {0} with Centeroid {1}", l_c.ListPoints.Count, l_c.Centeroid.ToString());
                l_ListAttainableClusters = null;
                l_c = null;
            }              // of loop over candidate points

            //LC_=LC_.OrderByDescending(o => o.ListPoints.Count).ToList();
            #endregion

            return(LC_);
        }
Beispiel #3
0
 public override bool Equals(object obj)
 {
     //Check for null and compare run-time types.
     if (obj == null || this.GetType() != obj.GetType())
     {
         return(false);
     }
     else
     {
         UnitCluster p = (UnitCluster)obj;
         return(this.Midpoint.Equals(p.Midpoint));
     }
 }
Beispiel #4
0
        }          // of AddPoint()

        /// <summary>
        /// Incorporates all points from given cluster to this cluster
        /// </summary>
        /// <param name="p_Cluster"></param>
        /// <returns>true always</returns>
        public override bool AnnexCluster(cluster p_Cluster)
        {
            base.AnnexCluster(p_Cluster);

            //Unit specific
            UnitCluster u_Cluster = (UnitCluster)p_Cluster;

            ListUnits.AddRange(u_Cluster.ListUnits);
            if (this.NearestMonsterDistance > u_Cluster.NearestMonsterDistance)
            {
                this.NearestMonsterDistance = u_Cluster.NearestMonsterDistance;
            }
            Info.Merge(u_Cluster.Info);


            return(true);
        }          // of AnnexCluster()