I would like to maximize an indicator with only one slider as a parameter.
I know that there’s only one solution which can be found by gradually increasing parameter value until it gets to the best value possible (the one that maximize the fitness parameter) like shown in the image.
I tried to do it with Galapagos but the evolutionary method, even though it gives good results, is far from optimal and tends to be time-consuming …
Fore cases like this I developed my own stepper driver which converges at a threshold value (which can be based on a “fitness” value). But the logic for that value is up to you to figure out (but you could collect result values in a list, then sort them and pick the best value as the “fitness” value. for example).
The MaxNumSolver(s) supports watching, and converging, at multiple downstream values (why waste your time running them one by one if they solve different non-dependent problems, like finding a bunch of “solution candidates” for different approaches etc).
I also made a VS version of this (which is included in a GH plugin though), but I can’t remember if I made any bugfixes on this script-component version, but the example provided in this definition seems to work:
This is a generic problem with non-deterministic methods; They can’t (or should’nt) be used for “production” solutions, which typically needs to be deterministic, and as you indicated, much faster. Or in other words, the end result really must be designed, implying a goal being based on some critical degree of foreknowledge.
How that foreknowledge is gained is another matter altogether. To clarify the reasoning I want to point out that earlier exploratory stages may well make use of non-deterministic methods, like for finding sensible boundaries for which a final (designed) solution is targeted with deterministic methods (like, finding target values within a known specific interval, with predefined step-sizes etc, which is what the basic idea was with the redneck solution which I called “MaxNumSolver”).
Whenever you have a single slider it is better to remove the slider and give a wide range of values.
Then get the optimized value get its index from the list and use the index to get the input value that produced it.
Here is another method that I use for optimization when there’s only one parameter:
-Divide the parameter domain into n equal segments and generate a range of values.
-Generate a solution for each value in the range.
-Generate points with the values from the range as X, and the corresponding solutions as Y coordinates.
-Interpolate the points to create a curve that represents the solution set.
-Find the extremes of the curve.
By that method, I managed to find optimal angle as 29.998832 when n is 10. The bigger the n, the better the result.
I actually think Goat is closest to what you want here
You connect it to sliders and an output value to min/max just like Galapagos, but it’s deterministic, and converges much faster than an evolutionary method for this sort of simple problem, yet still doesn’t require that you know a function for the gradient.
Kangaroo can be faster still for some types of problem, but requires that the thing being optimised can either be defined with a combination of the included goals, or you can write a function for the gradient as a custom goal.
I believe there’s also a completely non-iterative solution to this particular problem too - just using trigonometry. I’m guessing though that you are showing this just as a simpler example, and are actually interested in a more general method, in which case iterative numerical optimisation does make sense.
I initially tough of some recursive code inside the script to find the solution with dynamic increment to find the best solution unfortunately grasshopper doesn’
It seem to support recursive definitions …
I guess I’ll use a range of value (which actually gives good approximation) based on all these scripts ? @RIL would you mind if I use or slightly modify your solver for my master thesis ?
@DanielPiker Thank you ! This is exactly what I was looking for in first place !
There’s indeed a simple analytic solution for this particular problem. But as you’ve guessed it’s part of more complex structures and I, yet, haven’t found a better solution than numerical optimization (which I actually don’t know how to do for the moment)
I’m actually using kangaroo to create this kind of structures but the results aren’t great with all the structures I try to optimize … Maybe I should try to redefine my goals by looking at all the other possibilities and in particular dynamic relaxation which I have never heard of …
Dynamic relaxation is just a name for the method used by Kangaroo to find structures in equilibrium.
If you have examples where you’re trying to use Kangaroo and aren’t getting the results you expect, you can post them here. Often form-finding tensegrity structures can be as simple as modelling the approximate geometry, then assigning a pre-tension to the cables and making the struts stiff. If you are starting very far from an equilibrium position though you might need a bit more.
Also - depending on how you are fabricating them, you might need to actually calculate the slack length for the cables after the form-finding step.
For medium sized structures with something fairly inelastic like wire for the tensile elements, you can probably just take the lengths directly from the output of the form-finding, or scale them by some factor slightly less than 1 for pre-tension.
For larger structures though, or if using more stretchy material for the cables, then to get the same geometry you need to calculate how much each cable should increase in length, and I can share some example files for this if you need.
There is a simpler way to approximate the gradient of any continuous function: (F(x+h) - F(x))/h, where h is a value close to 0. Given a fitness function, you evaluate it in x in at x+h, and you can measure how it will change. If the fitness decrease, then move x backwards, if x+h is more apt, move it forward, iteratively until it converges into an acceptable error.
Here is a quick implementation using Anemone. Now I don’t have time to make it robust, but the main idea is there.
Thank you very much ! I didn’t know it was possible to create loop, as I’ve been facing that circular references lead to errors !
I can confirm by trial and error, BOBYQA and COBYLA are the two best options !
I’m actually struggling a bit to create an efficient script that create assembly of tensegrity cells …
I’m trying to vary the thickness of the assembly as well as the height thus leading to a specific ratio between compressed and tensile elements for each level of the assembly
I obtain some results by using a unique big ratio, but it makes the structure kind of inflating … Ideally, the best way to achieve good optimization of ratio would be maximizing the length of compressed element (in red in the script) with respect to the length goals of the other elements. But I can’t find a way to do it …
Perhaps I should point out that the MaxNumSolver approach is best suited for repeated tasks, which doesn’t suffer from local optima but instead having a convex result curve (like the one you posted). For repeated “heavy” tasks it is a big advantage to start the solver near a foreknown solution interval, and terminate as soon as a goal is reached. For one-off solutions number series is just as good or better since it can detect local optima, if any. So, the MaxNumSolver, although it supports “looping” (reacting on downstream values), it isn’t useful unless you know that you always have a convex result curve.
thanks for getting back to us on that sad issue. We have been fighting false positives from antivirus software ever since switching to an automated installer. See the thread starting at post #25913 over at https://www.food4rhino.com/app/goat
The only way to make the antivirus software happy would be to digitally sign the installer. With goat being freeware, that shifted a bit out of our focus, buying the respective certificate is not an option at the moment.