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