/// <summary>
        /// Retrives the connected subgraphs of the given cluster.
        /// </summary>
        /// <param name="level">The level of cluster.</param>
        /// <param name="numberNode">The index of cluster.</param>
        /// <returns>Connected components.</returns>
        private SortedDictionary <Double, Double> ConnectedSubgraphsInCluster(int level, int numberNode)
        {
            SortedDictionary <Double, Double> retArray = new SortedDictionary <Double, Double>();

            if (level == container.Level)
            {
                retArray[1] = 1;
                return(retArray);
            }

            int      branchSize  = (int)container.Branches[level][numberNode];
            int      branchStart = container.FindBranches(level, numberNode);
            BitArray node        = container.TreeNode(level, numberNode);

            bool haveOne = false;

            for (int i = 0; i < branchSize; ++i)
            {
                if (container.CountConnectedBlocks(node, branchSize, i) == 0)
                {
                    SortedDictionary <Double, Double> array = ConnectedSubgraphsInCluster(level + 1,
                                                                                          branchStart + i);

                    foreach (KeyValuePair <Double, Double> kvt in array)
                    {
                        if (retArray.Keys.Contains(kvt.Key))
                        {
                            retArray[kvt.Key] += kvt.Value;
                        }
                        else
                        {
                            retArray.Add(kvt.Key, kvt.Value);
                        }
                    }
                }
                else
                {
                    haveOne = true;
                }
            }

            if (haveOne)
            {
                EngineForConnectedComp      engForConnectedComponent = new EngineForConnectedComp();
                Dictionary <int, ArrayList> nodeMadrixList           = container.NodeAdjacencyLists(node, branchSize);

                Dictionary <int, ArrayList> connComp = engForConnectedComponent.GetConnSGraph(nodeMadrixList, branchSize);
                Double countConnElements             = 0;
                for (int i = 0; i < connComp.Count; ++i)
                {
                    if (connComp[i].Count > 1)
                    {
                        countConnElements = 0;
                        for (int j = 0; j < connComp[i].Count; ++j)
                        {
                            countConnElements += container.CountLeaves(level + 1,
                                                                       branchStart + (int)connComp[i][j]);
                        }

                        if (retArray.Keys.Contains(countConnElements))
                        {
                            retArray[countConnElements] += 1;
                        }
                        else
                        {
                            retArray.Add(countConnElements, 1);
                        }
                    }
                }
            }

            return(retArray);
        }
Ejemplo n.º 2
0
        private SortedDictionary <Double, Double> ConnectedSubgraphsInCluster(int numberNode, int level)
        {
            SortedDictionary <Double, Double> retArray = new SortedDictionary <Double, Double>();

            if (level == container.Level)
            {
                retArray[1] = 1;
                return(retArray);
            }
            BitArray node = container.TreeNode(level, numberNode);

            bool haveOne = false;

            for (int i = 0; i < container.BranchingIndex; i++)
            {
                if (container.CountConnectedBlocks(node, i) == 0)
                {
                    SortedDictionary <Double, Double> array =
                        ConnectedSubgraphsInCluster(numberNode * container.BranchingIndex + i,
                                                    level + 1);

                    foreach (KeyValuePair <Double, Double> kvt in array)
                    {
                        if (retArray.Keys.Contains(kvt.Key))
                        {
                            retArray[kvt.Key] += kvt.Value;
                        }
                        else
                        {
                            retArray.Add(kvt.Key, kvt.Value);
                        }
                    }
                }
                else
                {
                    haveOne = true;
                }
            }

            if (haveOne)
            {
                int powPK = Convert.ToInt32(Math.Pow(container.BranchingIndex, container.Level - level - 1));
                EngineForConnectedComp engForConnectedComponent = new EngineForConnectedComp();
                ArrayList arrConnComp = engForConnectedComponent.GetCountConnSGraph(container.NodeAdjacencyLists(node),
                                                                                    container.BranchingIndex);
                Double uKey = 0;
                for (int i = 0; i < arrConnComp.Count; i++)
                {
                    uKey = ((int)arrConnComp[i] * powPK);
                    if (retArray.Keys.Contains(uKey))
                    {
                        retArray[uKey] += 1;
                    }
                    else
                    {
                        retArray.Add(uKey, 1);
                    }
                }
            }

            return(retArray);
        }