Exemple #1
0
        /// <summary>
        ///     Constructor just construct, to cluster, call on the KMinKruskal Method.
        /// </summary>
        /// <param name="points">
        ///     A list of objects defined with the Point interface.
        /// </param>
        /// <param name="ClusterMaxSize">
        ///     A integer that limit the size of the maximum cluster.
        /// </param>
        public KMinSpanningTree(Point[] points, int ClusterMaxSize = -1)
        {
            Idx_V = new SortedDictionary <int, Point>();
            E     = new SortedSet <Edge>();        // Whther the edge is included in the MSt or not.
            V_Idx = new Dictionary <Point, int>(); // hashed, order is lost in the reverse map.
            // Chosen E established in EstablisheMST method.

            for (int I = 0; I < points.Length; I++)
            {
                Idx_V[I]         = points[I]; // index to vertex
                V_Idx[points[I]] = I;         // reverse map
            }

            // Parallel
            {
                EdgesBuffers Buffer = new EdgesBuffers(E);
                Parallel.For(0, points.Length, I =>
                {
                    for (int J = I + 1; J < points.Length; J++)
                    {
                        Buffer.LockAdd(new Edge(points[I], points[J]));
                    }
                });
            }

            if (ClusterMaxSize != -1)
            {
                this.ClusterSizeThreshold = ClusterMaxSize;
            }
            else
            {
                Threshold = (int)(Idx_V.Count / 2.0); // Default is 2 partition.
            }
        }
Exemple #2
0
        public FullGraph(Point[] points)
        {
            V = new SortedDictionary <int, Point>();
            E = new SortedSet <Edge>();        // Whther the edge is included in the MSt or not.
            W = new Dictionary <Point, int>(); // hashed, order is lost in the reverse map.
            // Chosen E established in EstablisheMST method.

            for (int I = 0; I < points.Length; I++)
            {
                V[I]         = points[I]; // index to vertex
                W[points[I]] = I;         // reverse map
            }

            // Parallel
            {
                EdgesBuffers Buffer = new EdgesBuffers(E);
                Parallel.For(0, points.Length, I =>
                {
                    for (int J = I + 1; J < points.Length; J++)
                    {
                        Buffer.LockAdd(new Edge(points[I], points[J]));
                    }
                });
            }

            max_partition = EstablishMST();
        }