Search in sources :

Example 1 with PrimeResult

use of org.logicng.primecomputation.PrimeResult in project LogicNG by logic-ng.

the class AdvancedSimplifier method apply.

@Override
public Formula apply(final Formula formula, final boolean cache) {
    start(this.handler);
    final FormulaFactory f = formula.factory();
    final Backbone backbone = BackboneGeneration.compute(Collections.singletonList(formula), formula.variables(), BackboneType.POSITIVE_AND_NEGATIVE, satHandler(this.handler));
    if (backbone == null || aborted(this.handler)) {
        return null;
    }
    if (!backbone.isSat()) {
        return f.falsum();
    }
    final SortedSet<Literal> backboneLiterals = backbone.getCompleteBackbone();
    final Formula restrictedFormula = formula.restrict(new Assignment(backboneLiterals));
    final PrimeResult primeResult = PrimeCompiler.getWithMinimization().compute(restrictedFormula, PrimeResult.CoverageType.IMPLICANTS_COMPLETE, this.handler);
    if (primeResult == null || aborted(this.handler)) {
        return null;
    }
    final List<SortedSet<Literal>> primeImplicants = primeResult.getPrimeImplicants();
    final List<Formula> minimizedPIs = SmusComputation.computeSmusForFormulas(negateAllLiterals(primeImplicants, f), Collections.singletonList(restrictedFormula), f, this.handler);
    if (minimizedPIs == null || aborted(this.handler)) {
        return null;
    }
    final Formula minDnf = f.or(negateAllLiteralsInFormulas(minimizedPIs, f).stream().map(f::and).collect(Collectors.toList()));
    final Formula fullFactor = minDnf.transform(new FactorOutSimplifier(this.ratingFunction));
    return f.and(f.and(backboneLiterals), fullFactor).transform(new NegationSimplifier());
}
Also used : Backbone(org.logicng.backbones.Backbone) SortedSet(java.util.SortedSet) Assignment(org.logicng.datastructures.Assignment) Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) Literal(org.logicng.formulas.Literal) PrimeResult(org.logicng.primecomputation.PrimeResult)

Aggregations

SortedSet (java.util.SortedSet)1 Backbone (org.logicng.backbones.Backbone)1 Assignment (org.logicng.datastructures.Assignment)1 Formula (org.logicng.formulas.Formula)1 FormulaFactory (org.logicng.formulas.FormulaFactory)1 Literal (org.logicng.formulas.Literal)1 PrimeResult (org.logicng.primecomputation.PrimeResult)1