Galapagos Evolutionary Solver in Grasshopper
What is Galapagos?
Galapagos is a tool that searches a parameter space to find designs
that optimize a "fitness" function. The parameter space is defined by
a set of sliders, and the fitness function is some code that produces
a numeric value that Galapagos tries to maximize. (It can also be
told to minimize the function, in which case "fitness" might be
renamed "loss" or "error".)
Blog posts introducing Galapagos.
Side Note: Drawing Samples from a Gaussian Distribution
Grasshopper's Random component samples from a Uniform distribution.
This article
explains how to sample from a Gaussian distribution if you have access
to a Uniform distribution:
- u1, u2 ← Uniform(0,1)
- R = sqrt(-2 log u1)
- θ = 2 π u2
- (x,y) = R cos(θ), R sin(θ)
Build this computation in Grasshopper using the Random and Expression components.
The Searchlight Problem
- Create four 1.00 < 50 < 150 sliders.
- Feed all four sliders into a number parameter.
- Feed the number parameter into the X input of a Construct Point component.
- Create a 0 < 21 < 40 slider and feed it into the Z input of the Construct Point component.
- Feed the output of Construct Point into the O input of a Construct Plane component.
- Feed the output of Construct Plane into the B input of a Cone component.
- Feed the output of the Z coordinate slider into the R input of the Cone component and set the R input
to compute the expression x/3.
- Also feed the output of the Z coordinate slider into the L input of the Cone component and set the L input
to compute the expression -x.
- Feed the output of the Cone component into a Cap Holes component.
- Create a 1 < 50 < 200 slider and feed it into the S input of a Series component.
- Create a 1 < 3 < 8 slider and feed it into the C input of the Series component.
- Set the N input of the Series component to 0.
- Create two Random components and set their seeds (S input) to 1 and 2.
- Connect the output of the Series component to the N inputs of both Random components.
- Feed the output of the first Random component into an Expression component with the expression sqrt(-2*log(x)).
- Feed the output of the second Random component into an Expression component with the expression 2*π*x.
- Feed the output of the second expression component into a Cosine component.
- Create a Multiply component and set its A input to the first
Expression and its B input to the output of the Cosine component.
- The output of the Multiply is a list of numbers drawn from a Gaussian distribution.
- Create a Panel and set its contents to the values 10, 75, and 125.
- Create an Expression component with the expression x+10*y.
- Feed the panel into the X input of the expression and graft the X input.
- Feed the random gaussians into the Y input of the expression.
- Flatten the output of the Expression.
- Feed the flattened output into the X input of a Construct Point component.
- Also feed the flattened output into a List Length component.
- Feed the output of the List Length component into the N input of a Random component.
- Create a Panel with the contents "10 to 18".
- Feed the panel into the R input of the Random component.
- Feed the output of the Random component into the Z input of Construct Point.
- These are our target points.
- Create a Point in Brep component.
- Connect the output of Cap Holes to the B input of Point in Brep.
- Connect the output of Construct Point (the target points) to the P input of Point in Brep, and graft this input.
- Feed the output of Point In Brep into a Mass Addition
component. This counts the number of cones that each point is
inside of. (Can be more than one if cones overlap.)
- Flatten the output of Mass Addition and feed it into the A input of a Larger Than component. Leave the B input at 0.
- Feed the ">" output of Larger Than into a Mass Addition
component. This counts the total number of target points captured by any cone.
- Feed the target points into the L input of a Dispatch component.
- Connect the ">" output of Larger Than to the P input of Dispatch.
- Connect the A output of Dispatch to a Point parameter. This lets us see the captured points.
- Turn off Preview on the Dispatch component.
- Insert a Galapagos component.
- Connect the Genome input of Galapagos to the four number sliders.
- Connect the Fitness input of Galapagos to the output of the last Mass Addition component.
- Double click on the Galapagos component, go to Solvers, click
on the first dial to display all variants, and click on the Start
Solver button.
- Stop the solver when the fitness asymptotes.
Galapagos documentation in blog posts
When you double click on Galapagos, in the Options tab are links to the blog posts that
serve as documentation and a tutorial.
The Revolved Surface Problem
You can use a Gene Pool component in place of individual sliders.
|