Esempio n. 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());
        }
Esempio n. 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());
        }