一套完整的结合3一套组合 [英] Complete set of combinations combining 3 set
问题描述
我需要生成组合的成套获得的结合三个不同的子集:
I need to generate the complete set of combinations obtained combining three different subset:
- 设置1 :13元素的矢量选择任何4个号码
- 设置2 :从3个元素的矢量选择任何2号。
- 设置3 :从9个元素的矢量选择任何2号。
- Set 1: choosing any 4 numbers from a vector of 13 elements.
- Set 2: choosing any 2 numbers from a vector of 3 elements.
- Set 3: choosing any 2 numbers from a vector of 9 elements.
4 4 4
3 4 4
3 3 4
3 3 3
2 4 4
2 3 4
2 3 3
2 2 4
Set A = 2 2 3
2 2 2
1 4 4
1 3 4
1 3 3
1 2 4
1 2 3
1 2 2
1 1 4
1 1 3
1 1 2
1 1 1
3 3
2 3
Set B = 2 2
1 3
1 2
1 1
4 4
3 4
3 3
2 4
Set C = 2 3
2 2
1 4
1 3
1 2
1 1
[设置A] = [20×3]
, [B组] = [6×2]
, [设置C] = [10×2]
。然后,我需要从这些三套获得所有可能的组合: AllComb = [设置A]×[B组]×[设置C] = [1200×8]
。在 AllComb
矩阵将是这样的:
[Set A] = [20 x 3]
, [Set B] = [6 x 2]
, [Set C] = [10 x 2]
. Then I need to obtain all possible combinations from these three sets: AllComb = [Set A] x [Set B] x [Set C] = [1200 x 8]
. The AllComb
matrix will be like this:
4 4 4 | 3 3 | 4 4
4 4 4 | 3 3 | 3 4
4 4 4 | 3 3 | 3 3
4 4 4 | 3 3 | 2 4
4 4 4 | 3 3 | 2 3
4 4 4 | 3 3 | 2 2
4 4 4 | 3 3 | 1 4
4 4 4 | 3 3 | 1 3
4 4 4 | 3 3 | 1 2
4 4 4 | 3 3 | 1 1
4 4 4 | 2 3 | 4 4
4 4 4 | 2 3 | 3 4
4 4 4 | 2 3 | 3 3
4 4 4 | 2 3 | 2 4
4 4 4 | 2 3 | 2 3
.
.
.
1 1 1 | 1 1 | 1 1
可惜我不能使用的集数相同,因为我需要替换的数字那样:
Unfortunately I can not use the same number for the sets since I need to substitute the numbers like that:
- 对于
设定
:1 = 10,2 = 25,3 = 30和4 = 45 - 对于
B组
:1 = 5,2 = 20,3 = 35 - 对于
设置C
:1 = 10,2 = 20,3 = 30和4 = 50
- For
Set A
: 1 = 10, 2 = 25, 3 = 30 and 4 = 45 - For
Set B
: 1 = 5, 2 = 20 and 3 = 35 - For
Set C
: 1 = 10, 2 = 20, 3 = 30 and 4 = 50
任何想法?实际案例设置往往会导致一个 AllComb
矩阵〜[491 400×8]因此量化的解决方案将被欣然接受。
Any ideas? Real case sets will often lead to an AllComb
matrix ~[491 400 x 8] so vectorized solutions will be gladly accepted.
的注:每套用以下code获得:的
a = combnk(1:H+L-1, H);
b = cumsum([a(:,1) diff(a,[],2) - 1],2);
什么是 ^ h
和→
?
^ h
是MultiheadWeigher(MHW)机的料斗。我有一个 A MHW H = 8
,我需要在每个漏斗一些材料来交付。如果我需要提供一种类型材料的所有不可能性的组合是(L + H-1)!/(H!(L-1)!)
和我计算它们与code上面写( A
和 b
)。现在,假设有3种不同的产品,那么我们有4个料斗产品A,在第4料斗2 B和2 C.产品A可以假设值 10:10:130
,产品B 10点十分30秒
和C 10:10:90
。随后的步数是A L = 13
,B L = 3
和C L = 9
What is H
and L
?
H
are the hoppers of a MultiheadWeigher (MHW) machines. I have a MHW with H=8
and I need to deliver in each of these hoppers some materials. If I need to deliver just one type of material all possibile combinations are (L+H-1)!/(H!(L-1)!)
and i compute them with the code write above (a
and b
). Now, suppose to have 3 different product then we have 4 hoppers for product A, 2 for B and 2 for C. Product A in the first 4 hoppers can assume values 10:10:130
, Product B 10:10:30
and c 10:10:90
. Then the number of steps are for A L=13
, B L=3
and C L=9
推荐答案
您基本上需要找到
- Combinations with repetition for each set;
- "Multi-variations" (I don't know the correct name for this) of the results of stage 1.
这两个阶段可以或多或少相同的逻辑来解决,从这里服用。
Both stages can be solved with more or less the same logic, taken from here.
%// Stage 1, set A
LA = 4;
HA = 3;
SetA = cell(1,HA);
[SetA{:}] = ndgrid(1:LA);
SetA = cat(HA+1, SetA{:});
SetA = reshape(SetA,[],HA);
SetA = unique(sort(SetA(:,1:HA),2),'rows');
%// Stage 1, set B
LB = 3;
HB = 2;
SetB = cell(1,HB);
[SetB{:}] = ndgrid(1:LB);
SetB = cat(HB+1, SetB{:});
SetB = reshape(SetB,[],HB);
SetB = unique(sort(SetB(:,1:HB),2),'rows');
%// Stage 1, set C
LC = 4;
HC = 2;
SetC = cell(1,HC);
[SetC{:}] = ndgrid(1:LC);
SetC = cat(HC+1, SetC{:});
SetC = reshape(SetC,[],HC);
SetC = unique(sort(SetC(:,1:HC),2),'rows');
%// Stage 2
L = 3; %// number of sets
result = cell(1,L);
[result{:}] = ndgrid(1:size(SetA,1),1:size(SetB,1),1:size(SetC,1));
result = cat(L+1, result{:});
result = reshape(result,[],L);
result = [ SetA(result(:,1),:) SetB(result(:,2),:) SetC(result(:,3),:) ];
result = flipud(sortrows(result)); %// put into desired order
这给了
result =
4 4 4 3 3 4 4
4 4 4 3 3 3 4
4 4 4 3 3 3 3
4 4 4 3 3 2 4
4 4 4 3 3 2 3
4 4 4 3 3 2 2
4 4 4 3 3 1 4
4 4 4 3 3 1 3
4 4 4 3 3 1 2
4 4 4 3 3 1 1
4 4 4 2 3 4 4
4 4 4 2 3 3 4
4 4 4 2 3 3 3
4 4 4 2 3 2 4
4 4 4 2 3 2 3
4 4 4 2 3 2 2
4 4 4 2 3 1 4
4 4 4 2 3 1 3
4 4 4 2 3 1 2
...
这篇关于一套完整的结合3一套组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!