Article Series About Smooth Factory Function and Factory Optimization Techniques

Post all other topics which do not belong to any other category.
OptimusPrimeLord
Manual Inserter
Manual Inserter
Posts: 1
Joined: Tue Dec 05, 2023 6:05 pm
Contact:

Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by OptimusPrimeLord »

Over the past six or so months I have been working on two primary factory design tools to help me better play Factorio and ended up deciding to make a writeup on both of them. The first tool solves an issue, which I term 'stalling.' I first ran into stalling while handling ores in Seablock, it occurs when recipes requiring the circuit networks to manage seem to have a ton of edge cases that the circuit network has to handle. The second design tool is a virtual pricing method that generates pricing models using calculus; this tool is particularly useful in building "optimal" factories, determining which recipe to use if multiple may suffice, when and where to use different modules, and determining what items should be transported via rails. I currently have five of the articles written, starting with an Introduction that hopefully makes the whole series more accessible even to those who haven't played Factorio. I have versioned all of these just in case I need to update them in the future.
I'm still working on programming an optimizer given what I have written so far so that I can write articles on the application of the virtual pricing models on different mod packs. Currently running into issues with floating point errors but I need a break so I probably won't be working on article #6 for a month or so.

Anyway here's the link to a folder with all the articles so far:
https://drive.google.com/drive/folders/ ... sp=sharing
NineNine
Fast Inserter
Fast Inserter
Posts: 157
Joined: Mon Oct 24, 2022 11:20 pm
Contact:

Re: Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by NineNine »

Wow! Mathematicians are a whole different breed!
User avatar
Khagan
Filter Inserter
Filter Inserter
Posts: 256
Joined: Mon Mar 25, 2019 9:40 pm
Contact:

Re: Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by Khagan »

OptimusPrimeLord wrote: Tue Dec 05, 2023 6:39 pm Anyway here's the link to a folder with all the articles so far:
https://drive.google.com/drive/folders/ ... sp=sharing
I have thought a couple of times about putting together something on the topic of pricing in Factorio (your part 3). Your approach is a little different from (and doubtless more rigorous than) the way I would proceed. One thing you don't mention is the value of resources: how much is, say, one unit of iron ore worth in the ground? (Or equivalently, how much more is a unit of mined ore worth than the cost of mining it?)
mrvn
Smart Inserter
Smart Inserter
Posts: 5878
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by mrvn »

Khagan wrote: Wed Dec 06, 2023 5:33 am
OptimusPrimeLord wrote: Tue Dec 05, 2023 6:39 pm Anyway here's the link to a folder with all the articles so far:
https://drive.google.com/drive/folders/ ... sp=sharing
I have thought a couple of times about putting together something on the topic of pricing in Factorio (your part 3). Your approach is a little different from (and doubtless more rigorous than) the way I would proceed. One thing you don't mention is the value of resources: how much is, say, one unit of iron ore worth in the ground? (Or equivalently, how much more is a unit of mined ore worth than the cost of mining it?)
Do you have a choice? If you mine the ore you have iron. If you don't mine the ore you have nothing. You have to mine it, there is no other way to get iron. Ore in the ground is worth nothing. So mined ore is infinitely more worth than not mined. Ore fields have a monopoly on ore, unlike oil. You can compare oil processing vs. coal liquification. Still, you compare methods of mining oil, not oil in the ground versus oil in the hand. What you think of as the worth of ore in the ground is always potential value of the mined ore. You can't compare the potential value of the mined or against the value of the mined ore. That's the same thing.

So the only thing you can compare there is the worth of mining the ore now or mining it in the future and different mining ways. Because with productivity and efficiency changes (or big mining drills from v2) you get more ore out of the ground or for less cost. With coal liquification you get oil from a different source.

You can also talk about the price of mining itself. Comparing mining it with steam power vs. solar power for example. Modules? Beacons or no beacons?
User avatar
Khagan
Filter Inserter
Filter Inserter
Posts: 256
Joined: Mon Mar 25, 2019 9:40 pm
Contact:

Re: Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by Khagan »

mrvn wrote: Wed Dec 06, 2023 6:23 am
Khagan wrote: Wed Dec 06, 2023 5:33 am One thing you don't mention is the value of resources: how much is, say, one unit of iron ore worth in the ground?
You have to mine it, there is no other way to get iron.
True.
Ore in the ground is worth nothing.
False. A depleted patch of ore, that can no longer be mined, is worth nothing. A non-depleted patch, that can still be mined, is clearly worth more than that. How much more?

It's a matter of supply and demand. If you had conquered and were defending sufficient territory that your current needs for iron were exactly met, but now one patch of iron ore has run out, you have to go and conquer and defend more territory. This costs time and resources.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by Qon »

