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


Java IProblem.model方法代码示例

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

示例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;
}
 
开发者ID:Vapsel,项目名称:social-media-analytic-system,代码行数:19,代码来源:SATSolverManagerImpl.java

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

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

示例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;
}
 
开发者ID:supertweety,项目名称:mln2poss,代码行数:33,代码来源:GroundProgramSolver.java


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