Ladybug Optimization using Galapagos
Contents
Introduction
Expected Time: 60 min
Part 1: Geometry Welcome to the tutorial on Single Criterion Optimization using Galapagos, a plug in for Grasshopper which is written by David Rutten. For the design problem, we are imagining the following scenario you're tasked to design the roof of a courtyard in which you will need to place openings. These openings should be placed maximize the direct light shining on the terrace below. In the following chapters we will discuss a method to optimize the location of the openings.
Part 2: Move Openings Now that we have our geometry linked, we will want to duplicate the opening geometry so that we can have multiple openings in our roof. I'm going to move the opening components down below. Use the stack data component to duplicate the geometry. The data which will be coming in will be connected to the surfaces and we will want to stack it three times to get three openings. Press forward slash twice followed by the number three and then enter to get the number three in a panel and connect that to the stack. Now if we connect a panel to the output what we can see is that there are three surfaces which right now are all in the same place. What we will do later is move them to different places along the roof.
Part 3: Gene Pool In Galapagos, the way to adjust variables is with the component called Gene Pool. The Gene Pool works similar to a number slider except that Galapagos will have control over these sliders. Double clicking the component to adjust the settings. Set the gene count to six, the decimal place to zero. Set the minimum value to zero because the opening is located at the edge of the roof. The maximum is the maximum distance that the opening should move to reach the other side of the roof. That value is the width of the roof minus the width of the panel which in our case is 1600.
Part 4: Roof Openings Now that we have the location of our openings, what we're going to need to do is cut our roof with these openings so that we can get our final roof geometry. Use the deconstruct be rep component and plug in our opening geometry. This allows us to extract the edges of the geometry. Then will use the project component to project the edges which are curves onto our Brep, which is our roof surface. Because the edges come in with the edges in separate branches, we also want to make sure to flatten the curves that come out of this projection. Use the surface split component in order to cut the roof surface with the opening curve.
Part 5: Sunlight For the analysis, we need to measure the fitness of our design decisions and show where the best location for the openings in the roof are. We will be using Ladybug to understand the amount of sunlight that comes through the openings to the deck below. Briefly, we'll go through the Ladybug setup, but please reference the TOIPedia article about using Ladybug with Galapagos for more detailed information.
Part 6: Optimization Now we can run our analysis with Galapagos. To do that, place the Galapagos component. What's unique about this component is that the wires will be connected backwards. What I mean is that you have to connect wires from the Galapagos component to other components even though it is an input into the Galapagos component. Connect fitness to the value from out Ladybug analysis, the result of our mass addition. Connect Genome to the Gene Pool, which controls the position of the openings.
Another example on how to do a sunlight optimization using Ladybug in combination with Galapagos
In this tutorial we will give a similar example on how to do a sunlight optimization using Ladybug in combination with Galapagos. Ladybug is a set of tools that allows a Grasshopper user to do a sunlight analysis on a model. This analysis can be taken over a longer period of time, based on a real world location. Galapagos is a an evolutionary solver that can optimize one Fitness values, based on multiple parameters. An extensive review on all available options in Galapagos can be found in Tutorial 22 - Galapagos Optimization. More information about Ladybug is available in Ladybug Light Analysis.
To explain you how to use Galapagos and Ladybug, we will use the following scenario: you have created a Rhino environment with multiple canopies. These canopies protect the visitors of your building from the sun. Now we want to place a terrace on a location that gets the most sunlight on average during the summer season. If you do not have the Ladybug Sunlight Analysis Grasshopper file, please download it here:
- Download Ladybug Sunlight Analysis: Ladybug Sunlight Script
Remember to Credit the Author when using this script for your projects!
Create the Rhino environment
For the first step, you will need to create a Rhino environment. Also create a surface that has the right shape for the terrace. Place this terrace in the center of your environment. It is recommended to use a surface, not a 3d geometry.
- Create a Rhino environment
- Place a terrace surface in the center of the environment
Setting up the Ladybug Analysis
Open the Ladybug Sun Analysis Grasshopper file. Specify the correct location in the script. Set the terrace in the “Geometry to calculate” node, and the surroundings in the “Context Geometry” node.
- Specify the location
- Add the surface to the Geometry to calculate node
- Add the context geometry to the Context Geometry node
Now we need to specify the period we want to analyze. Since Galapagos optimizations can take a while, we start with the analysis of 12:00 on the 21th of July.
- Set the period to 12:00 on the 21th of July
Check if the Ladybug Analysis works by setting the Run Boolean to True. If you only see one colored square, try to decrease the grid size of your Ladybug Analysis. If you only see the original surface, try to hide the terrace in Rhino.
- Run the analysis
Since we now know that the analysis is working, we can continue building the Galapagos script.
Move and rotate the terrace
As you can imagine, we will need to optimize a specific value: the total amount of sunlight on the terrace. In optimization terms, this is also called the Fitness value. This value can be found in the last panel of the Ladybug Sun Analysis script.
In the next step, we will need make sure that our Grasshopper script is able to move and rotate our terrace. This can be easily done by using the following script. Replicate the following script.
- Replicate the following script:
Now connect the Rhino terrace surface to the Geometry Parameter.
- Set the terrace surface to the Geometry Parameter
In standard Grasshopper scripts, the minimum and maximum of a Number Slider does not really matter. However, when we are optimizing using Galapagos, we need to make sure that the Number Sliders only contain values that are acceptable. Therefore you should try to find a reasonable x domain and y domain for the terrace to move. In our case, the terrace should always be within the hole in the ground. However, if it intersects with one of the walls, it does not really matter.
- Find a reasonable domain in x and y direction for the surface to move
- Find a reasonable domain for rotation
- Set the Number Sliders to the correct values
In this example
- The terrace can move from -5000 mm to 4000 mm in x-direction
- The terrace can move from -15000 mm to 5000 mm in y-direction
- The terrace may rotate from 0 to 359 degrees
Finally we need to connect the output to the “Surface to calculate” geometry node, since this is the location of the terrace.
- Connect the outputted surface to the Ladybug script
Galapagos Optimization
Now we are ready to setup the Galapagos optimization. Add a Galapagos node to the canvas.
- Add a Galapagos node to the canvas
Connect the Fitness input to the total amount of sunlight hours value. This works different than a normal Grasshopper node. You should drag the wire from the Galapagos node to the value.
- Assign a Fitness value
Now connect the movement and rotation parameters to the Genome input, similar to the Fitness value, holding shift.
- Assign the Genome parameters
The script is now ready for optimization.
Run the optimization
Before continuing, please save your Grasshopper file. Double-click on the Galapagos node to open the Galapagos Editor. An extensive review on all available settings can be found in Tutorial 22 - Galapagos Optimization For now, only set enable the Runtime Limit and set it to two minutes.
- Save your file
- Open the Galapagos Editor
- Set the Runtime Limit to two minutes
Now click on Solvers. For your first experience, you can turn on the display of all genomes.
- Click on Solvers
- Turn on the display of all genomes
Click on Start Solver. You will now see that Grasshopper starts to optimize the location of your terrace. After two minutes, the optimization stops. If the solver doesn't stop, click on "Stop Solver".
- Click on Start Solver
In the following image, you can see that Galapagos has found a best result that has 285 sun hours, spread over the grid on the terrace.
If you want to see other results, select a specific genome in the bottom right menu, and click on reinstate.
You can now close the solver. As you can see, the Number Sliders are adjusted to the optimized location of your terrace.
Intensive optimization
Although Galapagos has now found the optimized result for a Ladybug Analysis of one hour, we want to get the result over the whole summer period. This simulation may take way longer though. Set the _hoy input to a period from 21th of June to 21th of September. For each option, Galapagos will now calculate 91 days * 24 hours. This will take a considerable longer time to calculate.
- Set the _hoys period to 21th of June to 21th of September
Run the Galapagos optimization again and use you preferred option as final result.
- Run the Galapagos optimization again
Since Ladybug now calculates the amount of sunlight over a longer period, Galapagos will now find a way better location for the terrace on average.
Download file
Here you can download the final Ladybug Analysis script, including the Galapagos optimization script. Remember to always credit the author if you are using this for your own work.
- Download the Galapagos Optimization file: Ladybug Galapagos Sun Optimization
Remember to Credit the Author when using this script for your projects!