本文整理汇总了Java中org.sat4j.specs.IProblem.nVars方法的典型用法代码示例。如果您正苦于以下问题:Java IProblem.nVars方法的具体用法?Java IProblem.nVars怎么用?Java IProblem.nVars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sat4j.specs.IProblem
的用法示例。
在下文中一共展示了IProblem.nVars方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIterativeAssumptionCallsWithSet
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
@Test
public void testIterativeAssumptionCallsWithSet()
throws FileNotFoundException, ParseFormatException, IOException,
ContradictionException, TimeoutException {
ISolver satSolver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(satSolver);
IProblem p = reader.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
List<Integer> vars = new ArrayList<Integer>();
for (int i = 1; i <= p.nVars(); i++) {
vars.add(-i);
vars.add(i);
}
Set<Integer> sol = new HashSet<Integer>();
for (int i = 0; i < vars.size(); i++) {
ISolver satSolverOracle = SolverFactory.newDefault();
Reader readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
int varnr = vars.get(i);
int assumpsArray[] = new int[sol.size() + 1];
int c = 0;
for (int a : sol) {
assumpsArray[c] = a;
c++;
}
assumpsArray[assumpsArray.length - 1] = varnr;
IVecInt assumps = new VecInt(assumpsArray);
// Check
if (satSolver.isSatisfiable(assumps)) {
sol.add(varnr);
}
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
}
}
示例2: testIterativeAssumptionCallsWithSet
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
@Test
public void testIterativeAssumptionCallsWithSet()
throws FileNotFoundException, ParseFormatException, IOException,
ContradictionException, TimeoutException {
ISolver satSolver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(satSolver);
IProblem p = reader.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
List<Integer> vars = new ArrayList<Integer>();
for (int i = 1; i <= p.nVars(); i++) {
vars.add(-i);
vars.add(i);
}
Set<Integer> sol = new HashSet<Integer>();
for (int i = 0; i < vars.size(); i++) {
ISolver satSolverOracle = SolverFactory.newDefault();
Reader readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
int varnr = vars.get(i);
int assumpsArray[] = new int[sol.size() + 1];
int c = 0;
for (int a : sol) {
assumpsArray[c] = a;
c++;
}
assumpsArray[assumpsArray.length - 1] = varnr;
IVecInt assumps = new VecInt(assumpsArray);
System.out.println(assumps);
// Check
if (satSolver.isSatisfiable(assumps)) {
sol.add(varnr);
} else {
System.out.println("unsat: " + varnr);
}
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
}
}
示例3: testIterativeAssumptionCallsWithList
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
@Test
public void testIterativeAssumptionCallsWithList()
throws FileNotFoundException, ParseFormatException, IOException,
ContradictionException, TimeoutException {
ISolver satSolver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(satSolver);
IProblem p = reader.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
List<Integer> vars = new ArrayList<Integer>();
for (int i = 1; i <= p.nVars(); i++) {
vars.add(-i);
vars.add(i);
}
List<Integer> sol = new ArrayList<Integer>();
for (int i = 0; i < vars.size(); i++) {
ISolver satSolverOracle = SolverFactory.newDefault();
Reader readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
int varnr = vars.get(i);
int assumpsArray[] = new int[sol.size() + 1];
int c = 0;
for (int a : sol) {
assumpsArray[c] = a;
c++;
}
assumpsArray[assumpsArray.length - 1] = varnr;
IVecInt assumps = new VecInt(assumpsArray);
System.out.println(assumps);
// Check
if (satSolver.isSatisfiable(assumps)) {
sol.add(varnr);
} else {
System.out.println("unsat: " + varnr);
}
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
}
}
示例4: testIterativeCorrectWay
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
@Test
public void testIterativeCorrectWay() throws FileNotFoundException,
ParseFormatException, IOException, ContradictionException,
TimeoutException {
ISolver satSolver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(satSolver);
IProblem p = reader.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
Set<Integer> sol = new HashSet<Integer>();
for (int i = 1; i <= p.nVars(); i++) {
ISolver satSolverOracle = SolverFactory.newDefault();
Reader readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
int assumpsArray[] = new int[sol.size() + 1];
int c = 0;
for (int a : sol) {
assumpsArray[c] = a;
c++;
}
assumpsArray[assumpsArray.length - 1] = -i;
IVecInt assumps = new VecInt(assumpsArray);
System.out.println(assumps);
// Check
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
if (satSolver.isSatisfiable(assumps)) {
sol.add(-i);
continue;
}
assumpsArray[assumpsArray.length - 1] = i;
System.out.println(assumps);
satSolverOracle = SolverFactory.newDefault();
readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
if (satSolver.isSatisfiable(assumps)) {
sol.add(i);
} else {
System.out.println("unsat: " + i);
}
}
}
示例5: testBug3
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
@Test
public void testBug3() throws FileNotFoundException, ParseFormatException, IOException, ContradictionException{
ISolver satSolver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(satSolver);
IProblem p = reader.parseInstance("TestData/Realistic/Eshop-fm.dimacs");
List<Integer> uncovered = new ArrayList<Integer>();
for(int i = 1; i <= p.nVars(); i++){
uncovered.add(-i);
uncovered.add(i);
}
List<Integer> canBeSet = new ArrayList<Integer>();
Set<Integer> sol = new HashSet<Integer>();
for(int i=0; i<uncovered.size(); i++){
ISolver satSolverOracle = SolverFactory.newDefault();
Reader readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("TestData/Realistic/Eshop-fm.dimacs");
// Set it
int varnr = uncovered.get(i);
// Check
try {
// Convert
int assumpsArray[] = new int[sol.size()+1];
int c = 0;
for(int a : sol){
assumpsArray[c] = a;
c++;
}
assumpsArray[assumpsArray.length-1] = varnr;
IVecInt assumps = new VecInt(assumpsArray);
System.out.println(assumps);
// Check
if(satSolver.isSatisfiable(assumps)){
sol.add(varnr);
canBeSet.add(varnr);
}else{
System.out.println("unsat: " + varnr);
}
assertTrue(satSolverOracle.isSatisfiable(assumps) == satSolver.isSatisfiable(assumps));
} catch (org.sat4j.specs.TimeoutException e1) {
}
}
}
示例6: testIterativeAssumptionCallsWithSet
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
@Test
public void testIterativeAssumptionCallsWithSet()
throws FileNotFoundException, ParseFormatException, IOException,
ContradictionException, TimeoutException {
ISolver satSolver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(satSolver);
IProblem p = reader.parseInstance("TestData/Realistic/Eshop-fm.dimacs");
List<Integer> vars = new ArrayList<Integer>();
for (int i = 1; i <= p.nVars(); i++) {
vars.add(-i);
vars.add(i);
}
Set<Integer> sol = new HashSet<Integer>();
for (int i = 0; i < vars.size(); i++) {
ISolver satSolverOracle = SolverFactory.newDefault();
Reader readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("TestData/Realistic/Eshop-fm.dimacs");
int varnr = vars.get(i);
int assumpsArray[] = new int[sol.size() + 1];
int c = 0;
for (int a : sol) {
assumpsArray[c] = a;
c++;
}
assumpsArray[assumpsArray.length - 1] = varnr;
IVecInt assumps = new VecInt(assumpsArray);
System.out.println(assumps);
// Check
if (satSolver.isSatisfiable(assumps)) {
sol.add(varnr);
} else {
System.out.println("unsat: " + varnr);
}
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
}
}
示例7: testIterativeAssumptionCallsWithList
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
@Test
public void testIterativeAssumptionCallsWithList()
throws FileNotFoundException, ParseFormatException, IOException,
ContradictionException, TimeoutException {
ISolver satSolver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(satSolver);
IProblem p = reader.parseInstance("TestData/Realistic/Eshop-fm.dimacs");
List<Integer> vars = new ArrayList<Integer>();
for (int i = 1; i <= p.nVars(); i++) {
vars.add(-i);
vars.add(i);
}
List<Integer> sol = new ArrayList<Integer>();
for (int i = 0; i < vars.size(); i++) {
ISolver satSolverOracle = SolverFactory.newDefault();
Reader readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("TestData/Realistic/Eshop-fm.dimacs");
int varnr = vars.get(i);
int assumpsArray[] = new int[sol.size() + 1];
int c = 0;
for (int a : sol) {
assumpsArray[c] = a;
c++;
}
assumpsArray[assumpsArray.length - 1] = varnr;
IVecInt assumps = new VecInt(assumpsArray);
System.out.println(assumps);
// Check
if (satSolver.isSatisfiable(assumps)) {
sol.add(varnr);
} else {
System.out.println("unsat: " + varnr);
}
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
}
}
示例8: testIterativeCorrectWay
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
@Test
public void testIterativeCorrectWay() throws FileNotFoundException,
ParseFormatException, IOException, ContradictionException,
TimeoutException {
ISolver satSolver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(satSolver);
IProblem p = reader.parseInstance("TestData/Realistic/Eshop-fm.dimacs");
Set<Integer> sol = new HashSet<Integer>();
for (int i = 1; i <= p.nVars(); i++) {
ISolver satSolverOracle = SolverFactory.newDefault();
Reader readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("TestData/Realistic/Eshop-fm.dimacs");
int assumpsArray[] = new int[sol.size() + 1];
int c = 0;
for (int a : sol) {
assumpsArray[c] = a;
c++;
}
assumpsArray[assumpsArray.length - 1] = -i;
IVecInt assumps = new VecInt(assumpsArray);
System.out.println(assumps);
// Check
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
if (satSolver.isSatisfiable(assumps)) {
sol.add(-i);
continue;
}
assumpsArray[assumpsArray.length - 1] = i;
System.out.println(assumps);
satSolverOracle = SolverFactory.newDefault();
readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("TestData/Realistic/Eshop-fm.dimacs");
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
if (satSolver.isSatisfiable(assumps)) {
sol.add(i);
} else {
System.out.println("unsat: " + i);
}
}
}
示例9: testIterativeAssumptionCallsWithList
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
@Test
public void testIterativeAssumptionCallsWithList()
throws FileNotFoundException, ParseFormatException, IOException,
ContradictionException, TimeoutException {
ISolver satSolver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(satSolver);
IProblem p = reader.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
List<Integer> vars = new ArrayList<Integer>();
for (int i = 1; i <= p.nVars(); i++) {
vars.add(-i);
vars.add(i);
}
List<Integer> sol = new ArrayList<Integer>();
for (int i = 0; i < vars.size(); i++) {
ISolver satSolverOracle = SolverFactory.newDefault();
Reader readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
int varnr = vars.get(i);
int assumpsArray[] = new int[sol.size() + 1];
int c = 0;
for (int a : sol) {
assumpsArray[c] = a;
c++;
}
assumpsArray[assumpsArray.length - 1] = varnr;
IVecInt assumps = new VecInt(assumpsArray);
// Check
if (satSolver.isSatisfiable(assumps)) {
sol.add(varnr);
}
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
}
}
示例10: testIterativeCorrectWay
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
@Test
public void testIterativeCorrectWay() throws FileNotFoundException,
ParseFormatException, IOException, ContradictionException,
TimeoutException {
ISolver satSolver = SolverFactory.newDefault();
Reader reader = new LecteurDimacs(satSolver);
IProblem p = reader.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
Set<Integer> sol = new HashSet<Integer>();
for (int i = 1; i <= p.nVars(); i++) {
ISolver satSolverOracle = SolverFactory.newDefault();
Reader readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
int assumpsArray[] = new int[sol.size() + 1];
int c = 0;
for (int a : sol) {
assumpsArray[c] = a;
c++;
}
assumpsArray[assumpsArray.length - 1] = -i;
IVecInt assumps = new VecInt(assumpsArray);
// Check
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
if (satSolver.isSatisfiable(assumps)) {
sol.add(-i);
continue;
}
assumpsArray[assumpsArray.length - 1] = i;
satSolverOracle = SolverFactory.newDefault();
readerOracle = new LecteurDimacs(satSolverOracle);
readerOracle.parseInstance("src/test/testfiles/Eshop-fm.dimacs");
assertEquals(satSolverOracle.isSatisfiable(assumps),
satSolver.isSatisfiable(assumps));
if (satSolver.isSatisfiable(assumps)) {
sol.add(i);
}
}
}
示例11: print_model
import org.sat4j.specs.IProblem; //导入方法依赖的package包/类
public static void print_model(IProblem solver) {
for (int index = 1; index <= solver.nVars(); ++index) {
System.err.print((solver.model(index) ? "+" : "-") + index + " ");
}
}