本文整理汇总了Java中org.sat4j.minisat.SolverFactory类的典型用法代码示例。如果您正苦于以下问题:Java SolverFactory类的具体用法?Java SolverFactory怎么用?Java SolverFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SolverFactory类属于org.sat4j.minisat包,在下文中一共展示了SolverFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDeleteGroup
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void testDeleteGroup() throws ContradictionException {
ISolver solver = SolverFactory.newDefault();
ConstrGroup g1 = new ConstrGroup();
IVecInt clause = new VecInt(new int[] { 1, 2, -3 });
solver.addClause(clause);
// starting group
clause.clear();
clause.push(2).push(-3).push(-5);
g1.add(solver.addClause(clause));
clause.clear();
clause.push(-3).push(-2).push(-4);
g1.add(solver.addClause(clause));
assertEquals(3, solver.nConstraints());
g1.removeFrom(solver);
assertEquals(1, solver.nConstraints());
}
示例2: checkBugReportedByThomas
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void checkBugReportedByThomas() throws ContradictionException {
ISolver solver = SolverFactory.newDefault();
ConstrGroup g1 = new ConstrGroup();
IVecInt clause = new VecInt(new int[] { 1 });
solver.addClause(clause);
// starting group
clause.clear();
clause.push(2).push(-3).push(-5);
g1.add(solver.addClause(clause));
clause.clear();
clause.push(-3).push(-2).push(-4);
g1.add(solver.addClause(clause));
assertEquals(3, solver.nConstraints());
g1.removeFrom(solver);
assertEquals(1, solver.nConstraints());
}
示例3: checkItWorksAfterRunningTheSolver
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void checkItWorksAfterRunningTheSolver() throws ContradictionException, TimeoutException {
ISolver solver = SolverFactory.newDefault();
ConstrGroup g1 = new ConstrGroup();
IVecInt clause = new VecInt(new int[] { 1 });
solver.addClause(clause);
// starting group
clause.clear();
clause.push(-1).push(-2).push(-3);
g1.add(solver.addClause(clause));
clause.clear();
clause.push(-1).push(2).push(-3);
g1.add(solver.addClause(clause));
assertEquals(3, solver.nConstraints());
assertTrue(solver.isSatisfiable());
assertTrue(solver.model(1));
assertFalse(solver.model(3));
g1.removeFrom(solver);
assertEquals(1, solver.nConstraints());
}
示例4: checkTheExpectedWayToDealWithUnitClausesToRemove
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void checkTheExpectedWayToDealWithUnitClausesToRemove() throws ContradictionException, TimeoutException {
ISolver solver = SolverFactory.newDefault();
ConstrGroup g1 = new ConstrGroup();
IVecInt clause = new VecInt(new int[] { 1 });
solver.addClause(clause);
// starting group
clause.clear();
clause.push(2).push(-3);
g1.add(solver.addClause(clause));
clause.clear();
clause.push(-2).push(4);
g1.add(solver.addClause(clause));
IVecInt unitClauses = new VecInt(new int[] {3,-4});
assertFalse(solver.isSatisfiable(unitClauses));
g1.removeFrom(solver);
assertTrue(solver.isSatisfiable(unitClauses));
}
示例5: setup
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Before
public void setup() throws ContradictionException {
solver = SolverFactory.newDefault();
solver.setTimeout(15);
solver.addClause(new VecInt(new int[] { 1 }));
solver.addClause(new VecInt(new int[] { -1, 2 }));
solver.addClause(new VecInt(new int[] { -1, 3 }));
solver.addClause(new VecInt(new int[] { -2, 1 }));
solver.addClause(new VecInt(new int[] { -4, 1 }));
solver.addClause(new VecInt(new int[] { -3, 1 }));
solver.addClause(new VecInt(new int[] { -3, 5 }));
solver.addClause(new VecInt(new int[] { -5, 3 }));
solver.addClause(new VecInt(new int[] { 6 }));
solver.addClause(new VecInt(new int[] { -7 }));
solver.addClause(new VecInt(new int[] { 2, 5, 4, 6 }));
}
示例6: verifySatICPL_2
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void verifySatICPL_2() throws IOException, ParseFormatException, ContradictionException, org.sat4j.specs.TimeoutException, CSVException{
ISolver solver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(solver);
IProblem problem = reader.parseInstance("TestData/Realistic/freebsd-icse11.dimacs");
assertTrue(problem.isSatisfiable());
CNF cnf = new CNF("TestData/Realistic/freebsd-icse11.dimacs", CNF.type.dimacs);
CoveringArray ca = new CoveringArrayFile("reports/bestcoverages/freebsd-icse11-size78-1thread.dimacs.ca2.csv");
for(int n = 0; n < ca.getRowCount(); n++){
// Convert
Integer[] solinteger = ca.getRow(n);
int[] sol = new int[solinteger.length];
for(int i = 0; i < sol.length; i++){
sol[i] = cnf.getNr(ca.getId(i+1));
if(solinteger[i]==1) sol[i] = -sol[i];
}
IVecInt assumps = new VecInt(sol);
// Test
assertTrue(problem.isSatisfiable(assumps));
}
}
示例7: verifySatICPL_3
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void verifySatICPL_3() throws IOException, ParseFormatException, ContradictionException, org.sat4j.specs.TimeoutException, CSVException{
ISolver solver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(solver);
IProblem problem = reader.parseInstance("TestData/Realistic/2.6.28.6-icse11.dimacs");
assertTrue(problem.isSatisfiable());
CNF cnf = new CNF("TestData/Realistic/2.6.28.6-icse11.dimacs", CNF.type.dimacs);
CoveringArray ca = new CoveringArrayFile("reports/bestcoverages/2.6.28.6-icse11-size469-1thread.dimacs.ca2.csv");
for(int n = 0; n < ca.getRowCount(); n++){
// Convert
Integer[] solinteger = ca.getRow(n);
int[] sol = new int[solinteger.length];
for(int i = 0; i < sol.length; i++){
sol[i] = cnf.getNr(ca.getId(i+1));
if(solinteger[i]==1) sol[i] = -sol[i];
}
IVecInt assumps = new VecInt(sol);
//System.out.println(n + ", " + assumps.size());
// Test
assertTrue(problem.isSatisfiable(assumps));
}
}
示例8: solve
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Override
public SatOutput solve(SatInput input) throws InterruptedException {
if (input == null) {
throw new IllegalArgumentException("Null argument.");
}
solver = SolverFactory.newDefault();
solver.newVar(input.getLastId());
for (Set<Integer> clause : input.getClauses()) {
try {
solver.addClause(new VecInt(SatInput.toArray(clause)));
} catch (ContradictionException e) {
return new SatOutput(false, Collections.<Integer> emptySet());
}
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
return getSatOutput();
}
示例9: testModelIterator
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void testModelIterator() throws ContradictionException,
TimeoutException {
ModelIterator iterator = new ModelIterator(SolverFactory.newDefault());
iterator.addClause(new VecInt(new int[] { 1, 2 }));
iterator.addClause(new VecInt(new int[] { -1, -2 }));
iterator.addClause(new VecInt(new int[] { -3, -4 }));
iterator.addClause(new VecInt(new int[] { 5, 6 }));
iterator.addClause(new VecInt(new int[] { -5, -6 }));
iterator.addClause(new VecInt(new int[] { -1, 3 }));
int counter = 0;
int[] sub = new int[0];
while (iterator.isSatisfiable()) {
sub = iterator.model();
counter++;
}
assertEquals(8, counter);
assertEquals(6, sub.length);
}
示例10: testSubModelIterator
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void testSubModelIterator() throws ContradictionException,
TimeoutException {
IVecInt subset = new VecInt(new int[] { 1, 2, 3, 4 });
ModelIterator iterator = new SubModelIterator(
SolverFactory.newDefault(), subset);
iterator.addClause(new VecInt(new int[] { 1, 2 }));
iterator.addClause(new VecInt(new int[] { -1, -2 }));
iterator.addClause(new VecInt(new int[] { -3, -4 }));
iterator.addClause(new VecInt(new int[] { 5, 6 }));
iterator.addClause(new VecInt(new int[] { -5, -6 }));
iterator.addClause(new VecInt(new int[] { -1, 3 }));
int counter = 0;
int[] sub = new int[0];
while (iterator.isSatisfiable()) {
sub = iterator.model();
counter++;
}
assertEquals(4, counter);
assertEquals(4, sub.length);
}
示例11: test
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void test() throws ContradictionException, TimeoutException {
Solver<DataStructureFactory> solver = SolverFactory.newGlucose();
int[] backdoor = { 1, 2, 3 };
IOrder order = new SubsetVarOrder(backdoor);
solver.setOrder(order);
IVecInt clause = new VecInt();
clause.push(1).push(4);
solver.addClause(clause);
clause = new VecInt();
clause.push(2).push(5);
solver.addClause(clause);
clause = new VecInt();
clause.push(3).push(6);
solver.addClause(clause);
assertTrue(solver.isSatisfiable());
}
示例12: test2
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void test2() throws ContradictionException, TimeoutException {
Solver<DataStructureFactory> solver = SolverFactory.newGlucose();
int[] backdoor = { 1, 2, 3 };
IOrder order = new SubsetVarOrder(backdoor);
solver.setOrder(order);
IVecInt clause = new VecInt();
clause.push(-1).push(4);
solver.addClause(clause);
clause = new VecInt();
clause.push(-2).push(5);
solver.addClause(clause);
clause = new VecInt();
clause.push(-3).push(6);
solver.addClause(clause);
assertTrue(solver.isSatisfiable());
}
示例13: test3
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test(expected = TimeoutException.class)
public void test3() throws ContradictionException, TimeoutException {
Solver<DataStructureFactory> solver = SolverFactory.newGlucose();
solver.setSearchListener(new TextOutputTracing<Object>(null));
int[] backdoor = { 1, 2, 3 };
IOrder order = new SubsetVarOrder(backdoor);
solver.setOrder(order);
IVecInt clause = new VecInt();
clause.push(-1).push(4).push(7);
solver.addClause(clause);
clause = new VecInt();
clause.push(-2).push(5).push(7);
solver.addClause(clause);
clause = new VecInt();
clause.push(-3).push(6).push(5);
solver.addClause(clause);
clause = new VecInt();
clause.push(1).push(2).push(3).push(7).push(8);
solver.addClause(clause);
solver.isSatisfiable();
}
示例14: testJeanGuy1
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void testJeanGuy1() throws ContradictionException, TimeoutException {
Solver<DataStructureFactory> solver = SolverFactory.newGlucose();
int[] backdoor = { 1, 2, 3, 4 };
IOrder order = new SubsetVarOrder(backdoor);
solver.setOrder(order);
IVecInt clause = new VecInt();
clause.push(-1).push(5);
solver.addClause(clause);
clause = new VecInt();
clause.push(-2).push(3).push(5);
solver.addClause(clause);
clause = new VecInt();
clause.push(-4).push(5);
solver.addClause(clause);
assertTrue(solver.isSatisfiable());
}
示例15: testJeanGuy2
import org.sat4j.minisat.SolverFactory; //导入依赖的package包/类
@Test
public void testJeanGuy2() throws ContradictionException, TimeoutException {
Solver<DataStructureFactory> solver = SolverFactory.newGlucose();
int[] backdoor = { 5 };
IOrder order = new SubsetVarOrder(backdoor);
solver.setOrder(order);
IVecInt clause = new VecInt();
clause.push(-1).push(5);
solver.addClause(clause);
clause = new VecInt();
clause.push(-2).push(3).push(5);
solver.addClause(clause);
clause = new VecInt();
clause.push(-4).push(5);
solver.addClause(clause);
assertTrue(solver.isSatisfiable());
}