Grasshopper

algorithmic modeling for Rhino

Hi everyone,

I've been stuck for a while on a problem, and can't for the life of me figure out how to solve it! I think this is one for VB/C#, but happy to hear of any method.

So the thing is I am cycling through many (many, many) solutions, and am only interested in keeping the best 'X' number of them (say the top 100). In my case, a lower number is a better solution.

Since there are so many, I can't just use a Data Recorder to log them all, sort them and pick the top 100, because it would eventually be too long a list.

My idea is to log only the first 100 values that come in, and after that, only record a value if it is better (lower) than the worst (highest) value in the current log.

By "trapping" the better values as they come in, I will generate a list which slowly improves with time, while never having a super-heavy component.

Since this is a recursive function (one has to know things about the recorder before deciding whether to record or not), I have tried using Anemone, but it hasn't worked... (see image)

I would be really grateful if anyone could help me with this one, I'm stumped!

Cheers,

john

Edit:

If it's any help, in my research I have found these two other discussions about data recorders:

http://www.grasshopper3d.com/forum/topics/data-recorder-reset

http://www.grasshopper3d.com/forum/topics/data-recorder-with-boolea...

Views: 4733

Attachments:

Replies to This Discussion

The largest value? The largest value of the first N values you mean? Or has the plan changed?


    If x > lrg Then
      lrg = x
    End If

    A = lrg

 

  '<Custom additional code>

  Dim lrg As Int32 = Int32.MinValue

  '</Custom additional code>

So by declaring the variable with the rest of the code, am I resetting it each time? Will try it when I get home.

And yes, I wanted to record the largest so I could turn an out-of-the-box Grasshopper recorder on or off. But got stuck on the first step!

Thanks,

john

True

So it looks like I got lucky this time! Some desperate googling found me exactly what I needed...

http://dap3.nl/simple-data-recorders-in-grasshopper-updated

No learning done, but oh well, it works! Thanks for all the help Pieter (oh by the way, your code worked, but I still needed to keep the paths separate)

You have learned to google better maybe:) Quite important too! (Even more so since noone bothers to add some relevant Tags to their discussions anymore)

Can you please show us how you got this DAP3-component to record only values lower than the maximum value from the first N values? Hooking it up to your DataToRecordSimulatorfile with N= 5 or so will do.

Hmm I spoke too soon... I have attached what I thought would work, turns out it doesn't...

the idea was that I recorded the worst 'X' to go through, as well as how many 'X' had gone through - Turn this into a logic rule (always write to recorder, unless it is full and the current number is worse than what is already there), and use a stream filter to let the 'X' through only if the logic lets the data through.

I think that is working fine, the problem is that the data recorder isn't sorted internally, so whenever I record a number, I am kicking out whatever is at index 0, which might be a good value!

Back to the drawing board... argh!

Attachments:

Hi Tom, I'll explain in more detail:

This is a definition to lay out residential blocks automatically, and this problem in particular is intended to find good combinations of flats to fit into a given floorplate (say, 9 studios, 6 x 1-beds, 7 x 2-beds...).

My input is a text file which contains all possible combinations of unit types, up to a given size (basically, all the possible unit combinations up to a floorplate of 'x' square metres). The idea to save them into a text file was because of the sheer amount of combinations there were (33M), which took three days to compute but hopefully I can now use for a variety of projects (because the unit types don't change generally between projects, just the unit mixes).

Anyway, that's a small tangent. The point is I am reading through this index, finding good combinations for one project in particular ('good' being that it fits in the floorplate, with a decent floorplate efficiency).

The issue is that most of the log file isn't appropriate, only a very small percentage of combinations in the index are good for each floorplate (where each floorplate is represented by a separate path, by the way), hence me wanting to record only the best. I guess that is an optimisation, but I can't think of a better way of 'tunneling' through to a solution, to use your analogy. More than open to ideas, by the way!

The truth is I feel I am very close, if only I could code. In one hand I have the data recorder which sorts and keeps good values (Pieter's script), and in the other I have this one which keeps the paths separate....

Hi Tom thanks for this - truth is, I already have a parser working, feeding the file sequentially to avoid overloading my computer, and feeding into the recorder (which is what I'm stuck on).

I know it sounds like overkill to save all possible combinations, but the idea is to do that massive calculation only once, and keep it stored for the future. In residential blocks the unit types usually stay the same size, so the same text file can be used for many projects.

What does change is the floorplate, so the idea is to search through the text file and record only the combinations that apply to each one (and only the good ones, hence my question).

I appreciate what you say about fitness functions, but I don't think this is one for Galapagos anyway - the fitness landscape isn't regular - there are no "peaks" to climb, to reference David's analogy. It might come in later, when I am weighing different variables (as you say, closeness to a square, but also area, sun exposure... blah blah), but at the moment this is just to fit flats onto a floorplate.

This has been bugging me all weekend as one of those "surely there must be a simple solution!.. somewhere.." whelp, here's try #2 for me:

Uses the Human Plugin (gh group)


Basic logic:
convert all values to points
continuously bake to rhino.space (data structure > layers)
*loop start
geometry pipeline pipes points back in to GH
points sorted, everything except best 100 shifted to a different layer
unwanted points deleted, only 100 best (in each layer) is kept (in rhino.space)
*loop back, geometry pipeline picking up the best 100 plus new values

tl;dr Basically uses geometry pipeline to enact a loop and rhino.space acts as a global point array to hold the best 100 values of each stream

Issues:
-all streams must be manually initialized first (layer creation mainly)
-relies on tricks to make parts of the definition act sequentially as opposed to parallel (and crash and/or weirdness), might have missed some? something to be wary of when editing.
-tree input still iffy.. all inputs duplicate when an input updates.. so if non-updating inputs are empty when the input(s) update, should technically work?.. to my limited testing anyways.. problem is that I haven't yet figured a mechanism to ensure this.. :(


Hope this iteration finally gets you to the final solution *fingers crossed*

Attachments:

Hi! Thanks for this, it's definitely out of the box! Basically using Human as a way of creating the recursion... will give it a bash, I can't get it to work at the moment but I get the intention

Fingers crossed!

(And I know, right? Surely there must be a simple solution!)

Tom,

I'm not combining flat dimensions, perhaps I should have explained better. I am doing combinations of types of flats:

3 Studios

6 1-beds

9 2-beds

2 3-beds

....

and storing that combination with how much space that combination would take (according to London Design Guidelines). So for the example above, a 3/6/9/2 combination takes up 1219 square metres.

It's true I am storing very weird combinations of units (35/0/0/0 for example, a residential block made only of studios...), but a priori I don't know if it might come in handy one day!

Once I have that calculation done, which doesn't apply to any specific project, I "evaluate" it for a specific project. I have various floorplates of different sizes, so I go through my index looking for good matches (those which are close enough in area) - and here is where I need a recorder, but one that traps only the good results, and only gets better as it reads through the file.

After that, I lay the units onto the floorplate and evaluate how good the solutions I have found are (the usual suspects; orientation, sun exposure, cross-ventilation, etc.). I might need Galapagos for this, but the fact remains I need to cull a huge pool of 33M possible combinations into (say) 100. Hence my need for a recorder.

It would be great to read your thesis actually! If you would be so kind as to share, always looking for different ways of approaching the solution.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service