当前位置: 首页>>代码示例>>Java>>正文


Java IProblem.nVars方法代码示例

本文整理汇总了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));
    }
}
 
开发者ID:TakehideSoh,项目名称:Scarab,代码行数:41,代码来源:TestSatAssumps.java

示例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));
	}
}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:46,代码来源:TestSatAssumps.java

示例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));
	}
}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:46,代码来源:TestSatAssumps.java

示例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);
		}
	}
}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:48,代码来源:TestSatAssumps.java

示例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) {
		}
	}
}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:51,代码来源:TestSatAssumps.java

示例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));
	}
}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:46,代码来源:TestSatAssumps2.java

示例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));
	}
}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:46,代码来源:TestSatAssumps2.java

示例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);
		}
	}
}
 
开发者ID:axel-halin,项目名称:Thesis-JHipster,代码行数:48,代码来源:TestSatAssumps2.java

示例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));
    }
}
 
开发者ID:TakehideSoh,项目名称:Scarab,代码行数:42,代码来源:TestSatAssumps.java

示例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);
        }
    }
}
 
开发者ID:TakehideSoh,项目名称:Scarab,代码行数:43,代码来源:TestSatAssumps.java

示例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 + " ");
    }
}
 
开发者ID:TakehideSoh,项目名称:Scarab,代码行数:6,代码来源:MikolasTest.java


注:本文中的org.sat4j.specs.IProblem.nVars方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。