Author Topic: Factorio  (Read 566 times)

0 Members and 1 Guest are viewing this topic.

Online paulcaTopic starter

  • Super Contributor
  • ***
  • Posts: 6354
  • Country: gb
Factorio
« on: July 23, 2026, 03:34:49 pm »
This game isn't a game.  It's software engineering in a cute cartoon disguise.

https://factorio.com/

I have spent FAR too long trying to "Demand share" two logistics networks and all I can do is get feedback or oscilations.  I end up trying to analyse shared bus problems with mixed consumer/producers coupling.  Now I have to give up as its just not going to work... or rather... oscilation IS it working.

Anyone else addicted to this?

If not, why not?

Another example... after playing the game through a few times and getting more and more elaborate with trainlines and more and more elaborate deadlocks.  I finally applied some software engineering to the problem and noted immediately.  "Bi directional / dual lines are a mistake".  They create junctions where your choices are "single large monitor zone" and only permit one train at a time to enter the junction (slow for large junctions) OR you accept the A locks B, B locks A classic deadlock problem when you let 2 or more trains into the same junction.

I made the entire train network "single directional".  All "junctions" or "monitor zones" for concurrency nerds, were merge (sequence by arrival) or split - no special treatment.  Basically "Serialisation" of flow.  You can just keep making it go faster and faster with more and more traffic until you hit "capacity" when there are enough trains to fill the whole track and then it "Head = Tail" locks.  In code this normally occurs when your queue buffer occupies all entries in the circular array and the next operation in the queue is "write".

A clock wise loop then an anticlockwise loop, tiled out to create a grid.  The only trade off is latency.  Trains do need to literally "go around the town" to get anywhere.

Deadlocks do still occur.  Head = Tail deadlocks for station entry/exits happens when the station is full.  Train can't exit because the train trying to enter is holding the lock on the shared path.  But that train can't enter until the og. train leaves.  So "Station capacity" is still limited, but easily solved with making your traffic more demand based with "Parking when idle" in sidings off the main lines.

The entire need and the driver for the train network at all is to decouple factory components into "multiple consumers and producers" so you can duplicate and expand easily.  Which itself is "Software Architecture" and the trains are "Middle ware".
« Last Edit: July 23, 2026, 03:37:24 pm by paulca »
"What could possibly go wrong?"
Current Open Projects:  68000 Self Build computer + OS.
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1960
  • Country: 00
Re: Factorio
« Reply #1 on: July 30, 2026, 07:20:53 am »
Please, I just went through a full episode of withdrawal symptoms >:D


Yes, this is a very fun 'game' (or factory simulation editor) to play..

I haven't got a clear graphical picture of everything what you shared, but are you playing with some kind of cityblocks layout?

Personally I view trains as a similar system as anything else in the game. Things can backpressure and that's OK. But there does need to be enough space for this backpressure to go. For example with oil, in earlier game versions it was by the far the most scarce resource in the end game. Each pump degraded from 10-15 oil/s to just 0.1 oil/s. At later stages you could have the energy to boost them, but still, even with a 500% boost its only 0.5 oil/s
So the design requirement is: this pump must never stop operating. How frequent do I collect oil packets to send out to base? How much capacity is being used there? How much do I want to store for bursty moments? Those then are basically also consumer/producers in a very isolated form, and you can easily calculate the required buffer size.
I did a similar thing with trains. Just build a stacker that can hold as many trains needed. But in city blocks that is obviosuly harder. However, I did see there is a logistic train mods that only sends out trains "on demand", and will reuse trains for different routes. That seems a lot more managable.

At one point I also looking into mapping Factorio onto dataflow graphs. However, with the recent addition of Quality in the Space Age DLC, this wasn't so easy anymore. I wanted to calculate the ideal ratio of productivity : quality modules in each machine. The wiki had some information on this using Stochastic Matrices: https://wiki.factorio.com/Quality

However, these matrices make a few assumptions. For example, they assume that you want to go from [Plain Resource]  to [Legendary Product] in 1 machine step. Whatever is left gets recycled at 25% return (and crucially: a quality bump). Its not too hard to derive solutions that converge within just a few matrix multiplications.
Then the "meta" became to introduce LDS shuffle, space bingo, and a few others.. and basically crafting legendary 'everything' became almost trivial. Once you have all legendary resources, you don't have to think about quality anymore.. you just shifted a regular factory to legendary and almost everything gets a 150% bonus.

