给定一个大小不同的集合数组,生成一个集合数组,这些集合是给定集合的组合对。尝试了各种理解安排。错误消息有时是“不是整数表达式”
int: n = 4; % number of groups
set of int: Grp = 1..n;
array[Grp] of int: m = [3,2,2,3]; % sizes of groups
int: t = sum(i in Grp)(m[i]); % Total number of members
set of int: PRSN = 1..t; % a unique id for each member
% An array of sets of groups.
array[1..n] of set of int: GrpSets = [{1,2,3}, {4,5}, {6,7}, {8,9,10}];
% COMBINED GROUPS
int: r = 2; % number of combines
set of int: Cmb = 1..r;
array[Cmb] of Grp: cg1 = [1,2];
array[Cmb] of Grp: cg2 = [3,4]; % gc1[1] to be combined with gc2[1] ...
% generate array of combined sets. Both versions fails.
%array[PRSN] of set of int: CmbSets = [ {GrpSets[cg1[k]] union GrpSets[cg2[k]]}| k in 1..r];
array[PRSN] of set of int: CmbSets = [{GrpSets[cg1[1]] union GrpSets[cg2[1]]}, {GrpSets[cg1[2]] union GrpSets[cg2[2]]}];
% Expected outcome CmbSets = [{1,2,3,6,7}, {4,5,8,9,10}]
solve satisfy;
output ["CmbSets = ", show(CmbSets),
";\n" ];