Evolutionary Computing with GH and Galapagos

By Dan Raznick (razni001@umn.edu) for Grasshopper v. 0.8

Other Helpful links:

http://www.grasshopper3d.com/group/galapagos?xg_source=msg_wel_group

http://www.youtube.com/watch?v=kvySEV09cr0&feature=plcp

http://www.youtube.com/watch?v=LP7L_36aNgQ

Introduction to Galapagos from grasshopper3d.com:

The term "Evolutionary Computing" may very well be widely known at this point in time, but they are still very much a programmers tool. 'By programmers for programmers' if you will. The applications out there that apply evolutionary logic are either aimed at solving specific problems, or they are generic libraries that allow other programmers to piggyback along. It is my hope that Galapagos will provide a generic platform for the application of Evolutionary Algorithms to be used on a wide variety of problems by non-programmers.

Galapagos is a component that has incredible potential as a design tool. Thus far, the surface has only been scratched. This page will contain a collection of introduction tutorials, as well as examples of how Galapagos is being used in computational design. The focus here will be how to build upon the foundations of evolutionary computation capabilities to move from optimized design to actually designing the optimization.

TUTORIAL 1: Find the Closest Point on a Curve

First lets take a look a simple definition that demonstrates how Galapagos works. We will begin with a curve drawn through three points, a point in space, and a function the calculates the distance between the two. Galapagos will use the variable we set to determine the optimal point that is closest to the curve. This tutorial will go at a very slow pace, step by step, to build the definition. The tutorials to follow will involve more complex definitions, and thus will be geared toward more experienced GH users. Even if this is your first time ever opening Grasshopper, you should be able to follow Tutorial 1.

Before we start, there are some basics of using the Galapagos component that are helpful to know as you build and organize your definition.

In the Params tab under Special you will find the Galapagos component. You can also double click the canvas and type 'gal' and it will show up. Drop Galapagos on your canvas and mouse over the inputs to see 'Genomes' and 'Fitness.' For now, let's assume that Genomes will always be a collection of sliders, and Fitness will always be a number derived from an equation established in your GH definition. Drop in a bunch of sliders on your canvas and connect the to the Genome input.

HA! See, it doesn't work. Galapagos is a special component, and you must drag the wire from Genomes to a slider, and the wire will point to slider, and not connect, unlike most other components. Since it is likely that you will be using several sliders as Genomes, the best way to connect multiple sliders it to select them, then right click on 'Geno...' and chose 'selected sliders.' A number component needs to be connected in the same way to the fitness input by dragging the wire from fitness to the number.

It is also worth noting that the organization of your definition is crucial to understanding how to use Galapagos. For now, we will assume that our definitions to be used with Galapagos will be organized in three general groups.

1: Input Parameters - the components that control the geometry modeled in Rhino

2: Geometry - the only part of the definition that actually draws something in Rhino

3: Fitness Equation - components that solve a particular equation based on your geomet resulting in a single number component that is connected to the Fitness input on Galapagos

OK, Now let's get started from scratch.

Step 1: Draw a curve with three points.

Double click on your canvas and type "md" and select an MD Slider:

Double on the MD Slider and set the X and Y Domain to -10.0 to 10.0.

Next, copy and paste the MD Slider twice so you have three total. Then you can use a point component to see how the MD Sliders plot points in Rhino. Drag the white circle in the MD Slider around to move the point in Rhino:

Now either double click on the canvas and type interpolate curve, or select Interpolate Curve from the Curve tab under Spline. Interpolate Curve draws a spline between vertices you plug into V. We will use the vertices plotted by the MD Slider:

Now you can start to see how the organization is beginning to work. The MD Sliders are Input Parameters, the do not draw anything in Rhino. The Points and Interpolate Curve are pieces of Geometry, and are visible in Rhino, and controlled by the Input Parameters. THe following steps will build upon each of these groups, and then we will establish a Fitness Equation.

Step 2: Plot a point on the curve and a single point in space that will be moved by Galapagos.

Since the goal of the definition is to determine the closest point on a curve we will need a point in space and a point on the curve in order to have two pieces of geometry that a singe distance can be calculated from.

