Search in sources :

Example 11 with Literal

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

the class CCCardinalityNetworks method buildAMKForIncremental.

void buildAMKForIncremental(final EncodingResult result, final Variable[] vars, final int rhs) {
    final LNGVector<Literal> input = new LNGVector<>();
    final LNGVector<Literal> output = new LNGVector<>();
    for (final Variable var : vars) {
        input.push(var);
    }
    this.sorting.sort(rhs + 1, input, result, output, INPUT_TO_OUTPUT);
    assert output.size() > rhs;
    result.addClause(output.get(rhs).negate());
    this.incData = new CCIncrementalData(result, CCConfig.AMK_ENCODER.CARDINALITY_NETWORK, rhs, output);
}
Also used : Variable(org.logicng.formulas.Variable) Literal(org.logicng.formulas.Literal) LNGVector(org.logicng.collections.LNGVector)

Example 12 with Literal

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

the class CCCardinalityNetworks method buildALKForIncremental.

void buildALKForIncremental(final EncodingResult result, final Variable[] vars, final int rhs) {
    final LNGVector<Literal> input = new LNGVector<>();
    final LNGVector<Literal> output = new LNGVector<>();
    for (final Variable var : vars) {
        input.push(var.negate());
    }
    final int newRHS = vars.length - rhs;
    this.sorting.sort(newRHS + 1, input, result, output, INPUT_TO_OUTPUT);
    assert output.size() > newRHS;
    result.addClause(output.get(newRHS).negate());
    this.incData = new CCIncrementalData(result, CCConfig.ALK_ENCODER.CARDINALITY_NETWORK, rhs, vars.length, output);
}
Also used : Variable(org.logicng.formulas.Variable) Literal(org.logicng.formulas.Literal) LNGVector(org.logicng.collections.LNGVector)

Example 13 with Literal

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

the class CCCardinalityNetworks method buildEXK.

void buildEXK(final EncodingResult result, final Variable[] vars, final int rhs) {
    result.reset();
    final LNGVector<Literal> input = new LNGVector<>();
    final LNGVector<Literal> output = new LNGVector<>();
    for (final Variable var : vars) {
        input.push(var);
    }
    this.sorting.sort(rhs + 1, input, result, output, BOTH);
    assert output.size() > rhs;
    result.addClause(output.get(rhs).negate());
    result.addClause(output.get(rhs - 1));
}
Also used : Variable(org.logicng.formulas.Variable) Literal(org.logicng.formulas.Literal) LNGVector(org.logicng.collections.LNGVector)

Example 14 with Literal

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

the class CCCardinalityNetworks method buildAMK.

void buildAMK(final EncodingResult result, final Variable[] vars, final int rhs) {
    result.reset();
    final LNGVector<Literal> input = new LNGVector<>();
    final LNGVector<Literal> output = new LNGVector<>();
    if (rhs > vars.length / 2) {
        final int geq = vars.length - rhs;
        for (final Variable v : vars) {
            input.push(v.negate());
        }
        this.sorting.sort(geq, input, result, output, OUTPUT_TO_INPUT);
        for (int i = 0; i < geq; i++) {
            result.addClause(output.get(i));
        }
    } else {
        for (final Variable v : vars) {
            input.push(v);
        }
        this.sorting.sort(rhs + 1, input, result, output, INPUT_TO_OUTPUT);
        assert output.size() > rhs;
        result.addClause(output.get(rhs).negate());
    }
}
Also used : Variable(org.logicng.formulas.Variable) Literal(org.logicng.formulas.Literal) LNGVector(org.logicng.collections.LNGVector)

Example 15 with Literal

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

the class EncodingResult method addClause.

/**
 * Adds a clause to the result
 * @param literals the literals of the clause
 */
public void addClause(final LNGVector<Literal> literals) {
    if (this.miniSat == null) {
        this.result.add(this.vec2clause(literals));
    } else {
        final LNGIntVector clauseVec = new LNGIntVector(literals.size());
        for (final Literal l : literals) {
            addLiteral(clauseVec, l);
        }
        this.miniSat.underlyingSolver().addClause(clauseVec, this.proposition);
        this.miniSat.setSolverToUndef();
    }
}
Also used : Literal(org.logicng.formulas.Literal) LNGIntVector(org.logicng.collections.LNGIntVector)

Aggregations

Literal (org.logicng.formulas.Literal)115 Formula (org.logicng.formulas.Formula)51 ArrayList (java.util.ArrayList)38 Test (org.junit.jupiter.api.Test)32 Variable (org.logicng.formulas.Variable)29 FormulaFactory (org.logicng.formulas.FormulaFactory)25 PBConstraint (org.logicng.formulas.PBConstraint)21 TreeSet (java.util.TreeSet)17 SATSolver (org.logicng.solvers.SATSolver)14 Assignment (org.logicng.datastructures.Assignment)13 LNGVector (org.logicng.collections.LNGVector)12 HashMap (java.util.HashMap)11 LogicNGTest (org.logicng.LogicNGTest)11 LNGIntVector (org.logicng.collections.LNGIntVector)8 CardinalityConstraint (org.logicng.formulas.CardinalityConstraint)8 PropositionalParser (org.logicng.io.parsers.PropositionalParser)8 BufferedReader (java.io.BufferedReader)7 FileReader (java.io.FileReader)7 BinaryOperator (org.logicng.formulas.BinaryOperator)7 Not (org.logicng.formulas.Not)7