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