Grasshopper

algorithmic modeling for Rhino

The best way to find a combination of input

Hi everyone, I'd need your help for a combination issue that I would solve inside grasshopper (if possible). Maybe there's a plugin that makes this task easier...or maybe not.

*short version*

starting from a list of 12 items I would find all the combinations taking just 4 at time.

I'd use a Stream gate that takes the indexes of the items and pass them to a list item in order to select just the items of the combination. Doing so I can choose a single combination of index at time to pass to the list item.

In this moment all the data come out from the first gate, all the others are empty.

If I pass these index to the list item it gives me an error (probably because of the data structure).

*long version*

I start from a list of 12 segments, all of them with the starting point in common and the ending point distributed regularly in the space. It's a quite simple starting point.

What I'm trying to achieve is to find all the possible spatial configurations made of 2, 3, 4 segments. I started with 2 segments so I've 12^2=144 possible configurations but just 4 different configurations that can intuitivelly be recognized (60°, 90°, 120°, 180°).

Doing the same with 3 segments generates 12^3=1728 configurations and I don't know how many different ones. With 4 segments I've got 12^4=20736 possible configurations.

As you can imagine many configurations are identical but just with a different orientation so at the end I'll have to parse geometrically the output to delete duplicates (I'll address this later on).

Please could you help me to figure out how to mix these segments in different configurations?

Views: 393

Attachments:

Replies to This Discussion

Does this work?  More copy/paste than I like, there may be better ways to do it.

P.S.  The purple group eliminates the combinations where the same item is used twice.  So instead of 20736 combinations returned by 'CrossRef', only 11880 emerge from 'Dispatch'.

Attachments:

A slightly different configuration in how the combinations are "packaged" and presented:

Attachments:

The purple group eliminates the combinations where the same item is used twice.

On second thought...  There must still be many duplicate combinations where the same four items are in a different sequence?  I guess you did mention that.

Thank you so much Joseph! It works fine for me; I'm looking at the definition trying to understand what you've done but the most important parts are outhof reach for me at the moment :P
I would learn something from this like the use of Set or Entwin and Flip or the part inside the cluster...but it would take very long.

Yes there is a bit of redundancy but that's not an issue: among the various configurations most of them are identical, just with a different orientation. Because I'll need to filter them the redundancy given by a different order of the segments will be solved than.

Once again, Thank you!

I added the yellow group to earlier code (segmentscombination_2017Sep23d.gh) using 'Avr (Average)' of the end points as a "unique ID"- but is it really unique?  'MIndex (Set Member Index Example)' is used to trim the tree of "duplicate" combinations, using only the first one that "entered" the 'CSet'.  Only 133 unique combinations?!?

Using the mid-points of the four curves in each combination yields the same results, which isn't surprising, but it begs the question: what if each of the twelve base curves are a different length?

Easy to find out...  495 unique combinations instead of only 133!

Haven't tried to figure out why, or what the correct answer really is...?

Attachments:

Added cyan group to visualize the cloud of 495 "Unique ID Pts" with one yellow point corresponding to the path shown below the 'path idx' slider.

Attachments:

Easier to see - 'Pipe' the selected combination:

Attachments:

More visual aid - blue sphere around the yellow 'X', the "unique ID" point average of the end points:

Attachments:

Same code with a 'Permutation' slider added, 0 to 23, instead of just zero as before - to the 'Item i (Index)' input, dark blue group at top-right.  Renamed 'path_index' slider to 'Combination':

Attachments:

Added a 'Unitize' group/slider to make larger diameter, fixed-length 'Pipes' on the same curves.  The variable length lines are an abstraction, not in the original description, a convenience added to avoid "hashing collisions" of "unique ID points".  Use one or the other, or both.

Attachments:

A "weighted average" of those end points, really, because each was assigned a unique length.

Attachments:

The numbers from the model appear to be correct, according to this:

Combinations and Permutations Calculator
http://stattrek.com/online-calculator/combinations-permutations.aspx

• 12 sample points in set
• 4 sample points in each permutation = 11,880 permutations
• 4 sample points in each combination = 495 combinations

From the model itself, I had stumbled on the fact that each of the 495 "unique ID" points represents 24 (4 Factorial) different sequences of the four lines in each combination.  And 24 X 495 = 11,880.

Showing that was easy for two of the 495 "unique IDs": 0 and 494, but refinements are needed to see it better on the others.