Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Choco解算器:在intVar的一部分上定义约束_Java_Solver_Choco - Fatal编程技术网

Java Choco解算器:在intVar的一部分上定义约束

Java Choco解算器:在intVar的一部分上定义约束,java,solver,choco,Java,Solver,Choco,我们能用choco solver检查2个分数之间的相等吗 我有一个二维数组,对于其中的每个元素,它们的域都是不同的数字,具有相同的形式:一个由6位数字组成的数字(元素可以有一些值的示例:7810106801391111)。 我的问题是,如何只比较一个数字而不是整个数字 我必须做一些看起来像这样的事情: Model model = new Model(); IntVar[][] array = new IntVar[height][width]; .... // getting the doma

我们能用choco solver检查2个分数之间的相等吗

我有一个二维数组,对于其中的每个元素,它们的域都是不同的数字,具有相同的形式:一个由6位数字组成的数字(元素可以有一些值的示例:7810106801391111)。 我的问题是,如何只比较一个数字而不是整个数字

我必须做一些看起来像这样的事情:

Model model = new Model();
IntVar[][] array = new IntVar[height][width];

....
// getting the domains for each element of array
....

for(int i = 0; i < height; i++) {
    for(int j = 0; j < width; j++) {
       model.arithm(array[i][j]3rdDigit, "=", array[i+1][j]4thDigit);
    }
}
Model Model=新模型();
IntVar[][]数组=新的IntVar[高度][宽度];
....
//获取数组中每个元素的域
....
对于(int i=0;i

你能帮助我吗?

< P>你可以考虑将数字分解成一系列数字:对于当前的每个ItVaR,你可以创建一个数组ARR 6(如你的数字总是有6位数字),并且有另一个ItVar的值,具有以下约束:

IntVar value = model.intVar(0,999999);
model.scalar(arr, new int[]{100000, 10000, 1000, 100, 10, 1}, "=", value).post();
然后,您可以发布关于值的其他约束(您可以将其存储在矩阵中,就像您已经做的那样)

另一种可能更慢,可能是发布以下约束(不为数字创建变量):

for(int i=0;i
我不知道choco(因此可能有更好的答案),但这里有一个建议。你总是可以把数字写成一系列数字:x=d1+10*d2+100*d3。。。。每个数字都在0和9之间。如果可能,您可以避免使用
mod
作为
array
的第三个维度。
for(int i = 0; i < height; i++) {
    for(int j = 0; j < width; j++) {
       IntVar thirdDigit = model.intVar(0,9);
       model.mod(array[i][j], 1000, thirdDigit).post();
       IntVar fourthDigit = model.intVar(0,9);
       model.mod(array[i+1][j], 100, fourthDigit).post();
       model.arithm(thirdDigit, "=", fourthDigit).post();
    }
}