r/factorio • u/FibonacciSpiral444 • 6h ago
Design / Blueprint I created an algorithm that designs whole factories by itself: belts, inserters, pipes and poles, from ore to science, as compact as possible (open source)
(edit: as compact as it possibly can, within time budgets) I've been working on a program that lets you create Factorio layouts, without any user intervention. Just configure your recipes, along with desired amounts and it creates a fully working factory for you. Also supports some Space Age mechanics. You can try it out now.
There are actually two separate projects I would like to share with you:
1. Fully functioning base builder (images 1-5)
How it works, roughly:
- a linear program picks the recipes and machine counts (it handles by-products, oil cracking, productivity),
- simulated annealing places the machines, a router lays belts, undergrounds, splitters, inserters and pipes (the same negotiated-congestion algorithm computer chips are routed with), poles get placed, and an independent validator checks every belt lane, rate, and pipe before anything is saved,
- then it keeps shrinking the box for as long as its budget allows.
Big jobs can get split into blocks of custom size that are generated separately and stitched together. (images 3 and 5)
On single block builds it reaches about 110–130% area of my most compact hand-made designs. Hand-made designs still win and more compute has diminishing returns. I believe it works well as a proof of concept.
Space Age support is experimental: foundries, EM plants and biochambers work, meanwhile recyclers don’t, Gleba spoilage isn’t modelled, and Aquilo heating pipes are also not modelled.
You can set products and rates, machines per recipe type, belt and inserter tiers, which edge and coordinate each input and output uses, box size and shape, areas to leave empty, block size for big jobs, and the time budget. There are many, many more options in the README.
2 A bot mall optimizer
Using Google OR-Tools' CP-SAT solver, this finds optimal layouts for small malls and near-optimal ones for larger ones. Do note that solving complexity grows quickly.
You can set products and rates, quality, forbidden recipes, cells to leave empty, and where raw items arrive, with a weight per source to pull consumers closer to it.
I’ve had a chance to experiment with this in my own play through world, and the difficulty shifted to allowing as much throughput on rail as possible, with perfect timings.
It can dramatically help with city blocks designs
The idea is very similar to city blocks, and with just minor adjustments, it could reduce rail congestions. Specifically, for 174 about 5× less travel than a random layout, and the gap grows with size.
Try it out here
You can use Github codespaces (in the browser), which will automatically download all required dependencies. Otherwise you can use any operating system with Java 25. For help with configuration and running, LLM assistants are very useful.
Both are open source and any modifications are welcome, Github stars appreciated.
All the blueprint strings can be found in the READMEs:
v2 (belts): https://github.com/SeezoCode/factorio_optimizer_v2
v1 (bot malls): https://github.com/SeezoCode/factorio_optimizer
Quick links:
- Image 1 blueprint
- Image 2 blueprint
- Image 3 blueprint note: building it in game caught a bug with inserters on belt curves, now fixed.
Happy to answer questions. If you create or build one of the blueprints, I’d love to see it!
TL;DR now i don’t have to play the game i like to play so much