mrvn wrote: Wed Dec 06, 2023 6:23 am Do you have a choice? If you mine the ore you have iron. If you don't mine the ore you have nothing. You have to mine it, there is no other way to get iron. Ore in the ground is worth nothing. So mined ore is infinitely more worth than not mined. Ore fields have a monopoly on ore, unlike oil. You can compare oil processing vs. coal liquification. Still, you compare methods of mining oil, not oil in the ground versus oil in the hand. What you think of as the worth of ore in the ground is always potential value of the mined ore. You can't compare the potential value of the mined or against the value of the mined ore. That's the same thing.

So the only thing you can compare there is the worth of mining the ore now or mining it in the future and different mining ways. Because with productivity and efficiency changes (or big mining drills from v2) you get more ore out of the ground or for less cost. With coal liquification you get oil from a different source.

You can also talk about the price of mining itself. Comparing mining it with steam power vs. solar power for example. Modules? Beacons or no beacons?
Not yet in vanilla. But in SA (which kind of is vanilla, but unreleased) and in mods that will change.

Also for vanilla right now:
The cost of resources are payed in electricity and the mining drill, the modules and the electricity generating equipment cost resources to create. And if mining with coal power (electric drill and boilers fed with cola or coal mining drill) then things like mining productivity from research can decrease the energy cost. Electric mining drills are I'm pretty sure more efficient way to burn coal for how much ore you get per Joule. And then modules can change this. If you are mining coal with productivity modules, the miners become slower (so more energy per mined ore) and drain more energy. Speed modules also increase power cost. So when relying on coal power, how much productivity are you actually getting when prod moduling your mining drills? The prod effect is pretty large so surely it is way higher than the productivity loss of directing more of your output back into the drills, but it is still worth analysing. You might net more total resources with efficiency modules than productivity modules in some cases.

So I'm going to read the articles and consider the tool application to cost of everything, including ore cost now and even more so for future vanilla and mod use.
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
mrvn
Smart Inserter
Smart Inserter
Posts: 5878
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by mrvn »

Qon wrote: Wed Dec 06, 2023 10:09 am
That's the cost of mining the ore and the value the mined ore has. The ore in the ground has no value other than the potential to be mined ore. I.e. what it is worth once you mined it. And my argument was that you can't compare the value of the ore in the ground to the value of mined ore because the two are the same (except one is potential and the other actual).

In factorio mechanics you don't keep an ore field around because it looks like Jesus. Or get more efficient assemblers because you place them on ore or something.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by Qon »

mrvn wrote: Wed Dec 06, 2023 1:57 pm
Qon wrote: Wed Dec 06, 2023 10:09 am
That's the cost of mining the ore and the value the mined ore has. The ore in the ground has no value other than the potential to be mined ore. I.e. what it is worth once you mined it. And my argument was that you can't compare the value of the ore in the ground to the value of mined ore because the two are the same (except one is potential and the other actual).

In factorio mechanics you don't keep an ore field around because it looks like Jesus. Or get more efficient assemblers because you place them on ore or something.
Yeah. But also, ore in the ground can be more valuable than ore in a box. Ore in the ground increases in quantity with mining in the future after prod research compared to now (and so also value) if it is in the ground, but already mined ore relativly decreases in value due to the mining prod inflation. So while you can't chose much other than mining ore, you can choose between doing it now in excess and buffer or doing only what is necessary now to progress towards more productivity and delay it as much as possible. So there is some small reason to keep it in the ground as long as possible, especially in maps where infinite exploration isn't feasible. You're not really wrong, but there are considerations for some scenarios ;)
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
mrvn
Smart Inserter
Smart Inserter
Posts: 5878
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by mrvn »

Qon wrote: Wed Dec 06, 2023 3:19 pm
mrvn wrote: Wed Dec 06, 2023 1:57 pm
Qon wrote: Wed Dec 06, 2023 10:09 am
That's the cost of mining the ore and the value the mined ore has. The ore in the ground has no value other than the potential to be mined ore. I.e. what it is worth once you mined it. And my argument was that you can't compare the value of the ore in the ground to the value of mined ore because the two are the same (except one is potential and the other actual).

In factorio mechanics you don't keep an ore field around because it looks like Jesus. Or get more efficient assemblers because you place them on ore or something.
Yeah. But also, ore in the ground can be more valuable than ore in a box. Ore in the ground increases in quantity with mining in the future after prod research compared to now (and so also value) if it is in the ground, but already mined ore relativly decreases in value due to the mining prod inflation. So while you can't chose much other than mining ore, you can choose between doing it now in excess and buffer or doing only what is necessary now to progress towards more productivity and delay it as much as possible. So there is some small reason to keep it in the ground as long as possible, especially in maps where infinite exploration isn't feasible. You're not really wrong, but there are considerations for some scenarios ;)
As stated in my original post already.

Mine now or mine later is a valid question.
User avatar
MeduSalem
Smart Inserter
Smart Inserter
Posts: 1686
Joined: Sun Jun 08, 2014 8:13 pm
Contact:

