algorithmic modeling for Rhino
Hello all,
Recently I worked to make all possible combinations of data from each path in GH.
Let's say that I have multiple paths(trees) and each path has a different numbers of items. I selected an item from each path, and then made new paths(trees) with selected items. But, the result should be data trees of all possible combinations.
I knew that the [Cross Reference] can do this job. But when the numbers of paths(trees) change, I had to re-match the output of [Explode Tree] manually.
I think about some solution for this issue. And I made the definition as the attached image below. But still I want to know if there is another solution for this (e.g. some plug-in or much simpler components).
Thanks!
Tags:
I had some help from this blog. Here's a script that should do what you're asking:
private void RunScript(DataTree<object> data, ref object A)
{
var cp = CartesianProduct<object>(data.Branches);
DataTree<object> results = new DataTree<object>();
int counter = 0;
foreach(IEnumerable<object> branch in cp){
results.AddRange(branch, new GH_Path(new[]{0,counter}));
counter++;
}
A = results;
}
// <Custom additional code>
static IEnumerable<IEnumerable<T>> CartesianProduct<T>
(IEnumerable<IEnumerable<T>> sequences)
{
IEnumerable<IEnumerable<T>> emptyProduct =
new[] { Enumerable.Empty<T>() };
return sequences.Aggregate(
emptyProduct,
(accumulator, sequence) =>
from accseq in accumulator
from item in sequence
select accseq.Concat(new[] {item}));
}
Hello Andrew,
Sorry for my late reply, and thanks for your script!
I'm not good at making VB or C# component in GH. So your attached file helps me a lot.
I have another question. Now I want to make some combinations as upper strict or lower strict.
http://www.grasshopper3d.com/forum/topics/cross-reference-what-is-i...
Let's say that I have 20 lotto balls. And I'll choose 5 balls from them. How can I make all different combinations which have 5 items?
Really thanks for your work again.
Regards,
Hi,
I did few experiments with combinations and permutations,
https://naeimdesigntechnologies.wordpress.com/2016/12/23/permutatio...
you will find few examples (with files) in my discussions
regarding The cross reference thing, can you add the file
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
© 2024 Created by Scott Davidson. Powered by