本文整理汇总了Java中org.sat4j.specs.IVecInt.clear方法的典型用法代码示例。如果您正苦于以下问题:Java IVecInt.clear方法的具体用法?Java IVecInt.clear怎么用?Java IVecInt.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sat4j.specs.IVecInt
的用法示例。
在下文中一共展示了IVecInt.clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: and
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
/**
* Translate y <=> x1 /\ x2
*
* @param y
* @param x1
* @param x2
* @throws ContradictionException
* @since 2.1
*/
public IConstr[] and(int y, int x1, int x2) throws ContradictionException {
IVecInt clause = new VecInt(4);
IConstr[] constrs = new IConstr[3];
clause.push(-y);
clause.push(x1);
constrs[0] = addClause(clause);
clause.clear();
clause.push(-y);
clause.push(x2);
constrs[1] = addClause(clause);
clause.clear();
clause.push(y);
clause.push(-x1);
clause.push(-x2);
constrs[2] = addClause(clause);
return constrs;
}
示例2: testTrivialUnsat
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
public void testTrivialUnsat() {
solver.newVar(1);
IVecInt vec = new VecInt();
vec.push(1);
try {
solver.addClause(vec);
} catch (ContradictionException e) {
fail();
}
vec.clear();
vec.push(-1);
try {
solver.addClause(vec);
fail();
} catch (ContradictionException e1) {
}
}
示例3: testEclipseTestCase
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
@Test
public void testEclipseTestCase() throws ContradictionException,
TimeoutException {
solver.newVar(3);
IVecInt clause = new VecInt();
clause.push(-1);
solver.addClause(clause);
clause.clear();
clause.push(-2).push(3);
solver.addClause(clause);
clause.clear();
clause.push(-2).push(1);
solver.addClause(clause);
clause.clear();
clause.push(2);
solver.addClause(clause);
clause.clear();
assertFalse(solver.isSatisfiable());
Collection<IConstr> explanation = solver.explain();
assertEquals(3, explanation.size());
}
示例4: testGlobalInconsistencyIndex
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
@Test
public void testGlobalInconsistencyIndex() throws ContradictionException,
TimeoutException {
solver.newVar(2);
IVecInt clause = new VecInt();
clause.push(1).push(2);
solver.addClause(clause);
clause.clear();
clause.push(1).push(-2);
solver.addClause(clause);
clause.clear();
clause.push(-1).push(2);
solver.addClause(clause);
clause.clear();
clause.push(-1).push(-2);
solver.addClause(clause);
clause.clear();
assertFalse(solver.isSatisfiable());
int[] explanation = solver.minimalExplanation();
assertEquals(4, explanation.length);
assertEquals(1, explanation[0]);
assertEquals(2, explanation[1]);
assertEquals(3, explanation[2]);
assertEquals(4, explanation[3]);
}
示例5: xor
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
/**
* @since 2.2
*/
public void xor(int x, int a, int b) throws ContradictionException {
IVecInt clause = new VecInt(3);
clause.push(-a).push(b).push(x);
processClause(clause);
clause.clear();
clause.push(a).push(-b).push(x);
processClause(clause);
clause.clear();
clause.push(-a).push(-b).push(-x);
processClause(clause);
clause.clear();
clause.push(a).push(b).push(-x);
processClause(clause);
clause.clear();
}
示例6: testGlobalInconsistency
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
@Test
public void testGlobalInconsistency() throws ContradictionException,
TimeoutException {
solver.newVar(2);
IVecInt clause = new VecInt();
clause.push(1).push(2);
solver.addClause(clause);
clause.clear();
clause.push(1).push(-2);
solver.addClause(clause);
clause.clear();
clause.push(-1).push(2);
solver.addClause(clause);
clause.clear();
clause.push(-1).push(-2);
solver.addClause(clause);
clause.clear();
assertFalse(solver.isSatisfiable());
Collection<IConstr> explanation = solver.explain();
assertEquals(4, explanation.size());
}
示例7: testFolletExample
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
@Test
public void testFolletExample() throws ContradictionException,
TimeoutException {
IVecInt clause = new VecInt();
clause.push(1);
solver.addClause(clause);
clause.clear();
clause.push(2).push(3);
solver.addClause(clause);
clause.clear();
clause.push(3);
solver.addClause(clause);
clause.clear();
assertTrue(solver.isSatisfiable());
int[] model = solver.model();
System.out.println(new VecInt(model));
assertEquals(3, model.length);
int[] implicant = solver.primeImplicant();
System.out.println(new VecInt(implicant));
assertEquals(2, implicant.length);
}
示例8: testHasNoSingleSolution
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
public void testHasNoSingleSolution() throws ContradictionException,
TimeoutException {
IVecInt clause = new VecInt();
clause.push(1).push(2);
detector.addClause(clause);
clause.clear();
clause.push(-1).push(-2);
detector.addClause(clause);
assertTrue(detector.isSatisfiable());
clause.clear();
clause.push(-1).push(2);
detector.addClause(clause);
assertTrue(detector.isSatisfiable());
assertTrue(detector.hasASingleSolution());
clause.clear();
clause.push(1).push(-2);
detector.addClause(clause);
assertFalse(detector.isSatisfiable());
try {
assertFalse(detector.hasASingleSolution());
fail();
} catch (UnsupportedOperationException e) {
// OK
}
}
示例9: testHasASingleSolutionIVecInt
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
public void testHasASingleSolutionIVecInt() throws ContradictionException,
TimeoutException {
IVecInt clause = new VecInt();
clause.push(1).push(2);
detector.addClause(clause);
IVecInt assumptions = new VecInt();
assumptions.push(1);
assertTrue(detector.isSatisfiable(assumptions));
assertFalse(detector.hasASingleSolution(assumptions));
clause.clear();
clause.push(-1).push(2);
detector.addClause(clause);
assertTrue(detector.isSatisfiable(assumptions));
assertTrue(detector.hasASingleSolution(assumptions));
clause.clear();
clause.push(-1).push(-2);
detector.addClause(clause);
assertFalse(detector.isSatisfiable(assumptions));
try {
assertFalse(detector.hasASingleSolution(assumptions));
fail();
} catch (UnsupportedOperationException e) {
// OK
}
}
示例10: testDeleteGroup
import org.sat4j.specs.IVecInt; //导入方法依赖的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());
}
示例11: checkBugReportedByThomas
import org.sat4j.specs.IVecInt; //导入方法依赖的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());
}
示例12: testEclipseTestCase2
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
@Test
public void testEclipseTestCase2() throws ContradictionException,
TimeoutException {
solver.newVar(4);
IVecInt clause = new VecInt();
clause.push(-1).push(2);
solver.addClause(clause);
clause.clear();
clause.push(-1).push(3);
solver.addClause(clause);
clause.clear();
clause.push(-2).push(-3);
solver.addClause(clause);
clause.clear();
clause.push(-4).push(1);
solver.addClause(clause);
clause.clear();
IVecInt assump = new VecInt();
assump.push(4);
assertFalse(solver.isSatisfiable(assump));
Collection<IConstr> explanation = solver.explain();
assertEquals(4, explanation.size());
}
示例13: ite
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
/**
* translate y <=> if x1 then x2 else x3 into clauses.
*
* @param y
* @param x1
* the selector variable
* @param x2
* @param x3
* @throws ContradictionException
* @since 2.1
*/
public IConstr[] ite(int y, int x1, int x2, int x3)
throws ContradictionException {
IConstr[] constrs = new IConstr[6];
IVecInt clause = new VecInt(5);
// y <=> (x1 -> x2) and (not x1 -> x3)
// y -> (x1 -> x2) and (not x1 -> x3)
clause.push(-y).push(-x1).push(x2);
constrs[0] = processClause(clause);
clause.clear();
clause.push(-y).push(x1).push(x3);
constrs[1] = processClause(clause);
// y <- (x1 -> x2) and (not x1 -> x3)
// not(x1 -> x2) or not(not x1 -> x3) or y
// x1 and not x2 or not x1 and not x3 or y
// (x1 and not x2) or ((not x1 or y) and (not x3 or y))
// (x1 or not x1 or y) and (not x2 or not x1 or y) and (x1 or not x3 or
// y) and (not x2 or not x3 or y)
// not x1 or not x2 or y and x1 or not x3 or y and not x2 or not x3 or y
clause.clear();
clause.push(-x1).push(-x2).push(y);
constrs[2] = processClause(clause);
clause.clear();
clause.push(x1).push(-x3).push(y);
constrs[3] = processClause(clause);
clause.clear();
clause.push(-x2).push(-x3).push(y);
constrs[4] = processClause(clause);
// taken from Niklas Een et al SAT 2007 paper
// Adding the following redundant clause will improve unit propagation
// y -> x2 or x3
clause.clear();
clause.push(-y).push(x2).push(x3);
constrs[5] = processClause(clause);
return constrs;
}
示例14: testTrivialSat
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
public void testTrivialSat() throws TimeoutException {
solver.reset();
solver.newVar(2);
try {
IVecInt vec = new VecInt();
vec.push(1);
solver.addClause(vec);
vec.clear();
vec.push(-2);
solver.addClause(vec);
assertTrue(solver.isSatisfiable());
} catch (ContradictionException e) {
fail();
}
}
示例15: fullAdderSum
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
/**
* @since 2.2
*/
public void fullAdderSum(int x, int a, int b, int c)
throws ContradictionException {
IVecInt clause = new VecInt(4);
// -a /\ -b /\ -c -> -x
clause.push(a).push(b).push(c).push(-x);
processClause(clause);
clause.clear();
// -a /\ b /\ c -> -x
clause.push(a).push(-b).push(-c).push(-x);
processClause(clause);
clause.clear();
clause.push(-a).push(b).push(-c).push(-x);
processClause(clause);
clause.clear();
clause.push(-a).push(-b).push(c).push(-x);
processClause(clause);
clause.clear();
clause.push(-a).push(-b).push(-c).push(x);
processClause(clause);
clause.clear();
clause.push(-a).push(b).push(c).push(x);
processClause(clause);
clause.clear();
clause.push(a).push(-b).push(c).push(x);
processClause(clause);
clause.clear();
clause.push(a).push(b).push(-c).push(x);
processClause(clause);
clause.clear();
}