Re: Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by MeduSalem »

mrvn wrote: Wed Dec 06, 2023 10:05 pm
Qon wrote: Wed Dec 06, 2023 3:19 pm [...]
[...]
The question whether to do something now or later is easily answered in a generalized manner that I usually apply in all games I play.

If doing something can become more efficient if you do it later and if there is no worthwhile advantage from going ahead-of-time, then generally do it later. And in the "now" only focus on doing as much as you need to do to get that additional efficiency.


So I am with Qon. Ore in the ground is not worth nothing. It is nearly always more worth in the ground than when it is already mined because of future additional mining efficiency. I wrote "nearly always"... because for a short period exactly the opposite is true (which I talk about further down).


You could - hypothetically - stop mining ore exactly after you have mined the exact amount of ore you need to finish the current level of productivity research. Then let that productivity level finish researching, and after that restart mining more efficiently. Rinse & repeat. That would be the least amount of resources wasted.


But there is the time aspect and that is where it gets complicated. If you stop mining and wait for research to finish up first, the factory progressively shuts down and you wasted time where you could have continued doing stuff, albeit sacrificing small amount of "future efficiency" doing so.
Then that is the short phase where ore you have mined already and which is ready in stock is more worth than the one that is in the ground because you need it to keep the factory going. There it pays off to go ahead-of-time for a tiny period.


There totally is an optimal point between those two. How long would it be "okay" to shut the mining down so that you will spool up production fast enough again to have wasted the least amount of resources. Because neither "extreme" of either shutting the factory down nor keeping on mining stuff is the optimal during that "switch over"... it is rather somewhere in between. That optimal crossover point probably could be calculated.


But honestly I think it is not anywhere nearly worth the effort of going to such lengths to save on a bunch of virtual items. ^^

Also in practice... no one considers to shut their mining down even though from the hypothetical thought experiment above it is clear that there are points (close to when finishing the research) where it would be worth doing that because it would be less wasteful.


The best approach for practice is... Simply do mining & item production as much just-in-time as possible.
If one doesn't over-mine or over-produce ahead-of-time like crazy, but rather just in the amounts you need to keep stuff continuously going you should generally not have wasted too much time mining on a worse mining productivity.
So the practical goal is to cut down on buffered items where you can.



The real fun begins for things when it is actually worth doing stuff ahead-of-time. Like when starting Modules production or something. Because that stuff pays for itself the sooner you get it. And it will be even more extreme with quality added to the mix. ^^
FasterJump
Fast Inserter
Fast Inserter
Posts: 237
Joined: Sat Jul 09, 2016 11:43 am
Contact:

Re: Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by FasterJump »

Not sure if that's already been said, but linear optimisation could help.

Although the typical case is more for scenarios like the game Satisfactory, where you can make different products from materials, or products from different materials.

Factorio is simpler because there are few alternative recipes, but much more complex because of modules and productivity research. Maybe it's possible to modelize that using linear optimisation?
User avatar
MeduSalem
Smart Inserter
Smart Inserter
Posts: 1686
Joined: Sun Jun 08, 2014 8:13 pm
Contact:

Re: Article Series About Smooth Factory Function and Factory Optimization Techniques

Post by MeduSalem »

FasterJump wrote: Mon Mar 11, 2024 12:23 pmNot sure if that's already been said, but linear optimisation could help.

Although the typical case is more for scenarios like the game Satisfactory, where you can make different products from materials, or products from different materials.

Factorio is simpler because there are few alternative recipes, but much more complex because of modules and productivity research. Maybe it's possible to modelize that using linear optimisation?
It is possible. At least for someone with a better theoretical mathematical background than me.


I am using a bruteforce method in my spreadsheets by setting up a scenario (like different beacon arrangement & modules combination) and then calculating everything. Then comparing the total resource cost of the various scenarios trying to find the one that requires the least resources to get to that target SPM I have in mind; or taking some other metric as target (like least power/pollution or whatever)

But I have to manually set up these scenarios by making some educated guesses which combinations of modules make "sense" to eliminate the options; it can't find the optimal solution(s) on its own.

But when I can do it manually, I am sure there is an algorithm that could automate the process of finding that "optimal" scenario.


However my approach of testing pre-determined scenarios using some educated guesses delivers "meh, close enough" results that will be satisfying enough in practice. So it is questionable if it is worth to go the extra-length of solving it for every single combination, just to find the most optimal solution.

I am sure the most optimal scenario is not one that looks all that pretty either because it likely has some pretty weird ratios of machines and modules that you would never consider doing in practice for simplicity reasons or because of aesthetics.

At least I know I wouldn't leave some assemblers empty of modules or have a different module combination than the majority just because a spreadsheet tells me that it would be a few more percent resource efficient to do it in that odd way. ^^
Post Reply

Return to “General discussion”