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());
}
Aggregations