本文整理汇总了Java中org.sat4j.specs.IProblem.model方法的典型用法代码示例。如果您正苦于以下问题:Java IProblem.model方法的具体用法?Java IProblem.model怎么用?Java IProblem.model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sat4j.specs.IProblem
的用法示例。
在下文中一共展示了IProblem.model方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIteratingWithObjectiveFunctionWithDecorator
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
@Test
public void testIteratingWithObjectiveFunctionWithDecorator() {
IPBSolver solver = buildSolver2();
IProblem problem = new ModelIterator(solver);
int nbModel = 0;
try {
while (problem.isSatisfiable()) {
problem.model(); // needed to discard that model
nbModel++;
}
} catch (TimeoutException e) {
fail();
}
assertEquals(4, nbModel);
}
示例2: runSatSolver
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
private int[] runSatSolver(Path path){
ISolver solver = SolverFactory.newDefault();
solver.setTimeout(TIMEOUT_MINUTES);
Reader reader = new DimacsReader(solver);
IProblem problem = null;
try {
problem = reader.parseInstance(path.toString());
if (problem.isSatisfiable()) {
return problem.model();
} else {
logger.error("Problem described in " + path.getFileName() + " is unsatisfiable");
}
} catch (ContradictionException | TimeoutException | ParseFormatException | IOException e) {
logger.error("Error during SAT-solver processing", e);
}
return null;
}
示例3: getSolutions
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
public String getSolutions(int number) throws TimeoutException {
if (contradiction)
return "contradiction\n";
StringBuffer out = new StringBuffer();
IProblem problem = new ModelIterator(solver);
int[] lastModel = null;
for (int i = 0; i < number; i++) {
if (!problem.isSatisfiable(i > 0)) {
out.append("only " + i + " solutions\n");
break;
}
int[] model = problem.model();
if (lastModel != null) {
boolean same = true;
for (int j = 0; j < model.length; j++)
if (model[j] != lastModel[j])
same = false;
if (same) {
out.append("only " + i + " solutions\n");
break;
}
}
lastModel = model;
StringBuilder pos = new StringBuilder();
StringBuilder neg = new StringBuilder();
for (int var : model)
if (var > 0)
pos.append(intToVar.get(Math.abs(var)) + " ");
else
neg.append(intToVar.get(Math.abs(var)) + " ");
out.append("true: " + pos + " false: " + neg + "\n");
}
return out.toString();
}
示例4: getSolution
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
public String getSolution() throws TimeoutException {
if (contradiction)
return null;
StringBuilder out = new StringBuilder();
IProblem problem = new ModelIterator(solver);
if (!problem.isSatisfiable())
return null;
int[] model = problem.model();
for (int var : model)
if (var > 0)
out.append(intToVar.get(Math.abs(var)) + "\n");
return out.toString();
}
示例5: solve
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
public Set<Literal> solve(){
try {
ISolver solver = SolverFactory.newDefault();
solver.newVar(this.literalsToIndices.size());
solver.setExpectedNumberOfClauses(softProgram.size());
for (int[] clause : hardDimacsClauses){
//System.out.println("hard dimacs clause: "+VectorUtils.intArrayToString(clause));
try {
solver.addClause(new VecInt(clause));
} catch (ContradictionException ce){
//no solution
return null;
}
}
IProblem problem = solver;
if (problem.isSatisfiable()) {
int[] model = problem.model();
Set<Literal> solution = new HashSet<Literal>();
for (int i : model){
if (i > 0){
solution.add(literalsToIndices.indexToValue(i));
}
}
return solution;
} else {
return null;
}
} catch (Exception e){
e.printStackTrace();
}
return null;
}