Search in sources :

Example 1 with LongRunningTag

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

the class CCIncrementalFormulaTest method testVeryLargeModularTotalizerAMK.

@Test
@LongRunningTag
public void testVeryLargeModularTotalizerAMK() {
    final CCEncoder encoder = this.encoders[2];
    final CCEncoder initivalEncoder = new CCEncoder(this.f);
    final int numLits = 300;
    int currentBound = numLits - 1;
    final Variable[] vars = new Variable[numLits];
    for (int i = 0; i < numLits; i++) {
        vars[i] = this.f.variable("v" + i);
    }
    final Pair<List<Formula>, CCIncrementalData> cc = encoder.encodeIncremental((CardinalityConstraint) this.f.cc(CType.LE, currentBound, vars));
    final CCIncrementalData incData = cc.second();
    final SATSolver solver = this.solvers[3];
    solver.reset();
    solver.add(initivalEncoder.encode((CardinalityConstraint) this.f.cc(CType.GE, 234, vars)));
    solver.add(cc.first());
    // search the lower bound
    while (solver.sat() == Tristate.TRUE) {
        solver.add(incData.newUpperBound(--currentBound));
    }
    assertThat(currentBound).isEqualTo(233);
}
Also used : SATSolver(org.logicng.solvers.SATSolver) Variable(org.logicng.formulas.Variable) CardinalityConstraint(org.logicng.formulas.CardinalityConstraint) List(java.util.List) CardinalityConstraint(org.logicng.formulas.CardinalityConstraint) LongRunningTag(org.logicng.LongRunningTag) Test(org.junit.jupiter.api.Test) LogicNGTest(org.logicng.LogicNGTest)

Example 2 with LongRunningTag

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

the class CCIncrementalSolverTest method testLargeModularTotalizerAMK.

@Test
@LongRunningTag
public void testLargeModularTotalizerAMK() {
    for (final SATSolver solver : this.solvers) {
        if (solver != null) {
            this.f.putConfiguration(this.configs[2]);
            final int numLits = 100;
            int currentBound = numLits - 1;
            final Variable[] vars = new Variable[numLits];
            for (int i = 0; i < numLits; i++) {
                vars[i] = this.f.variable("v" + i);
            }
            solver.reset();
            // >= 42
            solver.add(this.f.cc(CType.GE, 42, vars));
            final CCIncrementalData incData = solver.addIncrementalCC((CardinalityConstraint) this.f.cc(CType.LE, currentBound, vars));
            // search the lower bound
            while (solver.sat() == Tristate.TRUE) {
                // <= currentBound - 1
                incData.newUpperBoundForSolver(--currentBound);
            }
            assertThat(currentBound).isEqualTo(41);
        }
    }
}
Also used : SATSolver(org.logicng.solvers.SATSolver) Variable(org.logicng.formulas.Variable) CardinalityConstraint(org.logicng.formulas.CardinalityConstraint) LongRunningTag(org.logicng.LongRunningTag) Test(org.junit.jupiter.api.Test) LogicNGTest(org.logicng.LogicNGTest)

Example 3 with LongRunningTag

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

the class CCPerformanceTest method testAMKPerformance.

@Test
@LongRunningTag
public void testAMKPerformance() {
    for (final CCConfig config : this.configs) {
        final FormulaFactory f = new FormulaFactory();
        f.putConfiguration(config);
        buildAMK(10_000, f, false);
        assertThat(f.newCCVariable().name()).endsWith("_0");
    }
}
Also used : FormulaFactory(org.logicng.formulas.FormulaFactory) LongRunningTag(org.logicng.LongRunningTag) Test(org.junit.jupiter.api.Test) LogicNGTest(org.logicng.LogicNGTest)

Example 4 with LongRunningTag

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

the class CCAMKTest method testLargeAMK.

@Test
@LongRunningTag
public void testLargeAMK() {
    final FormulaFactory f = new FormulaFactory();
    int counter = 0;
    for (final CCConfig config : this.configs) {
        f.putConfiguration(config);
        testCC(150, 2, 1 + 150 + 11175, f, false);
        assertThat(f.newCCVariable().name()).endsWith("_" + counter++);
    }
}
Also used : FormulaFactory(org.logicng.formulas.FormulaFactory) CardinalityConstraint(org.logicng.formulas.CardinalityConstraint) LongRunningTag(org.logicng.LongRunningTag) Test(org.junit.jupiter.api.Test) LogicNGTest(org.logicng.LogicNGTest)

Example 5 with LongRunningTag

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

the class SATTest method testDimacsFilesWithSelectionOrder.

@Test
@LongRunningTag
public void testDimacsFilesWithSelectionOrder() throws IOException {
    final Map<String, Boolean> expectedResults = new HashMap<>();
    final BufferedReader reader = new BufferedReader(new FileReader("src/test/resources/sat/results.txt"));
    while (reader.ready()) {
        final String[] tokens = reader.readLine().split(";");
        expectedResults.put(tokens[0], Boolean.valueOf(tokens[1]));
    }
    final File testFolder = new File("src/test/resources/sat");
    final File[] files = testFolder.listFiles();
    assert files != null;
    for (final SATSolver solver : this.solvers) {
        for (final File file : files) {
            final String fileName = file.getName();
            if (fileName.endsWith(".cnf")) {
                readCNF(solver, file);
                final List<Literal> selectionOrder = new ArrayList<>();
                for (final Variable var : FormulaHelper.variables(solver.execute(FormulaOnSolverFunction.get()))) {
                    if (selectionOrder.size() < 10) {
                        selectionOrder.add(var.negate());
                    }
                }
                final boolean res = solver.satWithSelectionOrder(selectionOrder) == Tristate.TRUE;
                assertThat(res).isEqualTo(expectedResults.get(fileName));
                if (expectedResults.get(fileName)) {
                    final Assignment assignment = solver.model();
                    testLocalMinimum(solver, assignment, selectionOrder);
                    testHighestLexicographicalAssignment(solver, assignment, selectionOrder);
                }
            }
        }
        solver.reset();
    }
}
Also used : SATSolver(org.logicng.solvers.SATSolver) Variable(org.logicng.formulas.Variable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Assignment(org.logicng.datastructures.Assignment) Literal(org.logicng.formulas.Literal) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) LongRunningTag(org.logicng.LongRunningTag) LogicNGTest(org.logicng.LogicNGTest) 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