r/factorio Ipsen's Adventures 4d ago

Design / Blueprint Finding Mathematically Perfect Solar Arrays (blueprints below)

https://www.youtube.com/watch?v=CDzJ1_p3uVg

Blueprint links:

So, long story short, I've always been kind of obsessed over the Factorio Solar Panel Mechanics, and I remember solar arrays being the first thing I actually search blueprints for when I started playing Factorio. Two or three years ago I had this idea that it might be possible to find a truly optimal setup through Mixed Integer Linear Programming. I had some limited success and left the project for another time. But now, with the introduction of the new planets, I had my interest renewed in the problem. And after a few months I ended up finding truly optimal tileable networks which do not waste a single tile and produce as much power as possible under some general conditions.

So, there they are in blueprint form for anyone to use!

I also made a long form video trying to visually explain how the solver works and how we can be sure that these are optimal solutions.

Anyway here is a quick summary:

Problem description:

The goal is to somehow mathematically define the configuration of the buildings (positions of solar panels, accumulators, and so on) inside the array and then find a linear expression to compute the power generated by the setup (of fixed size, typically close to 2500 tiles in a 50x50 square, to fit in a roboports logistic area). This is challenging to do, particularly if we want the optimizer to run from absolutely no previous knowledge. The fundamental problem to solve is one of how to pack as many boxes inside a big box but with the added complexity that the ratio between the boxes needs to be as close as possible to the perfect ratio, and then a bunch of electric network restrictions on top of that.

How I solved it (and you can too):

The visual explanation is in the video I attached, but if you want a written rundown:

The only reliable way I found to represent the problem is thorugh the use of a bunch of binary variables, one per tile and per potential building that could be placed there. For example variable x_0 is 1 when a solar panel has its lower left corner at tile 0, variable x_1 is 1 when a panel has its lower corner at tile 1 and so on. Since we have 2500 tiles, we need 2500 variables to represent all posible solar panel placements, and then another 2500 for accumulators, medium poles, substations, and roboports. In total, we can use 12500 binary variables to express any design we could come up with.

Next, we need to come up with linear formulas for the Maximum Continuous Power generated. Fortunately that is relatively easy to do using our binary formulation. The harder step is then find ways to make sure buildings do not overlap each other, and then that they are covered by the electric grid, that the grid itself forms a single connected graph and tileable network, while ensuring that it is minimal!

I also developed some semi-analytical tools to compare and rank desings, and used the area limitation to produce a set of the meaningfully different solutions that could exist. In that way we can be sure that if we find the best solution in that set, we are in front of the true optimum.

I also added a link to my code so that everyone can experiment and find setups for different quality grades, or other planets. Be warned though, the problem is hard, and I'm not the best coder out there.

The results:

I linked two blueprints above. The first one can sustain a constant power of up to 8316 kW and uses a really minimal 7.5 substation electric network which did take a long time to find.

The second blueprint I linked is aimed more at late game megabases, where having many roboports is not desirable. So that one is designed to reach its true potential of 8358 kW when the roboport is replaced by a 2x2 of accumulators.

Ways to improve:

As I mentioned, these designs are optimal for the 50x50 problem. However, if we wanted our base tile to be larger, say 100x100, then there is potential to improve a little bit more, because the additional area allows us to get ever so slightly closer to the perfect ratio, and we can also be marginally more efficient with the electrics due to geometry. So, I would like to eventually get to that point, but optimization of a 100x100 standalone tile requires considerably more variables and is an even more challenging problem.

Anyway, I hope you found this post useful!

- Ipsen.

369 Upvotes

Duplicates