# Idea for new generalised goal solution

If this feature already exists in the bouncy marsupial, please let me know. Otherwise consider it a suggestion for a new feature.

What occurred to me as being a useful goal is a simple component to minimise / maximise / target a value. The input to this component could be anything which generates a numerical result, such as distance between two points, the standard deviation of X coordinate values of the midpoint of several geometries, or anything else which might be output from the expression component.

The thought came to me when I was trying to create a solution where two points would stay a certain distance apart. I wasnâ€™t able to find a way of doing this which didnâ€™t involve creating a line between them and then setting a goal on the length of the line. But I didnâ€™t want a line to be there (and couldnâ€™t hide it). Then I thought a more abstract goal component could be applied to lots of situations.

I can imagine a goal component which takes one input function, a target value and a strength parameter which gives the priority of the deviation of the calculated result from the target.

I expect this process is what is happening under the bonnet in Kangaroo itself, and it would open up a lot of customisation.

Hi Ray,
Choosing which outputs to show can be done using the Entwine/Explode components and turning preview off for the objects you donâ€™t want to see by right clicking the components:

Itâ€™s an interesting thought of a generalised goal, but perhaps a bit of explanation of how Kangaroo works makes it clearer why this would be tricky.

For each goal, the code inside describes how to move the set of points it acts on in order to satisfy that goal (which can also be seen as projecting onto that constraint set, or zeroing that energy), a set of vectors which usually depends in some way on the positions of those points at that iteration.

For something like a length goal, finding these vectors is very easy - given the current length of the line, we can calculate how much shorter or longer it needs to get, and move the start point along the direction of the line by half this amount, and the end point by the opposite vector.

For some of the other goals finding these vectors gets much more complex though, and it isnâ€™t an automatic process. Even when the geometric property we are after is clearly described, the set of vectors we need to move the points by to satisfy this is sometimes far from obvious, and a big part of creating Kangaroo has been figuring out these calculations for all the different goals.

You donâ€™t actually always need to know how to calculate the vectors to exactly satisfy the goal in one step - if you do the goal will converge quicker, but as long as you can always calculate a set of vectors which reduces the error by some positive amount it should converge eventually.

If you have some new goal in mind, you can script it in C#/VB/Python if you know enough about the structure of the problem to describe how to calculate these vectors.

Something I have also thought about which should also be possible in theory would be to have a way to define a goal by wiring components together, without scripting - so youâ€™d create a sort of cluster with some points as input, and some vectors as output, and this cluster would get called with new inputs from inside the Kangaroo solver every time it was needed. Youâ€™d still need that understanding of the problem structure though.

Maybe you are thinking of something that would work more like how Galapagos does - where you can simply set the value to minimize, and the values it depends on, regardless of what calculations happen in between.
I have sometimes thought about a way to do this by testing the result of small changes to each of the inputs to estimate a gradient.

There are also various other plugins that have a setup similar to Galapagos, but use other methods for minimisation that are faster for many problem types - such as Goat and Octopus. You can even put a Kangaroo solver inside the optimisation loop of any of these.

Doing it the other way round (putting some kind of automatic gradient estimator inside Kangaroo to act like another goal) isnâ€™t currently possible, but could be interesting to think about more.

1 Like

Hey Daniel. The time and effort you expended on answering my question was gratefully appreciated.

The solution you gave to the specific question will be useful. There are still so many components in Grasshopper which I have yet to figure out â€“ and Iâ€™m only using the ones which come with the Mac v6 beta version!

However what I found most interesting was your partial explanation of the background processes. I had been imagining a blind iteration process of minuscule changes until equilibrium is attained (thatâ€™s the sort of approach Iâ€™ve done in my hobby projects). I can acknowledge that altering the step size based on approximated solutions will converge much faster â€“ and that it would be so daunting to do!

I enjoy physics and love numerical simulations of physical systems. I am glad Luis Fraguada recommended I check out Kangaroo way back in 2016. Unfortunately I couldnâ€™t get things to work back then and only regained interest in everything recently.