魔术系列:解决方案不适用于choco

问题描述

与Choco合作解决Magic Series问题。解决方案不起作用。 Choco Solver显示了1个解决方案,但未打印任何内容。魔术系列也称为魔术序列。

代码低于==>

public class MagicSeries {

  public static void main(String[] args) {
    int n = 5;
    IntVar[] x;

    Model model = new Model("Magic Series");
    int[] values = new int[n];
    for(int k = 0 ; k < n ; k++){
      values[k] = 1;
    }

    x = model.intVarArray("x",n,n-1,false );

    //Defining the constraints
    for(int i = 0 ; i < n ; i++){
      BoolVar[] innerVariables = new BoolVar[n];
      for(int j = 0 ; j < n ; j++){
        innerVariables[j] = model.boolVar();

//        model.ifOnlyIf(model.arithm(x[j],"=",i),model.arithm(innerVariables[j],1));
        model.arithm(x[j],i).reifyWith(innerVariables[j]);
      }
      model.scalar(innerVariables,values,x[i]).post();
    }

    Solver solver = model.getSolver();

//    solver.showSolutions();
//    solver.findSolution();
//    solver.solve();
//    System.out.println(solver.findAllSolutions());

    while (solver.solve()){
      System.out.println("\n************************\n");
      System.out.println(solver.findSolution());

      System.out.println("\n====================\n");
      for(int k = 0 ; k <  n ; k++){
        System.out.println("series[" + k + "] : "+ x[k]);
      }
    }

    System.out.println("Total Number of Solutions : "+ solver.getSolutionCount());
    solver.printStatistics();



  }
}

正在打印的解决方案在==>

************************

null

====================

series[0] : x[0] = {0..4}
series[1] : x[1] = {0..4}
series[2] : x[2] = {0..4}
series[3] : x[3] = {0..4}
series[4] : x[4] = {0..4}
Total Number of Solutions : 1
** Choco 4.0.6 (2017-11) : Constraint Programming Solver,Copyleft (c) 2010-2017
- Model[Magic Series] features:
    Variables : 80
    Constraints : 55
    Building time : 0.126s
    User-defined search strategy : yes
    Complementary search strategy : no
- Complete search - 1 solution found.
    Model[Magic Series]
    Solutions: 1
    Building time : 0.126s
    Resolution time : 0.084s
    Nodes: 10 (119.1 n/s) 
    Backtracks: 19
    Fails: 9
    Restarts: 0

Process finished with exit code 0

我在做什么错?任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...