use of org.logicng.formulas.CardinalityConstraint in project LogicNG by logic-ng.
the class CCIncrementalFormulaTest method testLargeTotalizerLowerBoundALK.
@Test
public void testLargeTotalizerLowerBoundALK() {
final CCEncoder encoder = this.encoders[0];
final CCEncoder initivalEncoder = new CCEncoder(this.f);
final int numLits = 100;
int currentBound = 2;
final Variable[] vars = new Variable[numLits];
for (int i = 0; i < numLits; i++) {
vars[i] = this.f.variable("v" + i);
}
final Pair<List<Formula>, CCIncrementalData> cc = encoder.encodeIncremental((CardinalityConstraint) this.f.cc(CType.GE, currentBound, vars));
final CCIncrementalData incData = cc.second();
final SATSolver solver = this.solvers[3];
solver.reset();
// <= 42
solver.add(initivalEncoder.encode((CardinalityConstraint) this.f.cc(CType.LE, 87, vars)));
solver.add(cc.first());
// search the lower bound
while (solver.sat() == Tristate.TRUE) {
// <= currentBound + 1
solver.add(incData.newLowerBound(++currentBound));
}
assertThat(currentBound).isEqualTo(88);
}
use of org.logicng.formulas.CardinalityConstraint in project LogicNG by logic-ng.
the class CCIncrementalFormulaTest method testLargeTotalizerUpperBoundAMK.
@Test
public void testLargeTotalizerUpperBoundAMK() {
final CCEncoder encoder = this.encoders[0];
final CCEncoder initivalEncoder = new CCEncoder(this.f);
final int numLits = 100;
int currentBound = numLits - 1;
final Variable[] vars = new Variable[numLits];
for (int i = 0; i < numLits; i++) {
vars[i] = this.f.variable("v" + i);
}
final Pair<List<Formula>, CCIncrementalData> cc = encoder.encodeIncremental((CardinalityConstraint) this.f.cc(CType.LE, currentBound, vars));
final CCIncrementalData incData = cc.second();
final SATSolver solver = this.solvers[3];
solver.reset();
// >= 42
solver.add(initivalEncoder.encode((CardinalityConstraint) this.f.cc(CType.GE, 42, vars)));
solver.add(cc.first());
// search the lower bound
while (solver.sat() == Tristate.TRUE) {
// <= currentBound - 1
solver.add(incData.newUpperBound(--currentBound));
}
assertThat(currentBound).isEqualTo(41);
}
use of org.logicng.formulas.CardinalityConstraint in project LogicNG by logic-ng.
the class CCIncrementalFormulaTest method testVeryLargeModularTotalizerAMK.
@Test
@LongRunningTag
public void testVeryLargeModularTotalizerAMK() {
final CCEncoder encoder = this.encoders[2];
final CCEncoder initivalEncoder = new CCEncoder(this.f);
final int numLits = 300;
int currentBound = numLits - 1;
final Variable[] vars = new Variable[numLits];
for (int i = 0; i < numLits; i++) {
vars[i] = this.f.variable("v" + i);
}
final Pair<List<Formula>, CCIncrementalData> cc = encoder.encodeIncremental((CardinalityConstraint) this.f.cc(CType.LE, currentBound, vars));
final CCIncrementalData incData = cc.second();
final SATSolver solver = this.solvers[3];
solver.reset();
solver.add(initivalEncoder.encode((CardinalityConstraint) this.f.cc(CType.GE, 234, vars)));
solver.add(cc.first());
// search the lower bound
while (solver.sat() == Tristate.TRUE) {
solver.add(incData.newUpperBound(--currentBound));
}
assertThat(currentBound).isEqualTo(233);
}
use of org.logicng.formulas.CardinalityConstraint in project LogicNG by logic-ng.
the class CCIncrementalSolverTest method testSimpleIncrementalAMK.
@Test
public void testSimpleIncrementalAMK() {
for (final CCConfig config : this.configs) {
this.f.putConfiguration(this.configs[2]);
final int numLits = 10;
final Variable[] vars = new Variable[numLits];
for (int i = 0; i < numLits; i++) {
vars[i] = this.f.variable("v" + i);
}
final SATSolver solver = MiniSat.miniSat(this.f);
// >= 4
solver.add(this.f.cc(CType.GE, 4, vars));
// <= 7
solver.add(this.f.cc(CType.LE, 7, vars));
this.f.putConfiguration(config);
final CCIncrementalData incData = solver.addIncrementalCC((CardinalityConstraint) this.f.cc(CType.LE, 9, vars));
// <= 9
assertSolverSat(solver);
// <= 8
incData.newUpperBoundForSolver(8);
assertSolverSat(solver);
// <= 7
incData.newUpperBoundForSolver(7);
assertSolverSat(solver);
// <= 6
incData.newUpperBoundForSolver(6);
assertSolverSat(solver);
// <= 5
incData.newUpperBoundForSolver(5);
assertSolverSat(solver);
// <= 4
incData.newUpperBoundForSolver(4);
assertSolverSat(solver);
final SolverState state = solver.saveState();
// <= 3
incData.newUpperBoundForSolver(3);
assertSolverUnsat(solver);
solver.loadState(state);
assertSolverSat(solver);
// <= 2
incData.newUpperBoundForSolver(2);
assertSolverUnsat(solver);
}
}
use of org.logicng.formulas.CardinalityConstraint in project LogicNG by logic-ng.
the class CCIncrementalSolverTest method testLargeModularTotalizerAMK.
@Test
@LongRunningTag
public void testLargeModularTotalizerAMK() {
for (final SATSolver solver : this.solvers) {
if (solver != null) {
this.f.putConfiguration(this.configs[2]);
final int numLits = 100;
int currentBound = numLits - 1;
final Variable[] vars = new Variable[numLits];
for (int i = 0; i < numLits; i++) {
vars[i] = this.f.variable("v" + i);
}
solver.reset();
// >= 42
solver.add(this.f.cc(CType.GE, 42, vars));
final CCIncrementalData incData = solver.addIncrementalCC((CardinalityConstraint) this.f.cc(CType.LE, currentBound, vars));
// search the lower bound
while (solver.sat() == Tristate.TRUE) {
// <= currentBound - 1
incData.newUpperBoundForSolver(--currentBound);
}
assertThat(currentBound).isEqualTo(41);
}
}
}
Aggregations