This week, we look at using Genetic Algorithms to solve geometric problems via Grasshopper’s built-in genetic algorithm engine, Galapagos. Genetic algorithms attempt to mimic the way lifeforms evolve over time, on the basis that if it’s good enough for creating all life as we know it, it’s probably a fairly good tool for helping us develop design solutions.
There are two main things to consider when we are setting up a grasshopper model to use Galapagos. The first are the input parameters that we are going to use as genomes. Each genome is a value that controls certain aspects of the design – the height of a wall, for instance, the width of a window, the number of columns etc. Galapagos will modify these values for us and attempt to find the ‘best’ solution. At present, galapagos can only do this through modifying sliders, which places a slight limitation on the way we set up the grasshopper definition because it means that everything we want it to be possible to change has to be controlled via a slider. We can still include other parameters (linked geometry, strings etc.) but galapagos will not be able to modify them for us. At each generation, grasshopper will fiddle (technical term) with these values and come up with a variety of different combinations. The best sets of values will pass on to the next generation (either directly or through ‘breeding’ with another value set) – the rest will be eliminated. The idea is that the population at each generation will become more and more suitable to the task at hand and hence you will be given ever improving solutions to whatever problem you are trying to solve.
The second, possibly more difficult part, is coming up with a way of assessing your model and turning that assessment into a single numerical value that you can use to express the ‘fitness’ of a given design, i.e. giving it a score based on how ‘good’ it is. This gets especially tricky if you need to consider more than one criteria that are not all of the same importance, since then you need to weight each criteria’s contribution to the final score. This is mathematically quite easy (you just need to multiply it by a certain factor) but determining what these weightings should be in order to give the best results can take a bit of trial and error. For some more on this I recommend this blog entry by the mighty David Rutten himself.
Indeed, if you’re thinking of using Galapagos you should probably leaf through the rest of David’s blog – he did write the thing, after all.
For my part, here are two annotated examples that use it:
The first (the idea for which I think I probably stole of of David anyway) uses galapagos to arrange a catenary so that it passes through (or at least, close to) a point, while (as a secondary consideration) minimising the length of the catenary.
Not breathtakingly useful, I know, but it should help to demonstrate the basics. Get it here: Example6a.ghx (Right click, save target as)
The next one does something a little bit cleverer. Given a certain set of points, we use metaballs (a form of implicit surface, although in grasshopper they only creates curves, which represent a 2D ‘slice’ through a metaball) to cover as many points as it can while also keeping the total covered area as small as possible. In this abstract form again this is probably not particularly useful but hopefully it is easy to see how it might be modified for use in masterplanning, for example.
Get it here: Example6b.ghx (Right click, save blahdy blah)
As an optimisation tool, genetic algorithms leave something to be desired. They need a large pool of test cases at each cycle and are highly random in the way that they work, meaning that they can take many many times longer than a more ‘straightforward’ optimisation routine would and may in the end not actually find the most optimum possible solution anyway. For this reason, they tend to fall onto the ‘often discussed, rarely used’ pile. However, they are also a lot more ‘creative’ – possibly throwing up solutions that you might never have considered otherwise. Given that we are all evolved creatures ourselves, it could be argued that all ‘designs’ are really the product of a genetic algorithm that has been running for several billion years.