예제 #1
0
        /// <summary>
        /// Creates the join tree (or forest) of this hypergraph.
        /// If the graph is not acylic, it returns null.
        /// </summary>
        public DynamicForest GetJoinTree()
        {
            if (!IsAcyclic)
            {
                return(null);
            }

            DynamicForest forest = new DynamicForest(edgeList.Length);

            for (int eId = 0; eId < edgeList.Length; eId++)
            {
                forest.AddVertex();
            }

            for (int eId = 0; eId < edgeList.Length; eId++)
            {
                int gamma = ai.gamma[eId];

                if (gamma < 0)
                {
                    continue;
                }

                int parId = ai.R[gamma];
                forest.SetParent(eId, parId);
            }

            return(forest);
        }
예제 #2
0
        private void PrepareTree()
        {
            int          centerCount = 0;
            List <int[]> allCenters  = new List <int[]>(forest.NumberOfTrees);

            int[] roots = forest.GetRoots();
            foreach (int rId in roots)
            {
                int[] centers = forest.GetCenter(rId);
                centerCount += centers.Length;
                allCenters.Add(centers);
            }

            foreach (int[] centers in allCenters)
            {
                forest.SetToRoot(centers[0]);
            }

            if (centerCount > 1)
            {
                // Forest is not connected or has two centers.
                // Add dummy root.

                isDummyRoot = true;
                rootId      = forest.AddVertex();

                foreach (int[] centers in allCenters)
                {
                    foreach (int c in centers)
                    {
                        forest.SetParent(c, rootId);
                    }
                }
            }
            else
            {
                isDummyRoot = false;
                rootId      = allCenters[0][0];
            }
        }