Example #1
0
        /// <summary>
        /// Given an array of predidates {p_1, p_2, ..., p_n} where n>=0,
        /// enumerate all satisfiable Boolean combinations Tuple({b_1, b_2, ..., b_n}, p)
        /// where p is satisfiable and equivalent to p'_1 &amp; p'_2 &amp; ... &amp; p'_n,
        /// where p'_i = p_i if b_i = true and p'_i is Not(p_i). Otherwise, if n=0
        /// return Tuple({},True).
        /// </summary>
        /// <param name="preds">array of predicates</param>
        /// <returns>all minterms of the given predicate sequence</returns>
        public List <TPredicate> GenerateMinterms(params TPredicate[] preds)
        {
            if (preds.Length == 0)
            {
                return(new List <TPredicate> {
                    _algebra.True
                });
            }

            // The minterms will be solved using non-equivalent predicates, i.e., the equivalence classes of preds. The
            // following code maps each predicate to an equivalence class and also stores for each equivalence class the
            // predicates belonging to it, so that a valuation for the original predicates may be reconstructed.

            var tree = new PartitionTree(_algebra);

            var seen = new HashSet <EquivalenceClass>();

            for (int i = 0; i < preds.Length; i++)
            {
                // Use a wrapper that overloads Equals to be logical equivalence as the key
                if (seen.Add(new EquivalenceClass(_algebra, preds[i])))
                {
                    // Push each equivalence class into the partition tree
                    tree.Refine(preds[i]);
                }
            }

            // Return all minterms as the leaves of the partition tree
            return(tree.GetLeafPredicates());
        }
Example #2
0
        /// <summary>
        /// Given an array of predidates {p_1, p_2, ..., p_n} where n>=0,
        /// enumerate all satisfiable Boolean combinations Tuple({b_1, b_2, ..., b_n}, p)
        /// where p is satisfiable and equivalent to p'_1 &amp; p'_2 &amp; ... &amp; p'_n,
        /// where p'_i = p_i if b_i = true and p'_i is Not(p_i). Otherwise, if n=0
        /// return Tuple({},True).
        /// </summary>
        /// <param name="preds">array of predicates</param>
        /// <returns>all minterms of the given predicate sequence</returns>
        public List <TPredicate> GenerateMinterms(IEnumerable <TPredicate> preds)
        {
            var tree = new PartitionTree(_algebra.True);

            foreach (TPredicate pred in preds)
            {
                // Push each predicate into the partition tree
                tree.Refine(_algebra, pred);
            }
            // Return all minterms as the leaves of the partition tree
            return(tree.GetLeafPredicates());
        }
Example #3
0
        /// <summary>
        /// Given an array of sets {p_1, p_2, ..., p_n} where n>=0,
        /// enumerate all satisfiable (non-empty) Boolean combinations Tuple({b_1, b_2, ..., b_n}, p)
        /// where p is satisfiable and equivalent to p'_1 &amp; p'_2 &amp; ... &amp; p'_n,
        /// where p'_i = p_i if b_i = true and p'_i is Not(p_i). Otherwise, if n=0 return Tuple({},True).
        /// </summary>
        /// <param name="solver">The solver to use for processing the sets.</param>
        /// <param name="sets">The sets from which to generate the minterms.</param>
        /// <returns>All minterms of the given set sequence</returns>
        public static List <TSet> GenerateMinterms(ISolver <TSet> solver, HashSet <TSet> sets)
        {
            var tree = new PartitionTree(solver.Full);

            foreach (TSet set in sets)
            {
                // Push each set into the partition tree
                tree.Refine(solver, set);
            }

            // Return all minterms as the leaves of the partition tree
            return(tree.GetLeafSets());
        }