简体   繁体   中英

Choco Solver: how to setup a CSP with real variables and constraints

I'd like to write a program for automatically generating indoor environments. To this end, I considered the idea of formulating the problem as a CSP , where the variables are:

  • x_o,y_o: position of object o in the environment

  • theta_o: orientation of object o

and the domains are:

  • a certain range [a,b] for x and y (ie, the dimensions of the 2D grid)

  • [0,90,180,270] degrees for the orientation.

To implement this problem, I'm using Choco in Eclipse 4.7.1a.

My problem is the following:

I'd like to espress a constraint like: object a is in front of object b.

Since objects have an orientation, I thought that a possible way to express this constraint was:

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

From this resource I found that Choco uses Ibex to solve real constraints. I followed the installation instructions and added the shared library to the java.library.path . To define a real constraint, I followed this docs, but when I run this piece of code:

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());
        }

    }

}

this is the error I get:

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.
#

I found that this is a common issue:

Failed to write core dump. Core dumps have been disabled

but none of the answers I found on the web, solved my problem.

So, I'd be very glad if someone could point me out a solution!!!

Thanks.

@Tobi I'm using Linux

Upgrading to Choco 4.0.6 and Ibex 2.6.3 fixed that problem. To get things working, I also had to debug the code. Here it's a working example:

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());
        }
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM