簡體   English   中英

Minizinc數組組合

[英]Minizinc array of sets combining

給定一組不具有相同大小的集合,請生成一組集合,這些集合是給定集合的組合對。 嘗試了各種理解安排。 錯誤消息有時是“不是整數表達式”

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM