Search in sources :

Example 1 with BoundedOptimizationHandler

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

the class SmusComputationTest method testCancellationPoints.

@Test
public void testCancellationPoints() throws IOException {
    final List<Formula> formulas = DimacsReader.readCNF("src/test/resources/sat/unsat/bf0432-007.cnf", this.f);
    for (int numOptimizationStarts = 1; numOptimizationStarts < 5; numOptimizationStarts++) {
        for (int numSatHandlerStarts = 1; numSatHandlerStarts < 10; numSatHandlerStarts++) {
            final OptimizationHandler handler = new BoundedOptimizationHandler(numSatHandlerStarts, numOptimizationStarts);
            testHandler(handler, formulas, true);
        }
    }
}
Also used : Formula(org.logicng.formulas.Formula) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) OptimizationHandler(org.logicng.handlers.OptimizationHandler) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) TimeoutOptimizationHandler(org.logicng.handlers.TimeoutOptimizationHandler) Test(org.junit.jupiter.api.Test)

Example 2 with BoundedOptimizationHandler

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

the class SmusComputationTest method testHSolverCancelled.

@Test
public void testHSolverCancelled() throws ParserException {
    final OptimizationHandler handler = new BoundedOptimizationHandler(-1, 3);
    final List<Formula> formulas = Arrays.asList(this.f.parse("a"), this.f.parse("~a"), this.f.parse("c"));
    testHandler(handler, formulas, true);
}
Also used : Formula(org.logicng.formulas.Formula) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) OptimizationHandler(org.logicng.handlers.OptimizationHandler) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) TimeoutOptimizationHandler(org.logicng.handlers.TimeoutOptimizationHandler) Test(org.junit.jupiter.api.Test)

Example 3 with BoundedOptimizationHandler

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

the class SmusComputationTest method testMinimumHittingSetCancelled.

@Test
public void testMinimumHittingSetCancelled() throws ParserException {
    final OptimizationHandler handler = new BoundedOptimizationHandler(-1, 0);
    final List<Formula> formulas = Arrays.asList(this.f.parse("a"), this.f.parse("~a"));
    testHandler(handler, formulas, true);
}
Also used : Formula(org.logicng.formulas.Formula) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) OptimizationHandler(org.logicng.handlers.OptimizationHandler) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) TimeoutOptimizationHandler(org.logicng.handlers.TimeoutOptimizationHandler) Test(org.junit.jupiter.api.Test)

Example 4 with BoundedOptimizationHandler

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

the class OptimizationFunctionTest method testCancellationPoints.

@LongRunningTag
@ParameterizedTest
@MethodSource("solvers")
public void testCancellationPoints(final SATSolver solver) throws IOException {
    final FormulaFactory f = new FormulaFactory();
    final SortedSet<Variable> selVars = new TreeSet<>();
    final List<Formula> clauses = DimacsReader.readCNF("src/test/resources/sat/c499_gr_rcs_w6.shuffled.cnf", f);
    final List<Formula> formulas = new ArrayList<>();
    for (final Formula clause : clauses) {
        final Variable selVar = f.variable("@SEL_" + selVars.size());
        selVars.add(selVar);
        formulas.add(f.equivalence(selVar, clause));
    }
    for (int numSatHandlerStarts = 1; numSatHandlerStarts < 5; numSatHandlerStarts++) {
        solver.reset();
        solver.add(formulas);
        final OptimizationHandler handler = new BoundedOptimizationHandler(numSatHandlerStarts, -1);
        final OptimizationFunction optimizationFunction = OptimizationFunction.builder().handler(handler).literals(selVars).maximize().build();
        final Assignment result = solver.execute(optimizationFunction);
        assertThat(handler.aborted()).isTrue();
        assertThat(result).isNull();
    }
}
Also used : Assignment(org.logicng.datastructures.Assignment) Formula(org.logicng.formulas.Formula) FormulaFactory(org.logicng.formulas.FormulaFactory) Variable(org.logicng.formulas.Variable) TreeSet(java.util.TreeSet) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) OptimizationHandler(org.logicng.handlers.OptimizationHandler) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) TimeoutOptimizationHandler(org.logicng.handlers.TimeoutOptimizationHandler) ArrayList(java.util.ArrayList) CardinalityConstraint(org.logicng.formulas.CardinalityConstraint) LongRunningTag(org.logicng.LongRunningTag) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with BoundedOptimizationHandler

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

the class PrimeCompilerTest method testCancellationPoints.

@Test
public void testCancellationPoints() throws IOException, ParserException {
    final Formula formula = this.f.parse(Files.readAllLines(Paths.get("src/test/resources/formulas/simplify_formulas.txt")).get(0));
    final List<Pair<PrimeCompiler, PrimeResult.CoverageType>> compilers = Arrays.asList(new Pair<>(PrimeCompiler.getWithMaximization(), PrimeResult.CoverageType.IMPLICANTS_COMPLETE), new Pair<>(PrimeCompiler.getWithMaximization(), PrimeResult.CoverageType.IMPLICATES_COMPLETE), new Pair<>(PrimeCompiler.getWithMinimization(), PrimeResult.CoverageType.IMPLICANTS_COMPLETE), new Pair<>(PrimeCompiler.getWithMinimization(), PrimeResult.CoverageType.IMPLICATES_COMPLETE));
    for (final Pair<PrimeCompiler, PrimeResult.CoverageType> compiler : compilers) {
        for (int numOptimizationStarts = 1; numOptimizationStarts < 5; numOptimizationStarts++) {
            for (int numSatHandlerStarts = 1; numSatHandlerStarts < 10; numSatHandlerStarts++) {
                final OptimizationHandler handler = new BoundedOptimizationHandler(numSatHandlerStarts, numOptimizationStarts);
                testHandler(handler, formula, compiler.first(), compiler.second(), true);
            }
        }
    }
}
Also used : Formula(org.logicng.formulas.Formula) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) OptimizationHandler(org.logicng.handlers.OptimizationHandler) BoundedOptimizationHandler(org.logicng.handlers.BoundedOptimizationHandler) TimeoutOptimizationHandler(org.logicng.handlers.TimeoutOptimizationHandler) Pair(org.logicng.util.Pair) Test(org.junit.jupiter.api.Test)

Aggregations

Formula (org.logicng.formulas.Formula)8 BoundedOptimizationHandler (org.logicng.handlers.BoundedOptimizationHandler)8 OptimizationHandler (org.logicng.handlers.OptimizationHandler)8 TimeoutOptimizationHandler (org.logicng.handlers.TimeoutOptimizationHandler)8 Test (org.junit.jupiter.api.Test)7 LongRunningTag (org.logicng.LongRunningTag)2 FormulaFactory (org.logicng.formulas.FormulaFactory)2 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 Assignment (org.logicng.datastructures.Assignment)1 CardinalityConstraint (org.logicng.formulas.CardinalityConstraint)1 Variable (org.logicng.formulas.Variable)1 Pair (org.logicng.util.Pair)1