Ladybug Optimization using Galapagos

From TOI-Pedia


Expected Time: 60 min
Ladybug optimization with Galapagos

In this tutorial you will learn 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.

The Rhino environment

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:

Remember to Credit the Author when using this script for your projects!

Create the Rhino environment

Our scene from top perspective

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

The Ladybug Sun Analysis script

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
  • Specify the location

Set the surface to analyze and the context
  • Add the surface to the Geometry to calculate node RMB on Geometry parameter » Set one surface
  • Add the context geometry to the Context Geometry node RMB on Geometry parameter » Set multiple surfaces

Specify the hour to analyze

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

A working Ladybug Sun Analysis

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 Double-click LMB on Run boolean

Since we now know that the analysis is working, we can continue building the Galapagos script.

Move and rotate the terrace

The fitness value to optimize

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:
Move and rotate the terrace

Set the surface to the input geometry parameter

Now connect the Rhino terrace surface to the Geometry Parameter.

  • Set the terrace surface to the Geometry Parameter RMB on Geometry parameter » Set one surface

Find the domains for x and y movement and rotation

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 RMB on Number Slider » Edit
  • Find a reasonable domain for rotation RMB on Number Slider » Edit
  • Set the Number Sliders to the correct values RMB on Number Slider » Edit

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

Combine the scripts

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

Add a Galapagos node

Now we are ready to setup the Galapagos optimization. Add a Galapagos node to the canvas.

  • Add a Galapagos node to the canvas Params » Util » Galapagos

Assign a Fitness value

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

Assign the gene Number Sliders

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

The Galapagos Editor

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 Double-click LBM on Galapagos node
  • Set the Runtime Limit to two minutes

Display all genomes

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

Run the Solver

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.

Select your preferred gene

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

Set the hoys_ to three months

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

The final optimized result

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.

Remember to Credit the Author when using this script for your projects!

Personal tools