algorithmic modeling for Rhino
Say I have a list as follows:
{0}
1. CAT
2. DOG
3. TREE
and I want to get every possible combination that does not necessarily use all the indices. Essentially I want a tree that would look like this:
{0}
1.CAT
2.DOG
3.TREE
{1}
1.CAT
2.DOG
{2}
1.CAT
{3}
1.DOG
2.TREE
{3}
1.DOG
{4}
1.TREE
{5}
1.CAT
2.TREE
Can cross reference be used to produce a tree like this?
Tags:
Yes it is possible, but convoluted and inefficient:
Convoluted because obvious, inefficient because on your way to the answer you end up calculating ALL possible combinations, which is a much larger set.
The general idea being:
Oops, forgot to attach the file.
Thanks David. This next question might shed too much light on my lacking math skills, but let's say I'm dealing with a much larger set of words and the number of permutations is less obvious. What is the formula for calculating the number of possible pemutations. I know the basic formala is n^r. But in the case the formula needs to be solved with r=n... r=1. Something tells me this is obvious and I'm not seeing it...
Yes I can see now how this can be a inefficient way to solve this problem. It seems like when dealing with 12 source words the number of possible permutations is too high for grasshopper to handle.
Yup, it blows up pretty damn quick.
It is fun thinking about this. I came up with an algorithm which is reasonably efficient, though not particularly elegant. It sometimes generates duplicate entries so it must deal with those which costs additional processor cycles.
It generates an index map which can then be used to retrieve the actual items. Code is heavily annotated, but pretty thorny nonetheless.
The basic idea is that you start with a complete pattern containing all elements, then you recursively remove elements from that pattern, generating all the patterns that are one item shorter. Then you recursively remove individual elements from this new list of shorter patterns to create shorter patterns still. Repeat until the pattern length drops below 1.
The problem is that if you first remove 'B' from 'A,B,C,D' and then remove 'D', you end up with the same pattern as when you first remove 'D' and then 'B'. So these cases need to be tested. I'm sure there's some clever looping that just does the right thing, but I couldn't think of it.
Like this?
Thanks Peter this definitely works except for one minor thing. In my specific case order does not matter. It seems your script has the added bonus of finding the permutations when order does matter which, in my case, results in duplicate branches.
http://www.grasshopper3d.com/forum/topics/permutations-vs-combinations
my 5th virsion (latest post) is the fastest as it uses anemone fast loop
but Anders version with python is very good
but its good example because in the beginning it also show you how many possible permutations/combinations even for higher values without producing the results
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by