Search in sources :

Example 1 with LNGVector

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

the class CCCardinalityNetworks method buildALK.

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

Example 2 with LNGVector

use of org.logicng.collections.LNGVector 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 3 with LNGVector

use of org.logicng.collections.LNGVector 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 4 with LNGVector

use of org.logicng.collections.LNGVector 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 5 with LNGVector

use of org.logicng.collections.LNGVector 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)

Aggregations

LNGVector (org.logicng.collections.LNGVector)17 Literal (org.logicng.formulas.Literal)12 Variable (org.logicng.formulas.Variable)8 LNGIntVector (org.logicng.collections.LNGIntVector)6 LNGBooleanVector (org.logicng.collections.LNGBooleanVector)2 Tristate (org.logicng.datastructures.Tristate)2 Formula (org.logicng.formulas.Formula)2 SATHandler (org.logicng.handlers.SATHandler)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 EncodingResult (org.logicng.datastructures.EncodingResult)1 UNSATCore (org.logicng.explanations.UNSATCore)1 DRUPTrim (org.logicng.explanations.drup.DRUPTrim)1 CardinalityConstraint (org.logicng.formulas.CardinalityConstraint)1 PBConstraint (org.logicng.formulas.PBConstraint)1 Proposition (org.logicng.propositions.Proposition)1 StandardProposition (org.logicng.propositions.StandardProposition)1 Encoder (org.logicng.solvers.maxsat.encodings.Encoder)1