Have you ever wished you had design software that could magically generate a garden/plot layout for you? What about one that takes into account spacing and companion planting of each plant?
After all in practice whether on paper, manually in software or right in the dirt we can generally tell where something
should go just by using our human brains.
So why is there not a neat piece of software that creates a layout all perfectly measured with plants next to their companions all with the press of a button? Sounds simple right?
Well I tried....here is what I learned; lets break down the problem.
The parameters:
-Let's let "r" represent the radius of a plant; being the distance it should be planted away from another plant of its kind.
-And lets say we want rectangular plots we will then have the parameters of length "x" and width "y" these will be the bounding coordinates that we want to plant in.
-Now plants should be represented as circles because
root systems don't necessarily grow in just 4 directions like a square. So we will use the expression of (Pi * r^2) for the area of a plant.
-For the rectangular plot we need to find the area so we use the expression of simply (x * y) lets call this variable "a".
-We will let "n" represent the number of plants we want in our plot and "t" be the total area of all the plants.
-Also for each plant we need to keep track of its distance & relationship relative to every other plant.
Goals:
We need to do the following things with those parameters..
A) Find if the total area of of plants fits within the area of the plot. If not there is not an optimal solution. Easy
enough if a - (n* t) >= 0 then we can fit the plants in the plot and can proceed to B.
B) Figure out how in the world you fit a bunch of
differently sized circles into a rectangle using up as much space as possible while keeping some sort of orientation for companion benefits...
Goal B?
Ok so how is that done? Well here we have run into what's called a packing problem. Specifically a
circle packing problem more specifically an unequal circle packing problem (unless you are planting a monoculture). In computer science this problem is considered NP hard.
When it comes to packing problems there are quite a few we have found proven algorithms for, such as packing uniform circles in a square although there isn't really a one size fits all algorithm for every case, for example after a certain number of circles it ceases to be optimal See
wikipedia
Of
course our goal would be to pack unequal circles into a rectangle for this problem there are a few
research papers but these may only address the packing of unequal circles but likely not with the relationship of companion planting kept in mind which adds another big problem on top of unequal circle packing.
This means a whole new algorithm to solve a likely one-off very difficult problem in not just computer science but in geometry in general, I would have to write a research paper like "Simultaneous sorting & packing of circles within rectangles" or something. Not to mention calculation Pi for all the circles, all the distance/angle checks would get computationally expensive.
So why pack unequal circles into a rectangle?
You are probably thinking "ok find another "less optimal" solution I don't measure my garden with a ruler anyways lol". But unequal circles are the best representation for the plant in 2D space.
Alright there are a few alternative solutions to choose from:
1) Pack the circles into a circle or square instead of a rectangle, this would leave the relationship issue to be solved but would use much more researched algorithms.
2) Represent the plant with a square instead, square packing algorithms are much more researched and used in digital industries and include simpler implementations such as the Greedy Packing algorithm. Personally I have implemented this for another
project and it was still a pain in the butt.
3) You may want to sort the plants by their neighbors/companions then arrange them in that order, for example along a linear line/curve/path, however this would not account for rows or better offset rows like in
permaculture and would only be separated by distance and in a fixed order of relation.
3b) Take the 3rd option and figure out positioning in a grid and try and take into account the above and below rows and shift entire rows to try and find an optimal distance/companion relationship between each layer.
4) AI, have AI mimic human thought and try to figure out where everything should fit.
The problem with all these solutions is that none of them would be theoretically as optimal as packing circles in a convex polygon such as a rectangle. This just means your software would not output a perfect optimally spaced coherent garden plan for you to look at. But they would get pretty close and probably better than we could do by hand anyway.
TL;DR Not all problems in geometry and mathematics have actually been solved including many packing problems, which would be required to write code for something like this. Mathematically perfect garden
plans require more research.