I read in 2.1 that they removed space bingo. So that makes it a bit harder again, which prompts for some research I was doing just when Space Age came out. I wanted to see if I can optimize my factory when I don't just keep recycling intermediate products to get to legendary straight away. Why don't I do like Smelt Iron => Craft Electronic Circuit => Craft Advanced Circuit => Craft Processing Unit
And then find the most efficient way to recycle Processing Units so that I maximize its legendary output, which means I can either put a recycle loop at Iron and then build only a Legendary Factory. Or I could put the recycle loop anywhere else along the chain and try to optimize for every single production step. Here we potentially have 3-4 production steps, 3 recycling steps, and also vary the modules for every quality level, as factories for each quality level need to be built.
 
Unfortunately this means a design problem with 4 producers across 5 recipe quality levels, with module configurations that can hold up to 5 modules (lets say an Electromagnetic Plant), which means I have 5^(4x5) = 95 367 431 640 625 multiple configurations to simulate. Ouch! So I was looking at another way of how you can design factories with a certain "item quality distribution" (much like we have a probability density function in statistics) and then find the optimal module configuration for the next "item quality distribution".
However, with my limited mathematical creativity to fit this onto a formal problem, I did find there is another design freedom in this "optimisation": you could prioritise which resource is recycled more or less... So even I can find a way to curtail 95T solutions, I also need some method to qualify which one is the best. Do I optimize for iron:product conversion ratio? Or copper:product? Or oil:product?

The quality system made Factorio a surprisingly interesting game. The meta is to just establish legendary resources and craft everything from there.. but building these more 'natural' factories and finding ways to model, balance and optimise them is quite challenging. I don't think I've seen anything like it in other games, as there you often don't have any sophisticated calculations beyond a single consumer-producer number, determine some logistic transporting interval, and calculate your required buffers from there.
Inadvertently it also made "optimal" in Factorio be like: which one out of potentially hundred variants?
« Last Edit: July 30, 2026, 07:25:49 am by hans »
 

Online paulcaTopic starter

  • Super Contributor
  • ***
  • Posts: 6354
  • Country: gb
Re: Factorio
« Reply #2 on: July 30, 2026, 12:08:52 pm »
Trains do now have (better) logicistics.  The way it works is:

You can have many stations called "Iron Out" say.  You can also have many stations with the name "Iron in".  You can then add as many trains as you want going from "Iron Out to Iron In".  With two "Interrupts".  Fuel and Parking.  By default it sort of works like the bots.  "Turn about next free".

If the fuel is low, the fuel interrupt inserts a stop at the nearest stop called "Fuel".  The parking interrupt is inserted anytime either "Iron In" or "Iron Out" is blocked, disabled or busy.  The interrupt takes the train to a near by free "Parking" siding where it will wait.

So in practice under light load most trains end up sitting in the parking sidings a lot.  You can literally just map zoom to your parking and note, for instance, "No iron trains in parking."  = "Probably need more iron trains, or they are stuck"

Stations them selves can be hooked up to their "loading boxes" for contents and a circuit condition disable "Output" stations if htey have less than X amount to give and shut down "Input" stations when they have plenty.  Hence idle trains in parking.
"What could possibly go wrong?"
Current Open Projects:  68000 Self Build computer + OS.
 

Online paulcaTopic starter

  • Super Contributor
  • ***
  • Posts: 6354
  • Country: gb
Re: Factorio
« Reply #3 on: July 30, 2026, 12:15:26 pm »
Bot networks.  Small bot networks are amazing.  But you learn the hard way when you think, "I'll just join them all together into one massive full factory bot network".  The convenience of full map logistics promptly cases huge latency.  Turns out that the game will just pick the next free bot and assign it "closest" next request.  So when it's busy, you can end up waiting for several minutes (or far worse) for a bot to make it from half way across the map to lift an item from a chest 4 tiles away and bring it to you.

The solution is "don't create large bot networks in the first place".  But since you probably did, separating them is a matter of moving bot roboports so the logistic network gets broken by 1 grid tile.  You can then use requestor->provider chest pairs and an inserter to move materials between two networks at it's border without the bots mixing.

This is fine.  When you try to make this two directional, so that network A can request from network B, but network B can also request for network A... you think you can get clever, but all you will do is get yourself tied into feedback knots, unless you go the long way of specifying each and every consumer and producer demand which crosses the border.  Fine if there are one or two, but not when there are dozens.  For that you need to start playing with "Constant provider lists"
« Last Edit: July 30, 2026, 12:17:14 pm by paulca »
"What could possibly go wrong?"
Current Open Projects:  68000 Self Build computer + OS.
 

Online paulcaTopic starter

  • Super Contributor
  • ***
  • Posts: 6354
  • Country: gb
Re: Factorio
« Reply #4 on: August 04, 2026, 01:47:02 pm »
Oh... what happens when you take a bored software engineer on a slow day in work, factorio and a claude code terminal?

"What could possibly go wrong?"
Current Open Projects:  68000 Self Build computer + OS.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf