Choco Solver:如何使用实变量和约束设置CSP

时间:2017-12-12 10:03:41

标签: constraints coredump choco

我想写一个自动生成室内环境的程序。为此,我考虑了将问题表述为CSP的想法,其中变量为:

  • x_o,y_o:对象o在环境中的位置

  • theta_o:对象的方向o

域名是:

  • x和y的某个范围[a,b](即2D网格的尺寸)

  • [0,90,180,270]方向的度数。

要实现此问题,我在Eclipse 4.7.1a中使用Choco

我的问题如下:

我想要一个约束,例如:对象a 位于对象b的前面。

由于对象具有方向,我认为表达此约束的可能方式是:

  • x_b == x_a + cos(theta_a)&& y_b == y_a + sin(theta_a)

this资源我发现Choco使用Ibex来解决实际约束。我按照安装说明将共享库添加到java.library.path。为了定义一个真正的约束,我遵循this文档,但是当我运行这段代码时:

import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solution;
import org.chocosolver.solver.variables.RealVar;

public class EnvironmentGenerationMain {

    public static void main(String[] args) {
        Model model = new Model("Environment generation problem");
        System.out.println(model.getName());

        //A
        RealVar x_a = model.realVar("X_a", 0, 2, 1.0d);
        RealVar y_a = model.realVar("Y_a", 0, 2, 1.0d);
        RealVar z_a = model.realVar("Z_a", 0, 270, 90.0d);

        //A
        RealVar x_b = model.realVar("X_b", 0, 2, 1.0d);
        RealVar y_b = model.realVar("Y_b", 0, 2, 1.0d);
        RealVar z_b = model.realVar("Z_b", 0, 270, 90.0d);

        model.post(model.realIbexGenericConstraint("{0}={1}+cos{2}", x_b,x_a,z_a));
        model.post(model.realIbexGenericConstraint("{0}={1}+sin{2}", y_b,y_a,z_a));


        Solution solution = model.getSolver().findSolution();
        if(solution != null){
            System.out.println(solution.toString());
        }

    }

}

这是我得到的错误:

Environment generation problem
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f7e322b0891, pid=21072, tid=0x00007f7e63562700
#
# JRE version: OpenJDK Runtime Environment (8.0_151-b12) (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
# Java VM: OpenJDK 64-Bit Server VM (25.151-b12 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libibex-java.so+0x4891]  Java_org_chocosolver_solver_constraints_real_Ibex_add_1ctr+0x61
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/dede/eclipse-workspace/EnvironmentGeneration/hs_err_pid21072.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

我发现这是一个常见的问题:

Failed to write core dump. Core dumps have been disabled

但我在网上找到的答案都没有解决我的问题。

所以,如果有人能指出我的解决方案,我会很高兴!!!

感谢。

1 个答案:

答案 0 :(得分:0)

@Tobi我正在使用Linux

升级到Choco 4.0.6和Ibex 2.6.3解决了这个问题。 为了使工作正常,我还必须调试代码。 这是一个有效的例子:

package it.semanticmapping.environmentgeneration;

import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solution;
import org.chocosolver.solver.variables.RealVar;

public class EnvironmentGenerationMain {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Model model = new Model("Environment Generation");
        System.out.println(model.getName());


        //A
        RealVar x_a = model.realVar("X_a", 0, 2, 0.0001d);
        RealVar y_a = model.realVar("Y_a", 0, 2, 0.0001d);
        RealVar z_a = model.realVar("Z_a", 0, Math.PI*3/2, Math.PI/2);

        //B
        RealVar x_b = model.realVar("X_b", 0, 2, 0.0001d);
        RealVar y_b = model.realVar("Y_b", 0, 2, 0.0001d);
        RealVar z_b = model.realVar("Z_b", 0, Math.PI*3/2, Math.PI/2);

        RealVar cost = model.realVar(0);

        model.post(model.realIbexGenericConstraint("{0}={1}", z_a,cost));
        model.post(model.realIbexGenericConstraint("{0}={1}+cos({2})", x_b,x_a,z_a));
        model.post(model.realIbexGenericConstraint("{0}={1}+sin({2})", y_b,y_a,z_a));
        model.post(model.realIbexGenericConstraint("{0}={1}", z_b, z_a));

        Solution solution = model.getSolver().findSolution();
        if(solution != null){
            System.out.println(solution.toString());
        }
    }

}