01-24-2014 03:54 AM
I have a list of items A,B,C,D,E,F.. and I'd like to loop through all possible unique pair combinations (note: AB and BA are the same pair). I know that the possible pair combinatios increase by (N-1)!! (!!=double factorial):
2 items : 1!! = 1=1
4 items : 3!! = 1*3=3
6 items : 5!! = 1*3*5=15
8 items : 7!! = 1*3*5*7=105
10 items : 9!! = 1*3*5*7*9=945
However I can't figure out an algorithm how to loop through all unique pair combinations once in Labview. I have N items, where N is even and reasonably low so that the number of pair combination is not too high. This is how it would look like for for 6 items: 15 different unique pair combinations. One row of index pairs is what I'd like to get for each loop index.
[0,1],[2,3],[4,5] (= AB,CD,EF)
[0,1],[2,4],[3,5] (= AB,CE,DF)
[0,1],[2,5],[3,4] (= AB,CF,DE)
[0,2],[1,3],[4,5] (= AC,BD,EF)
[0,2],[1,4],[3,5] (= AC,BE,DF)
[0,2],[1,5],[3,4] (= AC,BF,DE)
[0,3],[1,2],[4,5] (= AD,BC,EF)
[0,3],[1,4],[2,5] (= AD,BE,CF)
[0,3],[1,5],[2,4] (= AD,BF,CE)
[0,4],[1,2],[4,5] (= AE,BC,DF)
[0,4],[1,3],[2,5] (= AE,BD,CF)
[0,4],[1,5],[2,3] (= AE,BF,CD)
[0,5],[1,2],[3,4] (= AF,BC,DE)
[0,5],[1,3],[2,4] (= AF,BD,CE)
[0,5],[1,4],[2,3] (= AF,BE,CD)
I have score for each possible pair and I'm trying to get a group of pairs out of the N items with the highest total group score.
Thanks in advance
01-24-2014 04:27 AM - edited 01-24-2014 04:27 AM
01-24-2014 04:55 AM
Gerd I'm afraid that isn't correct. Your algorithm just gives an array increasing like this ...
1 (1)
1+2+3 (6)
1+2+3+4+5 (15)
1+2+3+4+5+6+7 (28) etc
rather than in a double factorial manner.
01-24-2014 05:04 AM
01-24-2014 05:19 AM
Gerd, I think you'll find that your snippet gives "unique pairs" rather than "unique pair combinations".
Having said that, I think that the unique pairs can subsequently be used to generate the necessary combinations ... it's just a case of working out how !
01-24-2014 05:24 AM
Hi Neil,
ok, I missed the word "combinations".
Atleast the OP now already has a "1 row list" of all possible combinations. Now we only need to pick some elements from it.
But well, this is a nice job of learning recursion and implementing it in LabVIEW. 😄
01-24-2014 05:37 AM
Thanks for the replys so far. What I actually want are the unique combinations of the pairs. Greg, out of your list the unique pair combinations would be:
1st unique pair combination: [0,1] and [2,3]
2nd unique pair combination: [0,2] and [1,3]
3rd unique pair combination: [0,3] and [1,2]
The question remains how to get these.
01-24-2014 05:52 AM
This was an interesting conversation a few years ago - http://forums.ni.com/t5/LabVIEW/How-can-I-create-list-of-permutations/td-p/1256988