Search in sources :

Example 1 with TimeoutOptimizationHandler

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

the class SmusComputationTest method testTimeoutHandlerLarge.

@Test
public void testTimeoutHandlerLarge() throws ParserException, IOException {
    final List<TimeoutOptimizationHandler> handlers = Arrays.asList(new TimeoutOptimizationHandler(1L, TimeoutHandler.TimerType.SINGLE_TIMEOUT), new TimeoutOptimizationHandler(1L, TimeoutHandler.TimerType.RESTARTING_TIMEOUT), new TimeoutOptimizationHandler(System.currentTimeMillis() + 1L, TimeoutHandler.TimerType.FIXED_END));
    final Formula formula = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/large_formula.txt", this.f);
    final List<Formula> formulas = formula.stream().collect(Collectors.toList());
    for (final TimeoutOptimizationHandler handler : handlers) {
        testHandler(handler, formulas, true);
    }
}
Also used : TimeoutOptimizationHandler(org.logicng.handlers.TimeoutOptimizationHandler) Formula(org.logicng.formulas.Formula) Test(org.junit.jupiter.api.Test)

Example 2 with TimeoutOptimizationHandler

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

the class OptimizationFunctionTest method testTimeoutOptimizationHandler.

@ParameterizedTest
@MethodSource("solvers")
public void testTimeoutOptimizationHandler(final SATSolver solver) throws IOException, ParserException {
    final FormulaFactory f = new FormulaFactory(FormulaFactoryConfig.builder().formulaMergeStrategy(FormulaFactoryConfig.FormulaMergeStrategy.IMPORT).build());
    final Formula formula = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/large_formula.txt", f);
    final TimeoutOptimizationHandler handlerMax = new TimeoutOptimizationHandler(1L);
    final Assignment maximumModel = optimize(Collections.singleton(formula), formula.variables(), Collections.emptyList(), true, solver, handlerMax);
    assertThat(maximumModel).isNull();
    assertThat(handlerMax.aborted()).isTrue();
    final TimeoutOptimizationHandler handlerTooShort = new TimeoutOptimizationHandler(1L);
    final Assignment model = optimize(Collections.singleton(formula), formula.variables(), Collections.emptyList(), false, solver, handlerTooShort);
    assertThat(model).isNull();
    assertThat(handlerTooShort.aborted()).isTrue();
    // SATHandler aborted before a model could be computed
    assertThat(handlerTooShort.getIntermediateResult()).isNull();
    final CustomOptimizationHandler customHandler = new CustomOptimizationHandler();
    final Assignment modelCustom = optimize(Collections.singleton(formula), formula.variables(), Collections.emptyList(), true, solver, customHandler);
    assertThat(modelCustom).isNull();
    assertThat(customHandler.aborted()).isTrue();
    assertThat(customHandler.currentResult).isNotNull();
}
Also used : Assignment(org.logicng.datastructures.Assignment) Formula(org.logicng.formulas.Formula) TimeoutOptimizationHandler(org.logicng.handlers.TimeoutOptimizationHandler) FormulaFactory(org.logicng.formulas.FormulaFactory) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with TimeoutOptimizationHandler

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

the class PrimeCompilerTest method testTimeoutHandlerLarge.

@Test
public void testTimeoutHandlerLarge() throws ParserException, IOException {
    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) {
        final List<TimeoutOptimizationHandler> handlers = Arrays.asList(new TimeoutOptimizationHandler(1L, TimeoutHandler.TimerType.SINGLE_TIMEOUT), new TimeoutOptimizationHandler(1L, TimeoutHandler.TimerType.RESTARTING_TIMEOUT), new TimeoutOptimizationHandler(System.currentTimeMillis() + 1L, TimeoutHandler.TimerType.FIXED_END));
        final Formula formula = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/large_formula.txt", this.f);
        for (final TimeoutOptimizationHandler handler : handlers) {
            testHandler(handler, formula, compiler.first(), compiler.second(), true);
        }
    }
}
Also used : TimeoutOptimizationHandler(org.logicng.handlers.TimeoutOptimizationHandler) Formula(org.logicng.formulas.Formula) Pair(org.logicng.util.Pair) Test(org.junit.jupiter.api.Test)

Example 4 with TimeoutOptimizationHandler

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

the class AdvancedSimplifierTest method testTimeoutHandlerSmall.

@Test
public void testTimeoutHandlerSmall() throws ParserException {
    final List<TimeoutOptimizationHandler> handlers = Arrays.asList(new TimeoutOptimizationHandler(5_000L, TimeoutHandler.TimerType.SINGLE_TIMEOUT), new TimeoutOptimizationHandler(5_000L, TimeoutHandler.TimerType.RESTARTING_TIMEOUT), new TimeoutOptimizationHandler(System.currentTimeMillis() + 5_000L, TimeoutHandler.TimerType.FIXED_END));
    final Formula formula = this.f.parse("a & b | ~c & a");
    for (final TimeoutOptimizationHandler handler : handlers) {
        testHandler(handler, formula, false);
    }
}
Also used : TimeoutOptimizationHandler(org.logicng.handlers.TimeoutOptimizationHandler) Formula(org.logicng.formulas.Formula) Test(org.junit.jupiter.api.Test)

Example 5 with TimeoutOptimizationHandler

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

the class SmusComputationTest method testTimeoutHandlerSmall.

@Test
public void testTimeoutHandlerSmall() throws ParserException {
    final List<TimeoutOptimizationHandler> handlers = Arrays.asList(new TimeoutOptimizationHandler(5_000L, TimeoutHandler.TimerType.SINGLE_TIMEOUT), new TimeoutOptimizationHandler(5_000L, TimeoutHandler.TimerType.RESTARTING_TIMEOUT), new TimeoutOptimizationHandler(System.currentTimeMillis() + 5_000L, TimeoutHandler.TimerType.FIXED_END));
    final List<Formula> formulas = Arrays.asList(this.f.parse("a"), this.f.parse("~a"));
    for (final TimeoutOptimizationHandler handler : handlers) {
        testHandler(handler, formulas, false);
    }
}
Also used : TimeoutOptimizationHandler(org.logicng.handlers.TimeoutOptimizationHandler) Formula(org.logicng.formulas.Formula) Test(org.junit.jupiter.api.Test)

Aggregations

Formula (org.logicng.formulas.Formula)7 TimeoutOptimizationHandler (org.logicng.handlers.TimeoutOptimizationHandler)7 Test (org.junit.jupiter.api.Test)6 Pair (org.logicng.util.Pair)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 Assignment (org.logicng.datastructures.Assignment)1 FormulaFactory (org.logicng.formulas.FormulaFactory)1