0

我在高尔夫球手问题中有一组集合(每周应该有一组,这样没有两个玩家一起玩超过一次,并且每个人每周都玩一次):

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”上使用它。不幸的是,我不明白这两者之间的区别(从我读过的内容来看,这可能与定义每组的大小有关,但我不确定)。

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

4

2 回答 2

0

我已经找到了解决方案——我们应该创建一个集合的元素数组,以在这种情况下使 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..)
于 2016-11-10T17:47:48.003 回答
0

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

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

(我希望 MiniZinc 有 < 集合所以我不撒谎,我不确定)

于 2016-11-05T19:31:27.113 回答