I need to generate the complete set of combinations obtained combining three different subset:
- 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.
Example: sample 3 from vector of 4 (H=3 and L=4) for the Set A, H=2 L=3 for the Set B and H=2 L=4 for the Set B:
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
[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:
- 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
Any ideas? Real case sets will often lead to an AllComb
matrix ~[491 400 x 8] so vectorized solutions will be gladly accepted.
Note: Each set is obtained with the following code:
a = combnk(1:H+L-1, H);
b = cumsum([a(:,1) diff(a,[],2) - 1],2);
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