Minizinc 组合数组

Minizinc array of sets combining

给定一个大小不同的集合数组,生成一个集合数组,这些集合是给定集合的组合对。尝试了各种理解安排。错误信息有时是"not an integer expression"

    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" ];  

你对 CmbSets 的两个定义有几个问题:

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]]}];

1) 集合PRSN 应该是1..2(而不是1..10),因为数组CmbSets 中只有两个元素。也许你的意思是 1..r?

2) 当使用 union 时,你不应该包含 {...} 的表达式。这就是为什么您会收到 - 有点不清楚 - 错误消息 "not an integer expression"

这里有两个工作变体:

array[1..r] of set of int: CmbSets = [ GrpSets[cg1[k]] union GrpSets[cg2[k]]| k in 1..r];

array[1..r] of set of int: CmbSets = [GrpSets[cg1[1]] union GrpSets[cg2[1]], GrpSets[cg1[2]] union GrpSets[cg2[2]]];