コード例 #1
0
        protected override double computeCost()
        {
            double maximum = Math.Max(this.SelectedNodeLeft.SubTreeWidth, this.SelectedNodeRight.SubTreeWidth),
                   sum     = this.SelectedNodeLeft.SubTreeSum + this.SelectedNodeRight.SubTreeSum;

            // Find the first common ancestor of a and b.
            DecompositionNode common = this.findCommonAncestor(this.SelectedNodeLeft, this.SelectedNodeRight);

            // Compute the width of the ancestors of a up to the common ancestor.
            this.computeWidthAncestors(this.SelectedNodeLeft, common, this.SelectedNodeRight.Set, this.SelectedNodeLeft.Set, ref maximum, ref sum);
            // Compute the width of the ancestors of b up to the common ancestor.
            this.computeWidthAncestors(this.SelectedNodeRight, common, this.SelectedNodeLeft.Set, this.SelectedNodeRight.Set, ref maximum, ref sum);

            // Compute the width of the first common ancestor.
            if (maximum < common.Width)
            {
                maximum = common.Width;
            }
            sum += common.Width;

            // Compute the width of the remaining common ancestors.
            this.computeWidthAncestors(common, null, null, null, ref maximum, ref sum);

            double topwidth = this.Tree.Root.Right.Width;

            if (common.IsRoot)
            {
                BitSet set = this.Tree.Root.Right.Set - this.SelectedNodeRight.Set | this.SelectedNodeLeft.Set;
                topwidth = this.Tree.WidthParameter.GetWidth(this.Tree.Graph, set);
            }

            return(DecompositionTree.ComputeCost(maximum, this.Tree.VertexCount, sum, topwidth));
        }
コード例 #2
0
        protected override double computeCost()
        {
            double maximum           = this.SelectedNode.SubTreeWidth,
                   sum               = this.SelectedNode.SubTreeSum,
                   topwidth          = this.Tree.Root.Right.Width;
            DecompositionNode common = null;

            if (!this.SelectedNode.Parent.Set.Intersects(this.SelectedSibling.Set))
            {
                maximum = Math.Max(maximum, Math.Max(this.SelectedSibling.SubTreeWidth, this.OriginalSibling.SubTreeWidth));
                sum    += this.SelectedSibling.SubTreeSum + this.OriginalSibling.SubTreeSum;

                // parent
                double width = this.Tree.WidthParameter.GetWidth(this.Tree.Graph, this.SelectedNode.Set | this.SelectedSibling.Set);
                sum += width;
                if (width > maximum)
                {
                    maximum = width;
                }

                // the common ancestor
                common = this.findCommonAncestor(this.SelectedNode.Parent, this.SelectedSibling);
                sum   += common.Width;
                if (maximum < common.Width)
                {
                    maximum = common.Width;
                }

                // update the width of the child of the root
                if (common.IsRoot)
                {
                    BitSet set = this.Tree.Root.Right.Set;
                    if (set.IsSupersetOf(this.SelectedNode.Set))
                    {
                        set -= this.SelectedNode.Set;
                    }
                    else
                    {
                        set |= this.SelectedNode.Set;
                    }
                    topwidth = this.Tree.WidthParameter.GetWidth(this.Tree.Graph, set);
                }

                // ancestors of parent
                this.computeWidthAncestors(this.SelectedNode.Parent, common, null, this.SelectedNode.Set, ref maximum, ref sum);
                // ancestors of the new sibling
                this.computeWidthAncestors(this.SelectedSibling, common, this.SelectedNode.Set, null, ref maximum, ref sum);
            }
            else if (this.SelectedNode.Set.IsSubsetOf(this.SelectedSibling.Set))
            {
                sum += this.OriginalSibling.SubTreeSum;
                if (maximum < this.OriginalSibling.SubTreeWidth)
                {
                    maximum = this.OriginalSibling.SubTreeWidth;
                }

                // parent
                sum += this.SelectedSibling.Width;
                if (maximum < this.SelectedSibling.Width)
                {
                    maximum = this.SelectedSibling.Width;
                }

                // the common ancestor
                common = this.SelectedSibling;

                // update the width of the child of the root.
                if (this.SelectedSibling.IsRoot)
                {
                    topwidth = this.SelectedNode.Width;
                }

                // ancestors of parent
                this.computeWidthAncestors(this.SelectedNode.Parent, this.SelectedSibling.Parent, null, this.SelectedNode.Set, ref maximum, ref sum);
            }
            else // the new sibling is a descendant of the original sibling
            {
                sum += this.SelectedSibling.SubTreeSum;
                if (maximum < this.SelectedSibling.SubTreeWidth)
                {
                    maximum = this.SelectedSibling.SubTreeWidth;
                }

                // parent
                double width = this.Tree.WidthParameter.GetWidth(this.Tree.Graph, this.SelectedNode.Set | this.SelectedSibling.Set);
                sum += width;
                if (maximum < width)
                {
                    maximum = width;
                }

                // the common ancestor
                common = this.SelectedNode.Parent;

                // update the width of the child of the root.
                if (this.SelectedNode.Parent.IsRoot)
                {
                    topwidth = this.OriginalSibling.Right.Set.IsSupersetOf(this.SelectedSibling.Set) ? this.OriginalSibling.Left.Width : this.OriginalSibling.Right.Width;
                }

                // ancestors of the new sibling
                this.computeWidthAncestors(this.SelectedSibling, this.SelectedNode.Parent, this.SelectedNode.Set, null, ref maximum, ref sum);
            }

            // common ancestors
            this.computeWidthAncestors(common, null, null, null, ref maximum, ref sum);

            return(DecompositionTree.ComputeCost(maximum, this.Tree.VertexCount, sum, topwidth));
        }