Simplex algorithm

Hi,

Has anyone tried to implement the Simplex optimization algorithm (or any other linear programming optimization solver) in Grasshopper?

I know there are packages that have solvers for Python like scipy or pulp, does anyone have experience in bringing those to Grasshopper? What is the most user-friendly and least troubling way to do it?

I believe many of the optimization problems in the 3D realm can be actually solved by linear programming, so it’d be of huge help here.

To the best of my knowledge there is not straightforward method for implementing e.g. scipy in GHPython (i.e. IronPython). The current path of least resistance might be to implement Rhino Inside Python to communicate with CPython. There’s also at least two CPython scripting components for Grasshopper, but those (from what I’ve seen) appear like quite complicated and brittle solutions.

A simpler solution might be to implement a .NET library instead (assuming it has what you require), such as https://numerics.mathdotnet.com/. Here’s a tutorial Giulio wrote on spinning that up in GHPython:

2 Likes

Read this:

Then play with that (as usual in C#):

Simplex_OnRndMatrix_V1.gh (121.5 KB)

2 Likes

I do not have an answer to your question, but can you share a couple of examples of “optimization problems in the 3D realm” where you believe linear programming might apply?

Thanks in advance.

1 Like

In my particular case I’m trying to find the best positioning for the sanitation facilities in refugee camps taking into account the walking distances, possible locations, cost of placement etc. I tried to do optimization through Galapagos and Wallacei but it’s more time consuming and as I understood from what I read about linear programming optimization, if your problem can be described appropriately then the exact single optimized solution can be found and in shorter computing time. This is just one of my cases but I’m assuming more of the task of this kind can be dealt with using the LP methods.

I do not know the layout but maybe machine learning is the way to go.

Appears to me that you are rather after swarm optimization (Google PSO).

1 Like

It sounds like the problem you want to solve is an example of the class of discrete optimization problems known as the Facility Location Problem. Linear programming is a component of many algorithms for these problems, but by itself, cannot solve these problems. You might want to look in particular for algorithms for the p-median problem for which the Wikipedia article says there is free software available. I have no insight into what might be involved in getting those algorithms to work in Grasshopper.

1 Like

Thank you people for all the suggestions. I will go through them.