1

Is there a way I can use the deap library inside grasshopper's Python node I want to run a genetic algorithm but the fitness function is to be calculated by grasshopper (only the fitness function, all the other things are to be taken of by deap inside the python node) can it be done?

I am having problem with

  1. importing the deap library in grasshopper's Python interface(I think I will be able to solve it by copying the files manually from Python path)

  2. (major problem) grashopper doesn't allow closed loops so I cant seem to find a way to feed the fitness back into the Python node with the main code

coder
  • 8,346
  • 16
  • 39
  • 53
gokul gupta
  • 330
  • 4
  • 13
  • Please remove the rhino tag, as this question doesn't relate to Rhino (but relates to rhino3d) – Paul Apr 08 '22 at 10:58

2 Answers2

0

couldnt get it to work, had to make do with the grasshopper pluggins

the problem was that you can only install iron python libraries for grasshopper

gokul gupta
  • 330
  • 4
  • 13
-1

These are two well known issues with 'out-of-the-box' grasshopper but there are several plugins that can help overcome them.

Question One

The basic GHPython component uses Iron Python and can limit which libraries are compatible and able to be used. To get around this constraint there is a plugin called 'GH_CPython'. It allows you to set a locally installed python interpreter for your code, and then have access to any libraries available to that local interpreter. So if you install deap Libary locally then it will be available within the grasshopper GH_Cpython editor. Here is a link to download and install GH_CPython: https://www.food4rhino.com/en/app/ghcpython

Question Two

As you noted, Grasshopper is procedural and has limited support for recursive routines. To get around this there are several plugins that support recursion and may be able to help with your implementation. Which plugin would be best for your situation is difficult to say without a deeper description of your goals. Here are several options, each option provides recursive functionality that would allow for 'closed loops' where results of a script can be fed back as input.

  1. Hoopsnake - very basic and has been around the longest
  2. Anemone - A little more flexible and uses multiple components for loop start and end for cleaner-looking scripts. It also has a 'record history' functionality.
  3. Octopus - Has a 'Loop' component that is similar to Hoopsnake. It also has a 'record history' functionality.