Lets start with the point in space. Double click on the canvas and type 'point xyz' and select Point XYZ. Next, drop in a slider and double click on the part that says 'Slider' to change the min and max to -10 and 10. Copy and paste the slider so you have two, then hook one up to X and one up to Y on the Point XYZ. Move the sliders around to see the point move in Rhino. Since the sliders themselves to not draw anything in Rhino, but they are used to control the Point XYZ, organize your definition so the sliders are grouped with the MD sliders (since they are also input parameters) and arrange the Point XYZ with the Interpolate Curve (since it is also geometry):

**hint: you can group any components by selecting the and typing ctrl+G. You can add text in various ways, but I used 'Scribble' in the Params tab under Special.

Now lets add the point on the curve. To do this we will use a 'Curve Closest Point' component which uses a point in space and a curve as inputs, and draws a point on the curve that is closest to the point in space. Double click on the canvas and type curve cp and select 'Curve CP.' Then drag the Point XYZ into the P on CrvCP (for point) and drag the C from the IntCrv in to C on CrvCP (for curve):

Drag the sliders to change their values to see how all of the components work together.

Step 3: Creating a Fitness Equation

As described in the beginning of this tutorial, the fitness equation is what is plugged into Fitness on Galapagos. The fitness equation establishes the criteria for which Galapagos will optimize. Since we want to optimize the distance from the point to the curve so it is as small as possible, we will need a distance component which calculates the distance between two inputs, A and B. Our inputs are the CrvCP and the Point XYZ. We use the CurveCP because it a single coordinate on an XYZ plane that generates a single value that can be used calculate a distance to another point. (Which is why we CAN NOT just plug the curve in. Use 'Panels' to see what data each component outputs). Double click the canvas and type 'dist' and select the Distance component. Plug the inputs in and plug the output distance into an empty number component so it can then be connected to Galapagos.

Now drop in a Galapagos component and drag the Fitness wire into the number generated by the distance component. Since it is the XYZ Point in space that we want to move to find the closest distance to the curve, we will need to find the input parameters that control th point, which are the two sliders. Select only the sliders connected to the Point XYZ and right click on Genome on Galapagos and choose 'selected sliders.' Right click and un-preview everything except the IntCrv and Point XYZ.

Hooray!! Now our definition is ready to be optimized!!!!!!!!!!!!!

Step 4: Galapagos

Double click the Galapagos component, and you will see the Galapagos window show up. On the first tab, the only setting we need to change at this point is setting fitness to MINIMIZE, since we want the smallest distance to the curve. We won't worry about the other setting in this tutorial.

Next, select the tab 'Solvers' and click start solver. You will want to pan over your definition to watch the sliders change, and the point in Rhino move, as Galapagos runs through combinations and evaluates them at a super ridiculous speed. Let the solver run until it is complete. You will know when the solver is finished when the OK button at the bottom is no longer gray, the Stop Solver button is inactive, and the simulation is no longer moving. Once it is complete, the data is available for analysis. Let's take a look at what we have.

Hopefully this introduces the incredible power and potential of Galapagos in optimization. The solver takes a fixed sample size of combinations the Genomes (sliders) produce, and it chose only the Genomes that best fit the criteria set in the fitness. These were then continued into the next generation to compete with a new sample of Genomes, which have been improved to better fit the fitness criteria because the solver was able to analyze and order the combinations and results from the previous generation. This process is repeated until all combinations are tested. The evolution from generation to generation weeded out the samples until the optimal solution was found(Like in the theory of evolution, only the strong survive). Frequently, running the solver again will generate a different optimized results depending mainly on the start point of the Genomes. Is it artificial intelligence? No, not really. Evolutionary computing has been around since the 1960s, but now we can intuitively control the parameters associated with our designs to test variations using a method that was once reserved only for programmers and computer scientists.

Here is a great video that starts with this tutorial and does more complex definitions that build on various ways to use Galapagos:

LINK TO VIDEO TUTORIAL:

http://www.youtube.com/watch?v=TGVwz4c6ieY