Minizinc "var set of int: x" 而不是 "set of int: x"

Minizinc "var set of int: x" instead of "set of int: x"

我在高尔夫球手问题中设置了一组数组(每周应该有分组,这样两个球员一起打球的次数不能超过一次,每个人每周只打一次球):

int: gr; %number of groups
set of int: G=1..gr;
int: sz; %size of groups
set of int: S=1..sz;
int: n=gr*sz; %number of players
set of int: P=1..n;
int: we; % number of weeks
set of int: W=1..we;

include "globals.mzn";

array[G,W] of var set of P: X; %X[g,w] is the set of people that form group g in week w

我的约束如下(我不确定是否一切正常):

constraint forall (g in G, w in W) (card (X[g,w]) = sz); %Each group should have size sz

constraint forall (w in W, g,h in G where g > h) (disjoint(X[g,w], X[h,w])); % Nobody plays twice in one week

constraint forall (w,u in W where w > u) (forall (g,h in G) (card(X[g,w] intersect X[h,u]) <= 1 )); % Two players never meet more than once

constraint forall (w in 2..we) (w+sz-1 in X[1,w] /\ 1 in X[1,w]); %Symmetries breaking: week permutations

constraint forall (w in W, g in 1..gr-1) ( min(X[g,w]) < min(X[g+1,w]) ); %Symmetries breaking: group permutations

constraint forall (g in G, s in S) ( s+sz*(g-1) in X[g,1]);

solve satisfy;

output [ show(X[i,j]) ++ if j == we then "\n" else " " endif | i in 1..gr, j in 1..we ];

我的问题在于约束编号 5。我不能在 "var set of int: x" 上使用 min,我应该在 "set of int: x" 上使用它。不幸的是,我不明白这两者之间的区别(从我读过的内容来看,这可能与定义每个集合的大小有关,但我不确定)。

有人可以向我解释问题并提出解决方案吗?我将非常感激。谢谢!

首先:Avar是一个决策变量。所有 Minizinc 程序的目标都是决定所有决策变量的值。您不知道这些值是什么,而您正试图找到这些值。任何不是 var 的东西都只是一个已知数字。 (忽略集合的使用)

决策变量 (var) 的 min(X[g,w]) 在 Minizinc 中根本没有实现。原因是使用不带最小值的 X[g,w] < X[g+1,w] 更有意义。为什么只限制所有数字中两组中最小的数字。即 {1,3,5} < {1,4} 代替 1 < 1

(我希望 MiniZinc 有 < on set 所以我没有撒谎,我不确定)

我找到了解决方案 - 我们应该制作一个集合的元素数组,以使 max 函数在这种情况下成为可能。

constraint forall (w in 2..we) ( max([i | i in X[1,w-1]]) < max([i | i in X[1,w]])); %Symmetries breaking: week permutations

constraint forall (w in W, g in 1..gr-1) ( min([i | i in X[g,w]]) < min([i | i in X[g+1,w]]));% Symmetries breaking: group permutations (I have been trying to speed up the constraint above, but it does not work with var set of int..)