在我的 Minizinc 项目中,我试图生成一个包含 n 个集合的数组。给定一个包含 t 个不同数字的数组,生成 n 个不同的集合,其
基数在数组 m 中给出。例如:t = 10;n = 4; 和 m = [3, 2, 2, 3];我想生成一组集合 x = [1..3, 4..5, 6..7, 8..10];
但是我从下面的代码中得到的是 x = [1..3, 4..5, {6,10}, 7..9]; (我不想使用求解最小化或其他各种求解,因为我的
目的只是生成一个中间集数组。)
int: n = 4; % number of groups
array[1..n] of int: m = [3, 2, 2, 3]; % size of each group
int: t = sum(i in 1..n)(m[i]); % total members
array[1..n] of var set of 1..t: x; % the array of sets
constraint forall(i in 1..n-1)(x[i] > x[i+1]); % SORT .
constraint forall(i in 1..n)(card(x[i] ) = m[i]); % Size of each set
constraint forall(i in 1..n-1)( x[i] intersect x[i+1] = {}); %
% I can't see a way to keep the digits in order
%constraint array_intersect(x) = {}; % this didn't help
solve satisfy;
output [show(x)];