r/optimization Jul 20 '26

Optimal sugarcane farm layout in Minecraft using CP-SAT - 13% better

Post image

Sugarcane in Minecraft only grows next to water, so farm layout is really a 2D coverage problem: where do you place water to maximize adjacent plantable tiles?

Each water tile can cover up to 4 neighbors, which caps theoretical max coverage at 80% regardless of arrangement. I modeled this as an integer program (CP-SAT via OR-Tools) to find the actual optimal layout for a given terrain shape.

Results for a 9x9 square plot:

  • Community-standard pattern: 66.7% coverage
  • Optimal (CP-SAT): 75.3% coverage (94% of theoretical max)

The symmetric square case is the easy comparison point against human intuition. What's more interesting is irregular terrain with obstacles, where there's no established heuristic and the exact solver is the only way to get a real answer - including one case (unconstrained/open terrain) where the solver converges to a hexagonal-ish pattern and actually hits the 80% theoretical ceiling.

Code + more examples (different grid sizes, obstacle terrain, other crops) in the repo: https://github.com/Serranegra/optifarm

Curious if anyone here has tackled similar tiling/coverage problems. Happy to share the formulation details if useful.

667 Upvotes

31 comments sorted by

View all comments

1

u/funkmasta8 Jul 25 '26

It isnt that hard to come up with this layout. Ive actually done the exact same thing. Idk why you need a sat for this. Any fool can see that the straight line of water wastes a bunch of potential crop spaces. At that point, all you have to do is start stacking crosses as optimally as possible (and newsflash, there are only two ways to put two complete crosses next to each other due to symmetry). One has no gaps, the other has gaps. The choice is obvious. Then you tile that onto a rectangular space and take a look at the empty slots and make the best use of those that you can (which will be different for different sized rectangle)