Grasshopper

algorithmic modeling for Rhino

Hello everyone,

I am trying to sort two lists in the same order and I actually know how it should be done.

Let me still explain:

The first list for example does contain 10 list of points. Scond list does contain the total distances calculated for each list (10) of points. Now I want to sort the distances by their size and of course the lists of points shall get the same order after sorting the list of distances.

first list: list of points                                              second list: distances

(1,2,3), (4,0,6), (7,1,9)                                            45

(4,6,3), (9,3,6), (1,6,3)                                            34

after sorting:

(4,6,3), (9,3,6), (1,6,3)                                            34

(1,2,3), (4,0,6), (7,1,9)                                            45

to achieve that, I tried this:

RunGA rga = new RunGA();
List<Tuple<List<int>, DataTree<Point3d>>> handoverGeneration = RunGA.createGenerations(FitnessInt, handoverDatatree);

custom additional part:

public static List<Tuple<List<int>, DataTree<Point3d>>> createGenerations(List<int> firstFitness, DataTree<Point3d> firstGeneration)
{
List<Tuple<List<int>, DataTree<Point3d>>> tuple = new List<Tuple<List<int>, DataTree<Point3d>>>
{new Tuple<List<int>, DataTree<Point3d>>(firstFitness, firstGeneration)};

tuple.Sort(Comparer<Tuple<List<int>, DataTree<Point3d>>>.Default);

return tuple;

}

I actually think that it worked but on grasshopper you can just see that there is a list and not the content of it. I tried two versions of it: with datatree and with list of lists. to take a look at it you can see the Picture below.

Does anyone has any idea about how I can see the content of the list?

 

Views: 1942

Replies to This Discussion

Er ... hmm ... you are lost in (cyber) space I suspect, he he

See attached (finish it: left on purpose unfinished)

Attachments:

Well ... in general you should:

  • Use DataTrees IF you intent to stay solely within the GH bandwagon (not my case).
  • Avoid DataTrees if the opposite is valid and depending upon how much the GH is contributing to a "complete" solution of some sort ...  and/or you need some sort of code "portability" [whatever this means, if it means anything at all]. For instance Imagine doing AEC stuff under some BIM umbrella ... meaning working with a variety of apps (the prime violins) including occasionally GH.

Back to sorting matters: the ArraySort works obviously with Lists meaning that if Trees hold your data ... then another approach is required. I'll prepare soon an example (as GH "neutral" as possible) on that matter (that said: there's various other ways to sort things).

BTW: Of course one way (using ArraySort) is to obtain Lists from Trees (this maintains the object order) ... do the job ... and then back to Trees (this requires some sort of "connectivity" info so to speak).

In the mean time get this (also entry level) stuff that departs from ArraySort and does business with another way:

Random lines are made within a cube and stored in a Tree.

Random N of random Pts (Line.PointAt(t)) are made (per line) and also stored in a Tree where branch {?;0} contains these AND

branch {?;1} contains the same points but ... sorted (OrderBy: meaning LINQ) by their distance to some focus point. Of course there's the // PLINQ thingy available (but in this case [see Elapsed] it would be like killing a bazooka with a mosquito).

These branches are made at once (per parent branch) but ... well ... you get the gist I do hope.

Attachments:

Spend a minute or two on that Genetic thingy of yours:

Excellent (and slow) way either:

  • To kill a bazooka with a mosquito (best option > fire and forget)
  • Or to kill a mosquito with a bazooka (worst option > forget and fire).

In general: coding is a &@*&*@ business (BTW: I hate computers, .NET, .NOT and .WHATEVER ) already thus complexity for complexity's shake is a no-no. What are you going to do when some real-life project exists? Solve it with 2M lines of code instead of just ONE LINQ clause? (not to mention trad segmentation of data [oct trees and the likes] and doing // stuff: the future).

Exercise for you: Imagine a box full of pts plus 24.67 cats and 48.03 dogs > find clusters that contain planar points (within tolerance) , dogs who like cats and cats who hate dogs. Solve it with less that 1M lines (and win 34 cans of sardines - a stunning offer by the The Lord [Himself]).

Repeat with me: the best bunny is the simplest bunny (if it's the fastest as well ... blame the law of unintended consequences).

And well ... you may find this interesting (made for a friend some time ago):

We have N points as masters and N as slaves (that are a bit "away" from masters): we need to connect them 1:1 based on proximity. So it's a "sorting" issue (kinda).

In order to do that 5 ways (in the Name of Science, what else ?) are provided ranging from efficient to ultra stupid: see Elapsed.

Attachments:

And here's a small challenge for you:

See this on the left? It's a balloon filled with points. See that on the right? is another balloon also filled with points.

Find the nearest pair with (at least) 3 methods (smart, medium, only for idiots) and compare the Elapsed times.

If you provide more ways ... you'll win 12.56 cans of the finest sardines known to man (in pure mineral oil).

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service