0

我有一个模型需要将 var float 数组的每个元素限制为完全不同

我尝试使用全局 alldifferent 全局约束,但出现以下错误:

MiniZinc: type error: no function or predicate with this signature found: `alldifferent(array[int] of var float)'

所以我用以下理解替换了 alldifferent 约束:

constraint forall (i,j in 1..nVERTICIES where i<j) (X[i] != X[j]);

但是现在当我使用地理编码求解器时出现以下错误:

Error: Registry: Constraint float_lin_ne not found

当我使用 G12 MIP 求解器时出现以下错误:

flatzinc: error: the built-in operation `float_lin_ne/3' is not supported by the MIP solver backend.

有没有不同的方法可以编码这个约束?

4

2 回答 2

0

对于您的第一个问题:根据官方文档,MiniZinc 不支持 alldifferent float。仅支持整数。

对于您的第二个问题和第三个问题:您的求解器不支持浮动。也许您没有使用最简单的求解器和/或最新的 MiniZinc?

另一个更好的解决方案是将浮点问题转换为整数问题。只需将您的浮点范围映射到整数范围即可。

于 2017-06-17T08:51:00.137 回答
0

正如其他一些回应所提到的那样(据我所知)没有alldifferent用于花车。

您将此全局约束表达为一系列二元不等式是一种有效的方法,但是您遇到的问题反映了确定两个浮点数是否不同的困难(这是一个更广泛的问题,不仅限于 CP 建模)。

您可以做的一种解决方案是比较变量之间的绝对差异并强制它必须大于某个可配置的值。

int: nVERTICES = 10;
float: epsilon = 0.001; % the minimum floats need to be apart to be considered not equal.

array[1..nVERTICES] of var -10.0..10.0: X;
constraint forall (i, j in 1..nVERTICES where i < j) (abs(X[i] - X[j]) >= epsilon);

solve satisfy;

output [ show(X) ];

另请注意,我设置了一个域,X而不仅仅是将其声明为浮点数。Gecode: Float::linear: Number out of limits在我切换到明确指定域之前,我一直在经历。

于 2019-01-13T12:12:31.650 回答