我想为 MiniZinc 中一组整数的每个子集创建一个约束,沿着这条线......
constraint forall (S subset C, k in M) (
% Some constraint over the set S, and integer k
);
我还想使用S
约束中的基数,并且C
只是一组整数。是否有我可以使用的子集语法?(上述模型不起作用)。
我想为 MiniZinc 中一组整数的每个子集创建一个约束,沿着这条线......
constraint forall (S subset C, k in M) (
% Some constraint over the set S, and integer k
);
我还想使用S
约束中的基数,并且C
只是一组整数。是否有我可以使用的子集语法?(上述模型不起作用)。
目前没有用于数组/集合的生成器;因此,除了在数据文件中手动列出幂集之外,没有可行的方法来迭代给定集合的所有子集。
在大多数情况下,可以重新制定模型,从而不需要这些生成器。例如,考虑使用变量集:
var set of C: S;
% or if you want to declare S in a different way:
% var set of 0..100: S; % Different declaration
% constraint S subset C;
forall (k in M) {
% some cool constraints
}
这将使您能够制作包含约束条件的模型,该约束条件声明“存在这样的集合S,因此所有约束条件都成立”。