0

我正在研究 CSP 中的解释,并尝试同时学习 Choco。求解器或任何类型的教程是否提供任何解释示例?官方文档位于: https ://choco-solver.org/docs/advanced-usages/explanations/ 只说使用solver.setLearningSignedClauses()作为API,但没有解释如何使用它。我试图在我的代码中添加这一行(会议问题),但它没有产生任何效果:

import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solution;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.search.strategy.Search;
import org.chocosolver.solver.variables.IntVar;

public class csp {

     public static void main(String[] args) {

         // Modeling CSP
         Model model = new Model("Conference");

         // creating the variables and domains
         IntVar[] vars = model.intVarArray(4, 1, 4);
         // constraints
         // unary constraint
         model.arithm(vars[2], "=", 2).post();
         // binary constraints
         model.arithm(vars[0], "!=", vars[1]).post();
         model.arithm(vars[2], "!=", vars[0]).post();
         model.arithm(vars[3], "!=", vars[0]).post();
         model.arithm(vars[2], "!=", vars[1]).post();
         model.arithm(vars[1], "!=", vars[0]).post();
         model.arithm(vars[2], "!=", vars[3]).post();
         // greater than
         model.arithm(vars[3], ">", vars[1]).post();
         model.arithm(vars[3], ">", vars[0]).post();
         model.arithm(vars[2], ">", vars[0]).post();
         model.arithm(vars[2], ">", vars[1]).post();

         // Solving CSP
         Solver solver = model.getSolver();
         Search.defaultSearch(model);
         
         // enable explanation engine
         solver.setLearningSignedClauses();

         Solution sol = new Solution(model);
         int count = 1;
         System.out.println("Solutions: ");
         while (solver.solve()) {
             sol.record();
             System.out.println("Solution " + count);
             for (int i = 0; i < vars.length; i++)
                 System.out.println("\t\t" + sol.getIntVal(vars[i]));
             count++;
         }

         System.out.println("End");
     }

}

你能否给我一个关于如何在 choco 中使用解释的例子,或者说我下面的代码缺少什么?

4

0 回答 0