use of org.logicng.solvers.sat.MiniSatStyleSolver in project LogicNG by logic-ng.
the class LinearSU method rebuildBMO.
/**
* Rebuilds a SAT solver with the current MaxSAT formula
* @param functions the functions
* @param rhs the right hand side
* @param currentWeight the current weight
* @return the rebuilt solver
*/
protected MiniSatStyleSolver rebuildBMO(final LNGVector<LNGIntVector> functions, final LNGIntVector rhs, final int currentWeight) {
assert functions.size() == rhs.size();
final MiniSatStyleSolver s = this.rebuildSolver(currentWeight);
this.objFunction.clear();
this.coeffs.clear();
for (int i = 0; i < nSoft(); i++) {
if (this.softClauses.get(i).weight() == currentWeight) {
this.objFunction.push(this.softClauses.get(i).relaxationVars().get(0));
this.coeffs.push(this.softClauses.get(i).weight());
}
}
for (int i = 0; i < functions.size(); i++) {
this.encoder.encodeCardinality(s, functions.get(i), rhs.get(i));
}
return s;
}
use of org.logicng.solvers.sat.MiniSatStyleSolver in project LogicNG by logic-ng.
the class MSU3 method rebuildSolver.
protected MiniSatStyleSolver rebuildSolver() {
final MiniSatStyleSolver s = newSATSolver();
for (int i = 0; i < nVars(); i++) {
newSATVariable(s);
}
for (int i = 0; i < nHard(); i++) {
s.addClause(this.hardClauses.get(i).clause(), null);
}
LNGIntVector clause;
for (int i = 0; i < nSoft(); i++) {
clause = new LNGIntVector(this.softClauses.get(i).clause());
for (int j = 0; j < this.softClauses.get(i).relaxationVars().size(); j++) {
clause.push(this.softClauses.get(i).relaxationVars().get(j));
}
s.addClause(clause, null);
}
return s;
}
use of org.logicng.solvers.sat.MiniSatStyleSolver in project LogicNG by logic-ng.
the class WBO method rebuildWeightSolver.
protected MiniSatStyleSolver rebuildWeightSolver(final WeightStrategy strategy) {
assert strategy == WeightStrategy.NORMAL || strategy == WeightStrategy.DIVERSIFY;
final MiniSatStyleSolver s = newSATSolver();
for (int i = 0; i < nVars(); i++) {
newSATVariable(s);
}
for (int i = 0; i < nHard(); i++) {
s.addClause(this.hardClauses.get(i).clause(), null);
}
if (this.symmetryStrategy) {
this.symmetryBreaking();
}
LNGIntVector clause = new LNGIntVector();
this.nbCurrentSoft = 0;
for (int i = 0; i < nSoft(); i++) {
if (this.softClauses.get(i).weight() >= this.currentWeight) {
this.nbCurrentSoft++;
clause.clear();
clause = new LNGIntVector(this.softClauses.get(i).clause());
for (int j = 0; j < this.softClauses.get(i).relaxationVars().size(); j++) {
clause.push(this.softClauses.get(i).relaxationVars().get(j));
}
clause.push(this.softClauses.get(i).assumptionVar());
s.addClause(clause, null);
}
}
return s;
}
use of org.logicng.solvers.sat.MiniSatStyleSolver in project LogicNG by logic-ng.
the class LNGHeapTest method test.
@Test
public void test() {
final MiniSatStyleSolver solver = new MiniCard();
solver.newVar(true, true);
solver.newVar(true, true);
solver.newVar(true, true);
final LNGHeap heap = new LNGHeap(solver);
assertThat(heap.empty()).isTrue();
heap.insert(1);
heap.insert(2);
heap.insert(0);
assertThat(heap.get(0)).isEqualTo(1);
assertThat(heap.toString()).isEqualTo("LNGHeap{[1, 2], [2, 0], [0, 1]}");
assertThat(heap.size()).isEqualTo(3);
heap.clear();
assertThat(heap.empty()).isTrue();
}
use of org.logicng.solvers.sat.MiniSatStyleSolver in project LogicNG by logic-ng.
the class WBO method rebuildSolver.
MiniSatStyleSolver rebuildSolver() {
assert this.weightStrategy == WeightStrategy.NONE;
final MiniSatStyleSolver s = newSATSolver();
for (int i = 0; i < nVars(); i++) {
newSATVariable(s);
}
for (int i = 0; i < nHard(); i++) {
s.addClause(this.hardClauses.get(i).clause(), null);
}
if (this.symmetryStrategy) {
this.symmetryBreaking();
}
LNGIntVector clause;
for (int i = 0; i < nSoft(); i++) {
clause = new LNGIntVector(this.softClauses.get(i).clause());
for (int j = 0; j < this.softClauses.get(i).relaxationVars().size(); j++) {
clause.push(this.softClauses.get(i).relaxationVars().get(j));
}
clause.push(this.softClauses.get(i).assumptionVar());
s.addClause(clause, null);
}
return s;
}
Aggregations