From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

run time combinations generation

Hi everyone, i am trying to generate run time combinations but the first combination will not store in array.

For example in 2 input combination only 01,10,11 combinations will store in array. here is my code which i tried. 

 

sam67_0-1582451679893.png

 

0 Kudos
Message 1 of 3
(1,929 Views)

You'd have to upload the VI to really get specific help with your VI, but for a related/similar problem, you could check the code uploaded here: How can I create list of permutations 


GCentral
0 Kudos
Message 2 of 3
(1,893 Views)

If you know the difference between a permutation (where the order of the elements matters) and combinations (where the order does not matter), you can (a) ask the correct question (you appear to want to generate Run Time Permutations), (b) can either derive, or at least understand, the formula for the number of permutations or combinations, and can then (c) generate an algorithm to do either.

 

I'm going to treat the "special case" where you have N different items and you want to create the number of permutations and combinations of these N items taken N at a time (i.e. using all N of them).  This is almost the most trivial case, but it will illustrate how to think about these concepts and come up with an algorithm.

 

Let's let the N objects be the numbers 1, 2, ... N, and let's take the "easy" question, how many Combinations of N objects, where we use all N of them, are there?  [Did you get the right answer?  You have to choose one of them first, leaving N-1, then you chose another, leaving N-2, and after you choose N of them, there are no more left to choose.  Since the order doesn't matter in a Combination, this is the only way to do it, so nCn (the n's should be sub-scripts, but that's hard to do here), the number of combinations of N objects chosen N at a time, is 1.

 

But what if the order does matter, that is, you want the number of Permutations of N things taken N at a time (called nPn, again, with the n's as subscripts)?  Let's ask a simpler question -- how many ways can I choose the first object?  Well, there are N objects, so there are N ways to choose the first.  Once I've done that, how many ways are there to choose the second object out of the remaining N-1 objects?  N-1.  Repeating for the remaining objects, you can choose N-2 from the remaining N-2 objects, N-3 from the remaining N-3, ... and 1 object from the final remaining object.  So the number of permutations of N objects taken N at a time, nPn = N! (pronounced "N Factorial"), or N*(N-1)*N-2)*...*2*1.  Note that this function can grow pretty fast, so you probably do not want to try to list all the permutations of 10 number taken 10 at a time ...

 

How can we implement this as an algorithm?  Let's place our N elements into an Array of size N.  We want to generate (many) new N-sized Arrays, each with a different Permutation.  Here's the Divide-and-Conquer (or "Recursive") way to do this:

For each of the N elements of the Array, return all of the Arrays formed by placing Element N first and filling the remaining N-1 elements with the Permutations of the remaining N-1 elements.

That's It -- that's the entire algorithm.  But what does it mean, how does it work, and how do you code it with LabVIEW?

 

Let's do all of the Permutations of 3 objects, 1, 2, 3.  Let me call P(a, b, c) the Permutations of a, b, c.  So the algorithm says we want 1, P(2, 3); 2, P(1, 3); and 3, P(1, 2).  So what is P(2, 3)?  It is 2, P(3) (which is the same as 2, 3) and 3, 2, so P(2, 3) returns two arrays, 2, 3 and 3, 2, and the first step returns 1, 2, 3 and 1, 3, 2.  A little more work shows the next steps return 2, 1, 3; 2, 3, 1; 3, 1, 2; and 3, 2, 1.  This is a total of 6 (= 3!) Permutations..

 

If you put the objects as elements of an Array of N items, you can implement the operations with Build Array and Delete from Array.  I enjoy programming with Recursion, which you can do in LabVIEW by making your VI "reentrant".  I'll leave this as an interesting "exercise for the reader" (though I'm sure Altenbach or someone else on the Forum has done this ...)

 

Bob Schor

 

 

 

 

 

 

0 Kudos
Message 3 of 3
(1,878 Views)