# Generating all possibility

Hi again!, from the last topic (How to INTERSECT MULTIPLE OBJECTS in one time?) I have asked about how to intersect multiple objects at the same time. Thanks to @HS_Kim who solved my issue! Next step I would like to know are there any solution to intersect them in all possibility that possible. As you can from my attached screenshot, in TEST2 have created number slider input for the list index but that is only for one to another. As in the panel in the screenshot I have listed all the possibility (12), but still stugging to script it in the right way.

Cheers!

@HS_Kim has spoiled you by answering your previous thread without any file from you. Most of us can’t (or won’t) do that unless the question is much simpler. Creating your geometry and duplicating your code from scratch is asking too much.

3 Likes

You can use python to find all possibilities

lists.gh (19.3 KB)

1 Like

I agree with Joseph.
It’s a simple gesture: attach what you have so who try to help works on the real thing, not a “guess from a picture” that can be wrong, resulting in a waste of time.

… still… I ended up putting up something anyway.
To achieve the combinations a small gh algorithm or a Linq “one-liner” for the same result.
And a c# for-loop for the iterative solid intersection.

possibilities.gh (20.5 KB)

The number of combinations is c = 2^n , with n being the number of objects (or “switches”), in your case is 16, counting also the case of no solid selected.

1 Like

Hello @Joseph_Oster , first of all sorry if my post made you think in that way. Actually I think opposite, but I understand your point. That day was myfirst day here so… and also sorry if my explanation might be confusing. That’s why I attached an image together with some description to make it more clear what I want to archieve because I don’t know much terminologies to explain it and just want to have some idea to be able to understand the logic.

You will find the link to my file below for both 3dm. And gh… Please be so kind to have a look and I hope this could show how sincere I’m and I hope you will happy to give me advice.

210112_SS3.gh (17.7 KB) testFORgrasshopper.3dm (307.9 KB)

Sorry you don’t agree. Shall I skip posting my GH file to make the point more strongly?

I found 11 unique intersections:

``````1+2
1+3
1+4
1+2+3
1+2+4
1+3+4
1+2+3+4
2+3
2+4
2+3+4
3+4
``````

You listed 12 but I believe your list (below) has a duplicate: “1+4+2” is the same as “1+2+4”, eh?

``````1+2
1+2+3
1+2+4
1+2+3+4
1+3
1+3+4
1+4
1+4+2
2+3
2+3+4
2+4
3+4
``````

intersect_2021Jan14a.gh (54.5 KB)

1 Like

It’s so easy to not see the obvious until you step away from the keyboard…

This is slightly simpler (and more reliable?). Results are the same. Breps are internalized.

intersect_2021Jan14b.gh (55.5 KB)

1 Like

Combinations1234.gh (17.5 KB)
For 3 items, you just need the first Cross Reference, for 5 you will need another with four in/outputs, and so on.

1 Like

I wanted to vary the number of breps without rewiring the model so looked around and found this hint:

The CharSeq component is used in the orange group below. It gets REAL SLOW with more than five breps. I tried with seven which generates 961K combinations from 11 through 7777777 after culling (down from 1.65M sequences!!). The bottleneck is a Sort operation which takes 2.3 minutes, though total time is a bit longer to get 120 unique combinations.

Fortunately, it is much faster when the input is limited to 5 or fewer breps. I have a Data Dam to allow some fiddling with Jitter to choose a subset of eight possible breps.

intersect_2021Jan14d.gh (51.9 KB) .

1 Like

Hi everyone, I want to thank you for all of your help and advices. I will have a look and try to understand all the scripts here. Thank you so much. I’m very appreciate.

By the way last night I have try something a little bit straight forwards with Galapagos. So I try to see the result of all that possibilities in term of Form and Srf area they have been produce. So that I would like to share it with you. The script is still not complete and correct as my little beginner skill right now and even not reached that all possibilities I want to explore as I don’t know how to set Galapagos to generate all option possible, but I hope it is make sense enough to illustrate what I would like to experiment.

Thank you again for all your help.
@anon39580149 @maje90 @Joseph_Oster @Dani_Abalde

testFORgrasshopper.3dm (416.3 KB)
210115_SS__.gh (30.5 KB)

Galapagos does not work like that, it does not explore all possible solutions, it navigates in the space of solutions. It starts with a set of configurations, evaluates them, selects the best ones and slightly mutates and combine their configuration to continue exploring for better solutions, and so on until it stabilizes, so it does not have to go through all the solutions, just the better ones. And that’s why it’s a method of optimisation, because instead of going through all of them, it goes through the solution space in the direction of the most optimal ones. If you want to permute, Galapagos is not for you. It is only useful for you if you are looking for those solutions in the set of permutations that minimize or maximize some feature.

2 Likes

Disappointed with the slow performance of my last post, yet still wanting to avoid hard wiring of CrossRef, I looked into Python. Had to struggle with tuples and lists but it’s WAY BETTER!

Tested with up to eight breps, the only bottleneck now is Solid Intersection which took ~25 seconds to produce 247 results.

All the “magic” happens in the small orange and white groups. The cyan group co-locates all breps at the origin so they will intersect. The yellow group displays the results in a grid (with labels).

intersect_2021Jan15a.gh (47.4 KB)

Here is the Python code:

``````from itertools import combinations

idx_st = [str(i) for i in idx] #convert integers to strings

combos = []
for i in range(2,len(idx)+1):
comb = combinations(idx_st, i)
for c in list(comb):
combos.append("+".join(c))

C = combos``````
3 Likes

I realized later that my Python struggles with string join ( `"+".join(c)` ) and converting integers to strings could have been avoided using a ‘Type hint’ of ‘str’ instead of ‘int’. This also makes the code much more flexible since it will work with a list of characters or words as well as integers (or reals?).

This is a simple demo of the modified Combos Python component using characters:

Combos_2021Jan15a.gh (10.0 KB)

The slightly simplified Python:

``````from itertools import combinations

combos = []
for i in range(2,len(vals)+1):
comb = combinations(vals, i)
for c in list(comb):
combos.append("+".join(c))

C = combos
``````

And the revised Solid Intersection model:
intersect_2021Jan15b.gh (48.4 KB)