Search in sources :

Example 1 with UBTree

use of org.logicng.datastructures.ubtrees.UBTree in project LogicNG by logic-ng.

the class Subsumption method generateSubsumedUBTree.

/**
 * Generates a UBTree from the formulas operands (clauses in CNF, minterms in DNF)
 * where all subsumed operands are already deleted.
 * @param formula the formula (must be an n-ary operator and CNF or DNF)
 * @return the UBTree with the operands and deleted subsumed operands
 */
protected static UBTree<Literal> generateSubsumedUBTree(final Formula formula) {
    final SortedMap<Integer, List<SortedSet<Literal>>> mapping = new TreeMap<>();
    for (final Formula term : formula) {
        mapping.computeIfAbsent(term.literals().size(), k -> new ArrayList<>()).add(term.literals());
    }
    final UBTree<Literal> ubTree = new UBTree<>();
    for (final Map.Entry<Integer, List<SortedSet<Literal>>> entry : mapping.entrySet()) {
        for (final SortedSet<Literal> set : entry.getValue()) {
            if (ubTree.firstSubset(set) == null) {
                ubTree.addSet(set);
            }
        }
    }
    return ubTree;
}
Also used : Literal(org.logicng.formulas.Literal) List(java.util.List) SortedSet(java.util.SortedSet) TreeMap(java.util.TreeMap) UBTree(org.logicng.datastructures.ubtrees.UBTree) Map(java.util.Map) Formula(org.logicng.formulas.Formula) SortedMap(java.util.SortedMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Formula(org.logicng.formulas.Formula) Literal(org.logicng.formulas.Literal) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap) UBTree(org.logicng.datastructures.ubtrees.UBTree)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 SortedSet (java.util.SortedSet)1 TreeMap (java.util.TreeMap)1 UBTree (org.logicng.datastructures.ubtrees.UBTree)1 Formula (org.logicng.formulas.Formula)1 Literal (org.logicng.formulas.Literal)1