迷你锌"var set of int: x"代替"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"上使用最小值,我应该在"set of int: x"上使用它。不幸的是,我不理解这两者之间的区别(从我所读到的内容来看,这可能与定义每个集合的大小有关,但我不确定)。

谁能给我解释一下这个问题并提出解决方案?我会非常非常感激。谢谢!

首先:A var是一个决策变量。所有最小化程序的目标都是决定所有决策变量的值。你不知道这些值是多少,你试着求出这些值。任何不是var的都是已知数。(不考虑set的使用)

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

(我希望MiniZinc有<所以我不说谎,我不确定)>

我已经找到了解决方案-我们应该创建一个集合元素的数组,以使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..)

相关内容

  • 没有找到相关文章

最新更新