How to index value location in multiple lists?

unhandled

(Janis Goldmanis) #1

Hello!

I’m very new GH user, currently trying to solve the following problem for which I couldn’t find explanation anywhere, I hope someone can guide me in the right direction.

Lets imagine I have two sets of data -

List 1 is numbers ranging from 100 to 200, step 10
List 2 is reversed, numbers ranging from 200 to 100, step 10

I multiply the lists between them with cross reference, end result is, I get 11 lists, each with 11 results.
I’d like to find the next smallest value, that is larger than X, and find, which numbers multiplying causes it.

My current actions where -

I created a mapping list where each number is compared if it’s larger than X.
Afterwards I cull the list with every number that’s smaller.
After that I sort the list from smallest to largest value and I find the next smallest value that’s larger than X.

Now comes the problem, that I can’t understand how to index it in the first multiplying list to somehow find, from which numbers the value comes.

I have attached my GH example file.

List indexing.gh (11.8 KB)

Goal is to use this method, to find, for example, smallest necessary cross section to withstand force F, e.t.c.

Thank you for any help!


(Pfotiad0) #2

Well … I have already something that suits your quest.

List indexing_V1.gh (124.4 KB)

The good news are that the attached does what you want (2 conditions, 3 relation tree modes [see explanations for mode 1 inside]). In mode 1 it gives you a Tree kinda the ones that you get from connectivity type of Trees (what index in List A is connected/related with indices from List B).

The bad news are that is carried over not via components. Maybe I’ll translate tha def some time tomorrow.


(Andrew Heumann) #3

it’s not that hard to extend your existing definition to achieve what you’re after. The trick is finding a way to reproduce the data operations caused by grafting + reversing the inputs to the multiply component, and apply those same operations to the source list. The “longest list” component here comes in handy - the default list lacing behavior of all grasshopper components is longest list, so if you want to ‘mimic’ a component it’s your best bet. Then you can just apply the same list cull operation to the results, and get the source values where the product is greater than X.


List indexing-02.gh (29.0 KB)

In order to reproduce the operations from Create Set onwards, you have to get a little trickier.
Trick 1 is to use Assign Paths from Human/Tree Frog to assign the unique item index map to the list of source values, to structure them into lists by their product. Trick 2 is to sort the list concurrently by feeding into the “Values A” input of the Sort component - if you zoom into the component you can add additional list inputs to sort concurrently with the “Keys” list.


List indexing-03.gh (30.5 KB)

The last thing I might suggest is that, if you want to think of AxB as the same as BxA, you can avoid duplicate calculations by using the Cross Reference component set to “upper triangle” instead of graft + reverse in multiply. This is a special setting that works like this:

   A   B   C
A AxA BxA CxA
B     BxB CxB
C         CxC

effectively ignoring the redundant AxB, AxC, and BxC options. This may or may not make sense for your use case.
In this scenario the Cross Reference component also serves the purpose of generating the “map” of the original values, replacing longest list in the first example.


List indexing-04.gh (16.7 KB)

Hope this helps explain a few tactics for list management in grasshopper - it’s a complex topic and there are lots of “tricks” to add to your repertoire over time.


(Janis Goldmanis) #4

Thank you for help!

Andrew, your first example achieved what I needed. In my final definition I only did some additional culling, since I only want to see first result.

Though, this achieves what I wanted, I may have worded my question badly.
I have attached example definition with final result, how I imagined it (in yellow zone), but I have two steps missing that I have put in manually. (And nothing I try works to get these values in red boxes)

In the long term I intend to way complicate this definition with 4 pairs of multiplications e.t.c.
And I think with my intended definition in yellow, it would be easier to follow the logic.

List indexing-05.gh (16.2 KB)


(Andrew Heumann) #5

Try the attached. Using tree frog again (possible without but this saves a few components. )
List indexing-05.gh (18.6 KB)


(Andrew Heumann) #6

just a note on the user of text match; there are a number of ways to find items in a list. The three most common are Item Index, Member Index, and Find Similar Member, but none of these worked in this particular case - see Grasshopper Item Index Issue for details on the differences between these. In this case because you had already converted everything to string (by passing it into a text panel) a text match (Is this text the same as that text) was the best way to get a dispatch pattern of true/false values by which to extract the branch + index.


(Janis Goldmanis) #7

Thank you, this will be huge help going forwards!

Just one last question - your definition uses custom plugins - Wombat and HDTTreeUtils, I found Wombat, but I can’t find the other one. Closest that google shows me is HUMAN.gha, which doesn’t resolve the issue.

Because of it, I assume Branch path isn’t working.


(Andrew Heumann) #8

Ah, yes sorry that’s Tree Frog, included with Human (or just grab from here: TreeFrog.gha)