algorithmic modeling for Rhino
Dear friends and colleagues,
I have written a simple Genetic Algorithm code in C#/Visual Studio. I used the template for Grasshopper in Visual Studio. Now I need to define proper Inputs/Outputs for the new component to collect the Genes and Objective Function (Cost Function) data from the script in a Grasshopper file. Objective Function is the results of energy simulation in Grasshopper. It seems I need to define those connections in a certain way different than the normal input/output definitions in the C# file.
I would appreciate it if somebody could give me some clues that how I can define proper connections for the Genes(variables) and Objective Function in the C#/Visual Studio file.
Thanks a lot in advance.
Cheers,
Saeed
Tags:
I think that you want to write a new Parameters!
Is that right?
Sounds like instead of a data inheritance connection you're looking for just a one-way awareness connection, like the Galapagos object or the Timer object.
This can be done but requires quite a bit of code. You're going to have to override the attributes of your object (which will be a lot harder if you inherit from GH_Component instead of GH_Param or GH_DocumentObject). In these attributes you will have to draw your special connections and you will also have to handle mousedown+mousemove events for drawing your custom connections.
Or you could ignore the visual aspect and just provide some UI to type in the names of all sliders you want to incorporate into your process.
Alternatively you could just use regular connections and ignore all calls to SolveInstance on your object. This would be somewhat confusing to users, but the least amount of code on your part.
The user of this tool is only me! So, I prefer to do it with a minimum amount of code just need it to work properly for me.
But I did not understand what you said in the last paragraph. "Alternatively you could just use regular connections and ignore all calls to SolveInstance on your object."
would you please make it more clear to me, or that would be great if you show it to me by a sample code.
Thank you very much.
If you use regular connections, then you do not need any additional UI for what you need. However it does mean that your component or parameter logically depends on all your inputs, and as such will expire every time an input changes and will recompute on every new solution.
It sounds like you want to create something which works like Galapagos, and thus sits 'on top of' Grasshopper and starts new solutions, rather than being a helpless player in them. So if you use regular connections, you'll just have to ignore all the calls to SolveInstance() or CollectData() and immediately return out of those methods.
I'll see if I can come up with an example, but I might not have enough time today.
Elaboration: the solver component has two inputs, X and Y. All the sliders must be plugged into X, the measuring number must be plugged into Y.
You can start the solver via the component menu. It will move all sliders from their minimum to their maximum in 101 steps, and for each iteration measure the Y value and print everything to the Rhino command history.
First I should say thank you very much, David, for your great support.
I have been working on my project using the clues you gave me here.
There is one problem left I couldn't solve it. Then I tried on your file and it didn't work on that too.
I tried to use SetSliderValue() to assign values to the sliders and it worked on your file. But I need also to do something that this solver runs automatically in a script. The solution came in my mind was to run it with a BooleanTugle instead of running it from the component's menu. I changed some parts in your file (attached file) achieving that purpose. When I try to use the new component in Grasshopper I get no error but also nothing happens, it does not work.
I did some research on it, I guess I should not write any code in SolveInstance(), if it is correct, I don't know how to do that in another way then.
I would appreciate it if you could have a look at the attached file which is the edited version of your file and give me some clues that how I can do what I need to do.
Thank you very much in advance for your time and help.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by