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