コード例 #1
0
        /// <summary>
        /// Returns a new formula that repairs the order after a substitution.
        /// </summary>
        /// <param name="level">Variable level of the new node.</param>
        /// <param name="lo">The node's lo branch.</param>
        /// <param name="hi">The node's hi branch.</param>
        /// <returns></returns>
        private DDIndex RepairOrder(int level, DDIndex lo, DDIndex hi)
        {
            var loNode = this.Manager.MemoryPool[lo.GetPosition()];
            var hiNode = this.Manager.MemoryPool[hi.GetPosition()];

            loNode = lo.IsComplemented() ? Flip(loNode) : loNode;
            hiNode = hi.IsComplemented() ? Flip(hiNode) : hiNode;

            var loConst = lo.IsConstant();
            var hiConst = hi.IsConstant();

            var loLevel = loConst ? int.MaxValue : loNode.Variable;
            var hiLevel = hiConst ? int.MaxValue : hiNode.Variable;

            if (level < loLevel && level < hiLevel)
            {
                return(this.Manager.Allocate(new BDDNode(level, lo, hi)));
            }
            else if (loLevel < hiLevel)
            {
                var l = RepairOrder(level, loNode.Low, hi);
                var h = RepairOrder(level, loNode.High, hi);
                return(this.Manager.Allocate(new BDDNode(loNode.Variable, l, h)));
            }
            else if (loLevel > hiLevel)
            {
                var l = RepairOrder(level, lo, hiNode.Low);
                var h = RepairOrder(level, lo, hiNode.High);
                return(this.Manager.Allocate(new BDDNode(hiNode.Variable, l, h)));
            }
            else
            {
                var l = RepairOrder(level, loNode.Low, hiNode.Low);
                var h = RepairOrder(level, loNode.High, hiNode.High);
                return(this.Manager.Allocate(new BDDNode(loNode.Variable, l, h)));
            }
        }
コード例 #2
0
 /// <summary>
 /// Gets the "level" for the node, where the maximum
 /// value is used for constants.
 /// </summary>
 /// <param name="idx">The node index.</param>
 /// <param name="node">The node.</param>
 /// <returns></returns>
 private int Level(DDIndex idx, BDDNode node)
 {
     return(idx.IsConstant() ? int.MaxValue : node.Variable);
 }