本文整理汇总了Java中org.sat4j.specs.IVecInt.push方法的典型用法代码示例。如果您正苦于以下问题:Java IVecInt.push方法的具体用法?Java IVecInt.push怎么用?Java IVecInt.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sat4j.specs.IVecInt
的用法示例。
在下文中一共展示了IVecInt.push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSolverClauses
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
protected void addSolverClauses(ISolver solver) throws Exception {
super.addSolverClauses(solver);
// add extra constraints
for( PropositionalFormula formula : featureModel.getConstraints() ) {
for( CNFClause clause : formula.toCNFClauses() ) {
IVecInt vectInt = new VecInt(clause.countLiterals());
for( CNFLiteral literal : clause.getLiterals() ) {
int signal = literal.isPositive() ? 1 : -1;
int varID = getVariableIndex(literal.getVariable().getID());
vectInt.push(signal * varID);
}
solver.addClause(vectInt);
// System.out.println("EC: " + vectInt);
}
}
}
示例2: testTrivialSatNewVar
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
@Deprecated
public void testTrivialSatNewVar() throws TimeoutException {
try {
solver.newVar(0);
solver.newVar();
IVecInt vec = new VecInt();
vec.push(1);
solver.addClause(vec);
vec.clear();
solver.newVar();
vec.push(-2);
solver.addClause(vec);
assertTrue(solver.isSatisfiable());
} catch (ContradictionException e) {
fail();
}
}
示例3: test5Sat
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
public void test5Sat() throws TimeoutException {
try {
solver.reset();
// 2 variables
solver.newVar(2);
// premi\x{FFFD}re contrainte de cardinalit\x{FFFD}
// a + not b <=0
IVecInt vecLit = new VecInt();
vecLit.push(1);
vecLit.push(-2);
solver.addAtMost(vecLit, 0);
boolean isSat = solver.isSatisfiable();
assertTrue(isSat);
} catch (ContradictionException e) {
assertTrue(false);
}
}
示例4: test2Sat
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
public void test2Sat() throws TimeoutException {
try {
solver.reset();
// 2 variables
solver.newVar(2);
// premi?re contrainte de cardinalit?
// a + not b <=3
IVecInt vecLit = new VecInt();
vecLit.push(1);
vecLit.push(-2);
solver.addAtMost(vecLit, 3);
boolean isSat = solver.isSatisfiable();
assertTrue(isSat);
} catch (ContradictionException e) {
assertTrue(false);
}
}
示例5: 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);
}
示例6: 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());
}
示例7: 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) {
}
}
示例8: addClause
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
@Override
public IConstr addClause(IVecInt literals) throws ContradictionException {
if (literals.equals(lastClause)) {
// System.err.println("c Duplicated entry: " + literals);
return null;
}
lastClause.clear();
literals.copyTo(lastClause);
int newvar = createNewVar(literals);
literals.push(newvar);
lastConstr = super.addClause(literals);
if (lastConstr == null) {
discardLastestVar();
} else {
constrs.put(newvar, lastConstr);
}
return lastConstr;
}
示例9: calcReason
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
public void calcReason(int p, IVecInt outReason) {
int c = (p == ILits.UNDEFINED) ? -1 : 0;
for (int q : lits) {
if (voc.isFalsified(q)) {
outReason.push(q ^ 1);
if (++c == maxUnsatisfied)
return;
}
}
}
示例10: count
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
private long count(int size) throws ContradictionException,
TimeoutException {
SolutionCounter counter = new SolutionCounter(
SolverFactory.newDefault());
IVecInt clause = new VecInt();
for (int i = 1; i <= size; i++) {
clause.push(i);
}
counter.addClause(clause);
counter.setTimeout(10);
return counter.countSolutions();
}
示例11: explain
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
public IVecInt explain(ISolver solver, Map<Integer, ?> constrs,
IVecInt assumps) throws TimeoutException {
computationCanceled = false;
IVecInt encodingAssumptions = new VecInt(constrs.size()
+ assumps.size());
assumps.copyTo(encodingAssumptions);
IVecInt firstExplanation = solver.unsatExplanation();
if (solver.isVerbose()) {
System.out.print(solver.getLogPrefix() + "initial unsat core ");
firstExplanation.sort();
for (IteratorInt it = firstExplanation.iterator(); it.hasNext();) {
System.out.print(constrs.get(-it.next()));
System.out.print(" ");
}
System.out.println();
}
Set<Integer> constraintsVariables = constrs.keySet();
int p;
for (int i = 0; i < firstExplanation.size(); i++) {
if (constraintsVariables.contains(p = -firstExplanation.get(i))) {
encodingAssumptions.push(p);
}
}
IVecInt results = new VecInt(encodingAssumptions.size());
computeExplanation(solver, encodingAssumptions, assumps.size(),
encodingAssumptions.size() - 1, results);
return results;
}
示例12: isSatisfiable
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
@Override
public boolean isSatisfiable() throws TimeoutException {
assump = VecInt.EMPTY;
IVecInt extraVariables = new VecInt();
for (Integer p : constrs.keySet()) {
extraVariables.push(-p);
}
return super.isSatisfiable(extraVariables);
}
示例13: tearDDown
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
@Before
public void tearDDown() throws ContradictionException {
solver = new ModelIterator(SolverFactory.newDefault());
IVecInt clause = new VecInt();
for (int i = 1; i <= 1000; i++)
clause.push(-i);
solver.addClause(clause);
}
示例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: primeImplicant
import org.sat4j.specs.IVecInt; //导入方法依赖的package包/类
@Override
public int[] primeImplicant() {
int[] last = super.primeImplicant();
nbModelFound += Math.pow(2, nVars() - last.length);
IVecInt clause = new VecInt(last.length);
for (int q : last) {
clause.push(-q);
}
try {
addBlockingClause(clause);
} catch (ContradictionException e) {
trivialfalsity = true;
}
return last;
}