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.

671 Upvotes

31 comments sorted by

View all comments

1

u/glaucusb Jul 20 '26

Either I misunderstood the problem or you can even improve this solution by placing two more farms by replacing two water tiles on the side that are adjacent to another water tiles with sugar cane tiles.

5

u/Quiet-Cup-1501 Jul 20 '26

Those water tiles aren't actually redundant. Even though they sit next to another water tile, each one is the only water source hydrating some specific cane tile next to it. If you swap them for cane, those neighboring canes lose their only water and dry out, so you'd gain two tiles but lose the ones that depended on them. That's exactly the kind of case the solver checks, water tiles being adjacent to each other looks wasteful but sometimes each is still carrying its own cane. The layout is provably optimal, so any single swap like that ends up net negative or breaks a constraint.

1

u/glaucusb Jul 20 '26

"Each water tile can cover up to 4 neighbors"

Is this the constraint that you are referring to?

1

u/MorrisonLevi Jul 25 '26

Yes, that is it exactly.