本文整理汇总了Java中org.sat4j.specs.IProblem类的典型用法代码示例。如果您正苦于以下问题:Java IProblem类的具体用法?Java IProblem怎么用?Java IProblem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IProblem类属于org.sat4j.specs包,在下文中一共展示了IProblem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseInstance
import org.sat4j.specs.IProblem; //导入依赖的package包/类
@Override
public final IProblem parseInstance(final InputStream input)
throws ParseFormatException, ContradictionException, IOException {
this.in = new BufferedInputStream(input, LecteurDimacs.TAILLE_BUF);
s.reset();
passerCommentaire();
if (nbVars < 0)
throw new ParseFormatException(
"DIMACS error: wrong max number of variables");
s.newVar(nbVars);
s.setExpectedNumberOfClauses(nbClauses);
char car = passerEspaces();
if (nbClauses > 0) {
if (car == EOF)
throw new ParseFormatException(
"DIMACS error: the clauses are missing");
ajouterClauses(car);
}
input.close();
return s;
}
示例2: verifySatICPL_2
import org.sat4j.specs.IProblem; //导入依赖的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));
}
}
示例3: verifySatICPL_3
import org.sat4j.specs.IProblem; //导入依赖的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));
}
}
示例4: parseInstance
import org.sat4j.specs.IProblem; //导入依赖的package包/类
@Override
public final IProblem parseInstance(final InputStream input)
throws ParseFormatException, ContradictionException, IOException {
mapping = null;
this.in = new BufferedInputStream(input, LecteurDimacs.TAILLE_BUF);
this.s.reset();
passerCommentaire();
if (this.nbVars < 0) {
throw new ParseFormatException(
"DIMACS error: wrong max number of variables");
}
this.s.newVar(this.nbVars);
this.s.setExpectedNumberOfClauses(this.nbClauses);
char car = passerEspaces();
if (this.nbClauses > 0) {
if (car == EOF) {
throw new ParseFormatException(
"DIMACS error: the clauses are missing");
}
ajouterClauses(car);
}
input.close();
return this.s;
}
示例5: parseInstance
import org.sat4j.specs.IProblem; //导入依赖的package包/类
@Override
public IProblem parseInstance(String filename) throws ParseFormatException,
IOException, ContradictionException {
String fname;
String prefix = "";
if (filename.startsWith("http://")) {
filename = filename.substring(filename.lastIndexOf('/'),
filename.length() - 1);
}
if (filename.indexOf(':') != -1) {
String[] parts = filename.split(":");
filename = parts[1];
prefix = parts[0].toUpperCase(Locale.getDefault());
}
if (filename.endsWith(".gz") || filename.endsWith(".bz2")) {
fname = filename.substring(0, filename.lastIndexOf('.'));
} else {
fname = filename;
}
this.reader = handleFileName(fname, prefix);
return this.reader.parseInstance(filename);
}
示例6: solve
import org.sat4j.specs.IProblem; //导入依赖的package包/类
public void solve(IProblem problem, Reader reader, ILogAble logger,
PrintWriter out, long beginTime) {
this.exitCode = ExitCode.UNKNOWN;
this.out = out;
this.nbSolutionFound = 0;
this.beginTime = beginTime;
try {
if (problem.isSatisfiable()) {
if (this.exitCode == ExitCode.UNKNOWN) {
this.exitCode = ExitCode.SATISFIABLE;
}
} else {
if (this.exitCode == ExitCode.UNKNOWN) {
this.exitCode = ExitCode.UNSATISFIABLE;
}
}
} catch (TimeoutException e) {
logger.log("timeout");
}
}
示例7: parseInstance
import org.sat4j.specs.IProblem; //导入依赖的package包/类
protected IProblem parseInstance(LineNumberReader input)
throws ParseFormatException, ContradictionException {
this.solver.reset();
this.in = input;
try {
parse();
return this.solver;
} catch (ContradictionException ce) {
throw ce;
} catch (ParseFormatException pfe) {
throw new ParseFormatException(" line "
+ (input.getLineNumber() + 1)
+ ", "
+ pfe.getMessage().substring(
ParseFormatException.PARSING_ERROR.length()));
} catch (Exception e) {
throw new ParseFormatException(" line "
+ (input.getLineNumber() + 1) + ", " + e.toString());
}
}
示例8: readProblem
import org.sat4j.specs.IProblem; //导入依赖的package包/类
@Override
protected IProblem readProblem(String problemname)
throws ParseFormatException, IOException, ContradictionException {
IProblem problem = super.readProblem(problemname);
ObjectiveFunction obj = null;
if (super.feedWithDecorated) {
SolverDecorator<IPBSolver> decorator = (SolverDecorator<IPBSolver>) problem;
obj = (decorator.decorated()).getObjectiveFunction();
} else {
obj = ((IPBSolver) problem).getObjectiveFunction();
}
if (obj != null) {
this.out.println(COMMENT_PREFIX + "objective function length is "
+ obj.getVars().size() + " literals");
}
return problem;
}
示例9: 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);
}
示例10: getSolvableProblem
import org.sat4j.specs.IProblem; //导入依赖的package包/类
/**
* If already called, will return the previous solver!
*
* @param tunings
* enable tunings
* @return the problem
* @throws ContradictionException
*/
public IProblem getSolvableProblem(boolean tunings)
throws ContradictionException {
if (this.solver != null)
return this.solver;
this.solver = SolverFactory.newDefault();
this.solver.setVerbose(true);
GateTranslator translator = new GateTranslator(this.solver);
System.out.println("Representing problem in Java");
LogicStatement problem = this.getProblem();
System.out.println("Adding to GateTranslator");
problem.addToGateTranslator(translator);
if (tunings) {
System.out.println("Adding tunings to GateTranslator");
this.getTunings().addToGateTranslator(translator);
}
// allow to free psis
this.psiResults = null;
return this.solver;
}
示例11: 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;
}
示例12: parseInstance
import org.sat4j.specs.IProblem; //导入依赖的package包/类
@Override
public IProblem parseInstance(InputStream in) throws ParseFormatException,
ContradictionException, IOException {
if (in.read() != 'a' || in.read() != 'i' || in.read() != 'g'
|| in.read() != ' ') {
throw new ParseFormatException("AIG format only!");
}
maxvarid = parseInt(in, ' ');
nbinputs = parseInt(in, ' ');
int nblatches = parseInt(in, ' ');
if (nblatches > 0) {
throw new ParseFormatException(
"CNF conversion cannot handle latches!");
}
int nboutputs = parseInt(in, ' ');
if (nboutputs > 1) {
throw new ParseFormatException(
"CNF conversion allowed for single output circuit only!");
}
int nbands = parseInt(in, '\n');
solver.newVar(maxvarid + 1);
solver.setExpectedNumberOfClauses(3 * nbands + 2);
if (nboutputs > 0) {
assert nboutputs == 1;
int output0 = parseInt(in, '\n');
readAnd(nbands, output0, in, 2 * (nbinputs + 1));
}
return solver;
}
示例13: parseInstance
import org.sat4j.specs.IProblem; //导入依赖的package包/类
@Override
public IProblem parseInstance(java.io.InputStream in)
throws ParseFormatException, ContradictionException, IOException {
EfficientScanner scanner = new EfficientScanner(in);
String prefix = scanner.next();
if (!"aag".equals(prefix)) {
throw new ParseFormatException("AAG format only!");
}
maxvarid = scanner.nextInt();
nbinputs = scanner.nextInt();
int nblatches = scanner.nextInt();
int nboutputs = scanner.nextInt();
if (nboutputs > 1) {
throw new ParseFormatException(
"CNF conversion allowed for single output circuit only!");
}
int nbands = scanner.nextInt();
solver.newVar(maxvarid + 1);
solver.setExpectedNumberOfClauses(3 * nbands + 2);
readInput(nbinputs, scanner);
assert nblatches == 0;
if (nboutputs > 0) {
int output0 = readOutput(nboutputs, scanner);
readAnd(nbands, output0, scanner);
}
return solver;
}
示例14: testReaderFromDimacsReader
import org.sat4j.specs.IProblem; //导入依赖的package包/类
@Test
public void testReaderFromDimacsReader() throws ParseFormatException,
ContradictionException, IOException, TimeoutException {
String cnfString = "p cnf 3 4\n1 2 3 0\n-1 -2 0\n-1 -3 0\n-2 -3 0";
DimacsReader reader = new DimacsReader(SolverFactory.newDefault());
IProblem problem = reader.parseInstance(new ByteArrayInputStream(
cnfString.getBytes()));
assertNotNull(problem);
assertTrue(problem.isSatisfiable());
}
示例15: testReaderFromLecteurDimacs
import org.sat4j.specs.IProblem; //导入依赖的package包/类
@Test
public void testReaderFromLecteurDimacs() throws ParseFormatException,
ContradictionException, IOException, TimeoutException {
String cnfString = "p cnf 3 4\n1 2 3 0\n-1 -2 0\n-1 -3 0\n-2 -3 0";
LecteurDimacs reader = new LecteurDimacs(SolverFactory.newDefault());
IProblem problem = reader.parseInstance(new ByteArrayInputStream(
cnfString.getBytes()));
assertNotNull(problem);
assertTrue(problem.isSatisfiable());
}