# Genetics algorithm

#1

Hello,
I am trying to calculate the best rotation of the tower that has better views. To every floor plan I draw a line that intersect with the next building. the length of the line views change if we rotate the tower more or less.
To determine the fittest rotation we need to try many rotations and then get the rotation that gives us the longest line view sum.
I tried Optimo but I am not happy about. I am trying now with a simple code, but unfortunately I have no experience with programming and I can not solve it. Maybe someone with better knowledge in Code blocks could help me out.
So far i defined a definition that creates random values for the rotation values, and I need now another definition that take the sum values of the âviewlinesâ and get the longest and related it to the value of the rotation. With an amount of iterations we will be close to the fittest rotation :).Turm_genetics algorithms.dyn (46.1 KB)

#2

You may want to try using project fractal for this exercise instead of trying to look at all rotations yourself and looking at the âbest viewing distanceâ as the best viewing distance may not be the best tower (best view but worst form or too much unusable space). It will also likely be much faster to run as it uses the cloud rather than your CPU (youâre doing something like 4010**4360 tests here, if not more).

https://home.fractal.live

#3

Thanks Jacob, I already contacted the Fractal group, but the fact it is that I want to learn to code myself. Yes, the best rotation might not be the one that offers better usable spaces, but if I learn to code, I will add this variable, and many others too. Anyhow, I am giving a try to Fractal, cause it looks really cool!

#4

Thatâs a hell of a challenge if youâve never done any programming! You might want to try something a little less complicated for now. Youâre asking for some pretty heavy computational lifting.

You could try to adapt the course on ThinkParametric â
https://thinkparametric.com/courses/view-optimization-using-galapagos-for-grasshopper â to Dynamo and Optimo.

#5

Thaks Greg!! Yes I know the example of Galapagos, pretty much is the same example that I copied with the intention of learning programming in Dynamo ;). But thanks for the website, I might visit some courses there :).

#6

I tried assembling a little Optimo script for you. It seems to work on my part. Havenât gone through in detail, and should probably be washed so that it doesnât create all the geometry each run, but it didnât consume my computer at allâŚ
Anyway:

To use the results, you will have to pick a value from the last codeblock. List [0] contains the rotations, List[1] contains the Fitness. Optimo sorts so that the best fitness is at the top of the list. (as long as the population size/ number of loops is enough for not hitting a local optimum)

The âcustom nodeâ aka your script:

Mind that Optimo, unlike Galapagos, can ONLY minimize values, that means that in your case you have to add a negative to the Fitness.

#7

oh great!! I tried with Optimo but i didnât succeed. Thanks a lot!!