Search in sources :

Example 16 with LongRunningTag

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

the class DnnfCompilerTest method testLargeFormula.

@Test
@LongRunningTag
public void testLargeFormula() throws IOException, ParserException {
    final FormulaFactory f = new FormulaFactory();
    f.putConfiguration(CCConfig.builder().amoEncoding(CCConfig.AMO_ENCODER.PURE).build());
    final Formula parsed = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/formula1.txt", f);
    final DnnfFactory dnnfFactory = new DnnfFactory();
    Dnnf dnnf = dnnfFactory.compile(parsed);
    final BigInteger dnnfCount = dnnf.execute(DnnfModelCountFunction.get());
    final List<Formula> formulas = new ArrayList<>();
    final List<Formula> originalFormulas = new ArrayList<>();
    for (final Formula formula : parsed) {
        originalFormulas.add(formula);
        if (formula instanceof PBConstraint) {
            formulas.add(formula);
        } else {
            formulas.add(formula.transform(new CNFFactorization()));
        }
    }
    final Graph<Variable> constraintGraph = ConstraintGraphGenerator.generateFromCnf(formulas);
    final Set<Set<Node<Variable>>> ccs = ConnectedComponentsComputation.compute(constraintGraph);
    final List<List<Formula>> split = ConnectedComponentsComputation.splitFormulasByComponent(originalFormulas, ccs);
    BigInteger multipliedCount = BigInteger.ONE;
    for (final List<Formula> component : split) {
        dnnf = dnnfFactory.compile(f.and(component));
        multipliedCount = multipliedCount.multiply(dnnf.execute(DnnfModelCountFunction.get()));
    }
    assertThat(dnnfCount).isEqualTo(multipliedCount);
}
Also used : Dnnf(org.logicng.knowledgecompilation.dnnf.datastructures.Dnnf) Variable(org.logicng.formulas.Variable) Set(java.util.Set) ArrayList(java.util.ArrayList) Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) List(java.util.List) PBConstraint(org.logicng.formulas.PBConstraint) CNFFactorization(org.logicng.transformations.cnf.CNFFactorization) LongRunningTag(org.logicng.LongRunningTag) Test(org.junit.jupiter.api.Test)

Example 17 with LongRunningTag

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

the class CNFSubsumptionTest method testEvenLargerFormula.

@Test
@LongRunningTag
public void testEvenLargerFormula() throws IOException, ParserException {
    final FormulaFactory f = new FormulaFactory();
    final Formula formula = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/large_formula.txt", f);
    final Formula cnf = formula.transform(new CNFFactorization());
    final Formula subsumed = cnf.transform(new CNFSubsumption());
    assertThat(f.equivalence(cnf, subsumed).holds(new TautologyPredicate(f))).isTrue();
    assertThat(cnf.numberOfOperands() > subsumed.numberOfOperands()).isTrue();
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) TautologyPredicate(org.logicng.predicates.satisfiability.TautologyPredicate) LongRunningTag(org.logicng.LongRunningTag) Test(org.junit.jupiter.api.Test)

Example 18 with LongRunningTag

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

the class AdvancedSimplifierTest method testCancellationPoints.

@LongRunningTag
@Test
public void testCancellationPoints() throws ParserException {
    final FormulaFactory f = new FormulaFactory();
    final Formula formula = f.parse("~v16 & ~v22 & ~v12 & (~v4 | ~v14) & (~v4 | ~v15) & (v3 | v4) & (v3 | ~v14) & (v3 | ~v15) " + "& (~v20 | ~v8) & (v9 | ~v20) & (~v21 | ~v8) & (v9 | ~v21) & (~v21 | ~v10) & (~v21 | ~v11) & v19");
    for (int numOptimizationStarts = 1; numOptimizationStarts < 30; numOptimizationStarts++) {
        for (int numSatHandlerStarts = 1; numSatHandlerStarts < 500; numSatHandlerStarts++) {
            final OptimizationHandler handler = new BoundedOptimizationHandler(numSatHandlerStarts, numOptimizationStarts);
            testHandler(handler, formula, true);
        }
    }
}
Also used : Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) OptimizationHandler(org.logicng.handlers.OptimizationHandler) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) TimeoutOptimizationHandler(org.logicng.handlers.TimeoutOptimizationHandler) LongRunningTag(org.logicng.LongRunningTag) Test(org.junit.jupiter.api.Test)

Aggregations

LongRunningTag (org.logicng.LongRunningTag)18 Test (org.junit.jupiter.api.Test)12 Formula (org.logicng.formulas.Formula)10 LogicNGTest (org.logicng.LogicNGTest)8 FormulaFactory (org.logicng.formulas.FormulaFactory)8 Variable (org.logicng.formulas.Variable)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 CardinalityConstraint (org.logicng.formulas.CardinalityConstraint)6 SATSolver (org.logicng.solvers.SATSolver)6 ArrayList (java.util.ArrayList)5 Assignment (org.logicng.datastructures.Assignment)4 BufferedReader (java.io.BufferedReader)3 FileReader (java.io.FileReader)3 List (java.util.List)3 Backbone (org.logicng.backbones.Backbone)3 File (java.io.File)2 BoundedOptimizationHandler (org.logicng.handlers.BoundedOptimizationHandler)2 OptimizationHandler (org.logicng.handlers.OptimizationHandler)2 TimeoutOptimizationHandler (org.logicng.handlers.TimeoutOptimizationHandler)2