[英]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: 为此,我考虑了将问题表述为CSP的想法,其中变量为:
x_o,y_o: position of object o in the environment x_o,y_o:对象o在环境中的位置
theta_o: orientation of object o theta_o:对象o的方向
and the domains are: 和域是:
a certain range [a,b] for x and y (ie, the dimensions of the 2D grid) x和y的某个范围[a,b](即2D网格的尺寸)
[0,90,180,270] degrees for the orientation. 方向为[0,90,180,270]度。
To implement this problem, I'm using Choco in Eclipse 4.7.1a. 为了实现此问题,我在Eclipse 4.7.1a中使用Choco 。
My problem is the following: 我的问题如下:
I'd like to espress a constraint like: object a is in front of object b. 我想约束一个约束:对象a 在对象b的前面 。
Since objects have an orientation, I thought that a possible way to express this constraint was: 由于对象具有方向性,所以我认为表达此约束的一种可能方法是:
From this resource I found that Choco uses Ibex to solve real constraints. 从该资源中,我发现Choco使用Ibex解决实际约束。 I followed the installation instructions and added the shared library to the java.library.path
. 我按照安装说明进行操作,并将共享库添加到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 @Tobi我正在使用Linux
Upgrading to Choco 4.0.6 and Ibex 2.6.3 fixed that problem. 升级到Choco 4.0.6和Ibex 2.6.3可以解决此问题。 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());
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.