LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Finding all possible Combination


@altenbach wrote:

To get the max and min sum, all you need to do is sort the array and sum the last four and first four element of the sorted array, respectively. Right?


It is really important to ask the right question and not make up partial solution steps that may or may not be needed. Originally you asked how to generate all the possible combinations while this is not even needed to solve the problem. 😄

 

So here is the solution that gives the four elements with the largest sum and the four elements with the smallest sum as well as their sums.

 

MaxMinSumCombinationOfFour.png

 

 

This assumes that there are no unusual values (such as NaN, etc.) in the array. If there are, you need to decide what to do and handle it accordingly.

 

(Of course generating all possible combinations is an interesting programming task too and we already showed you how to do that. Good exercise! Study it!)

Message 11 of 17
(1,912 Views)

@altenbach wrote:
(Of course generating all possible combinations is an interesting programming task too and we already showed you how to do that. Good exercise! Study it!)

Here's how that could look like, i.e. the solution to your original problem (except it is DBL instead of SGL, same basic code):

 

"I have a set of 60 data(single precision floating value of 1 d array of size 60). I would like to find all possible combinations of 4 elements"

 

AllCombinations4Of60.png

 

 

Message 12 of 17
(1,908 Views)

Thanks 

0 Kudos
Message 13 of 17
(1,886 Views)

If order matters, I am sure you can still do it with one loop pyramid. Try it! You could generate all permutations for each right after the ToU8, or even change the logic completely. Even your smallest FOR loop needs to execute exactly once, and not gazillion times. It belongs on the toplevel diagram and not inside any loops, because the output never changes. Even the permutations can be calculated once and implemented as a lookup table.

 

It is not nice if you constantly change the problem specification on us. Can you give us the original and correct problem specification verbatim from the beginning instead? It is useless to solve the wrong problems because you don't tell us the whole story. That's now the third time you changed specs completely!!! 😮 Is this homework or school?

0 Kudos
Message 14 of 17
(1,871 Views)

As I told in my last post, i need to find all possible permutations of 4 element groups in total of 60 elements and i need array indexes (indexes of 4 elements in 60 element array say for one permutation it is 5,17,25,58, for another it is 1,55,56,57 etc...total 11703240 permutations , 60p4) of these elements also  for finding some combinations like which all permutations  gives a value less than  given value,  which all combinations gives sum between two given numbers, which permutations gives maximum sum , which permutations gives minimum sum etc.. Hope this time my requirements are clear..

As i said in my last post, i have written a code clubbing your code with some other permutation code, and I am able to meet all my above requirements.. code is shown below, which gives me 4 index elements ( they are indexes of original 60 element array) for all 60p4 permutations .. rest of the code for finding max sum, min sum, any other combinations etc is not shown below..hope its clear now..Untitled.png all my above requirements with this code..

Thank you once again for your help, suggestions and code..

0 Kudos
Message 15 of 17
(1,841 Views)

Obviously, you did not understand what I meant. My suggestion will give the same result as yours, except more efficiently and with much less code clutter.

0 Kudos
Message 16 of 17
(1,835 Views)

What I meant is that you calculate the permutations from scratch for each unique set while it is sufficient to do that exactly once. Here's what I had in mind. Now the permutations are created immediately in the main loop pyramid. Let me know if you have any questions.

 

permutations4of60.png

 

(Seen you are using my old code here)

0 Kudos
Message 17 of 17
(1,817 Views)