use of org.logicng.LongRunningTag in project LogicNG by logic-ng.
the class BackboneFunctionTest method testRealFormulaIncremental2.
@ParameterizedTest
@MethodSource("solvers")
@LongRunningTag
public void testRealFormulaIncremental2(final MiniSat solver) throws IOException, ParserException {
solver.reset();
final Formula formula = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/small_formulas.txt", f);
solver.add(formula);
final List<String> expectedBackbones = new ArrayList<>();
final BufferedReader reader = new BufferedReader(new FileReader("src/test/resources/backbones/backbone_small_formulas.txt"));
while (reader.ready()) {
expectedBackbones.add(reader.readLine());
}
reader.close();
Backbone backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(0)));
solver.add(f.variable("v2609"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(1)));
assertThat(backbone.isSat()).isTrue();
solver.add(f.variable("v2416"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(2)));
assertThat(backbone.isSat()).isTrue();
solver.add(f.variable("v2048"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(3)));
assertThat(backbone.isSat()).isTrue();
solver.add(f.variable("v39"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(4)));
assertThat(backbone.isSat()).isTrue();
solver.add(f.variable("v1663"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(5)));
assertThat(backbone.isSat()).isTrue();
solver.add(f.variable("v2238"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEmpty();
assertThat(backbone.isSat()).isFalse();
}
use of org.logicng.LongRunningTag in project LogicNG by logic-ng.
the class BackboneFunctionTest method testRealFormulaIncrementalDecremental2.
@ParameterizedTest
@MethodSource("solvers")
@LongRunningTag
public void testRealFormulaIncrementalDecremental2(final MiniSat solver) throws IOException, ParserException {
if (solver.underlyingSolver() instanceof MiniSat2Solver) {
solver.reset();
final Formula formula = FormulaReader.readPseudoBooleanFormula("src/test/resources/formulas/small_formulas.txt", f);
solver.add(formula);
final SolverState state = solver.saveState();
final List<String> expectedBackbones = new ArrayList<>();
final BufferedReader reader = new BufferedReader(new FileReader("src/test/resources/backbones/backbone_small_formulas.txt"));
while (reader.ready()) {
expectedBackbones.add(reader.readLine());
}
reader.close();
Backbone backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(0)));
solver.add(f.variable("v2609"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(1)));
assertThat(backbone.isSat()).isTrue();
solver.loadState(state);
solver.add(f.parse("v2609 & v2416"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(2)));
assertThat(backbone.isSat()).isTrue();
solver.loadState(state);
solver.add(f.parse("v2609 & v2416 & v2048"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(3)));
assertThat(backbone.isSat()).isTrue();
solver.loadState(state);
solver.add(f.parse("v2609 & v2416 & v2048 & v39"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(4)));
assertThat(backbone.isSat()).isTrue();
solver.loadState(state);
solver.add(f.parse("v2609 & v2416 & v2048 & v39 & v1663"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEqualTo(parseBackbone(expectedBackbones.get(5)));
assertThat(backbone.isSat()).isTrue();
solver.loadState(state);
solver.add(f.parse("v2609 & v2416 & v2048 & v39 & v1663 & v2238"));
backbone = solver.backbone(formula.variables());
assertThat(backbone.getCompleteBackbone()).isEmpty();
assertThat(backbone.isSat()).isFalse();
}
}
use of org.logicng.LongRunningTag 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();
}
}
use of org.logicng.LongRunningTag in project LogicNG by logic-ng.
the class OptimizationFunctionTest method testLargerFormulaMinimize.
@ParameterizedTest
@MethodSource("solvers")
@LongRunningTag
public void testLargerFormulaMinimize(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/small_formulas.txt", f);
final Assignment minimumModel = optimize(Collections.singleton(formula), formula.variables(), Collections.emptyList(), false, solver, null);
testMinimumModel(formula, minimumModel, formula.variables());
}
use of org.logicng.LongRunningTag in project LogicNG by logic-ng.
the class OptimizationFunctionTest method testLargerFormulaMaximize.
@ParameterizedTest
@MethodSource("solvers")
@LongRunningTag
public void testLargerFormulaMaximize(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/small_formulas.txt", f);
final Assignment maximumModel = optimize(Collections.singleton(formula), formula.variables(), Collections.emptyList(), true, solver, null);
testMaximumModel(formula, maximumModel, formula.variables());
}
Aggregations