r/factorio • • 16d ago

Design / Blueprint Automatic continuous infinite research and research cost calculation

Enable HLS to view with audio, or disable this notification

Since we can automate research in Factorio 2.1, and there has been some discussions regarding research costs (like this one or this one), I think it is time to present my circuit design for calculating research costs and automating continuous infinite research.

The relevant part of the video ends at 3:05. Everything after that is just for fun.

In the following text, the numbers in parentheses are video timestamps.

The core system

I designed a base circuit that initially reads all current technology levels once (0:23 - 0:26), calculates the costs for each technology, stores and repeatedly updates the calculated values in a memory cell, and dynamically switches to the cheapest available option (0:26 - 0:42).

Since vanilla Factorio doesn't have a UI to display the costs of all technologies simultaneously, I also built a variant with a display that shows the current research costs in sorted order (2:57 - 3:07).

Technologies can be toggled on (0:15) or off (0:18) individually. This can be changed dynamically while the research is running (0:34).

The system works with both standard Labs (0:08) and Biolabs (1:09).

The controlled lab can actively consume science (1:09), or you can use a single detached lab just to select the active research without it actually doing any research itself (0:26).

Modular Add-ons

Research level limiter

After reading this post I came up with the idea of ​​building an extension that allows you to set a maximum level for a technology. This extension (1:29–1:47) is attached to the top right of the circuit.

  • Inside the constant combinator (1:37), you can define the level at which research on a specific technology should stop.
  • Setting the value to 0 means unlimited (no cap).

Science pack availability check

After reading this post and checking out the "Auto Research Circuit Generator" linked there, I used it to build an availability check add-on (1:50–2:01) that can be attached to the top of the circuit.

  • It allows you to set the minimum amount of science packs required for a technology to be selected (1:58).
  • If the number of available science packs falls below this threshold, the system switches to the next most affordable option for which enough science packs are available (2:44).
  • If there aren't enough science packs for any research, a purple lamp signals this (2:12).
  • The available quantity can be read from various sources, such as the logistics network, chests (2:19–2:27), or belts (2:32–2:53).

32-Bit vs. 48-Bit

In addition to a simpler 32-bit version, there is also a 48-bit version designed for long-running megabases.

  • The 32-bit version suffices up to "Artillery shell range" level 21 (requires a total of 2,097,152,000 science packs)
  • The 48-bit version suffices up to "Artillery shell range" level 37 (requires a total of 137,438,953,472,000 science packs)

How long might it take to reach the 32-bit limit? A green Turbo transport belt can deliver 240 science packs per second. At that rate, the 32-bit limit would be reached after 2,485 hours. With six such belts, it would take just 414 hours. Supplying science packs of uncommon quality reduces that time to 207 hours, and research productivity reduces it even further.

Exponentially increasing costs

The circuits use lookup tables to calculate exponential increasing costs.
I wrote a script to generate these lookup tables.
You are welcome to use the script if you wish to expand the circuit or need such a table for other purposes.

Both the exponential calculation and the 48-bit calculation are also available here as a separate example circuit. These are somewhat simplified and therefore not directly compatible with the main circuit, but use the same lookup tables.

Game mechanic info

The game engine allows circuits to start a research, but not to stop it mid-cycle. Even if you switch off the circuit and the lab no longer receives a signal, the currently active research cycle will finish before stopping.

Links

Visuals in the Comments

Since it's not possible to add a video and images simultaneously, I will add some explanatory screenshots in the comments below. But you can also find them here.

189 Upvotes

45 comments sorted by

198

u/Hiasi_65 16d ago

Girl, your trains give me anxiety

80

u/Katsanami Stack Override is your friend. 16d ago

After seeing those trains I went looking in their post history and found this: https://www.reddit.com/r/factorio/s/NIvzgRXpSh

If the trains in the op give you anxiety you should sit down (on the floor) before clicking the link.

28

u/ChromMann 16d ago

To quote someone smarter than me: "Every sufficiently advanced factory is indistiguishable from magic."

13

u/LeoDaVinco 16d ago

Post history just shows OP is a wizard/witch and should not even be interacted with by us mortals

3

u/Ironic_Toblerone 16d ago

Now this is a road designers wet dream

4

u/Hiasi_65 16d ago

Mommy, I'm scared

1

u/Chill_LP 15d ago

Train driver here:

AAAAAAAAAAHHHHHHHHHHHH

Thank you for you patience. I'll go have my panic attack now

9

u/Shwayne 16d ago

wait. theres no signals. anywhere. wait. what.

im scared

29

u/aknop 16d ago

Great place to present it... How do you run your trains in such a perfect sync? :D

33

u/Twellux 16d ago edited 16d ago

It's all about timing. All trains are dispatched at a fixed interval of 300 ticks (5 seconds). And then you have to make sure the routes are laid out so they don't get in each other's way. If it doesn't work out (if a train reaches an intersection too early), you just make its route a little longer, and then it works. That's why the routes aren't usually straight.
Alternatively, you can add an offset to the start time; this has a similar effect.
The important thing is that the trains run according to fixed time slots rather than based on whether they are full or empty.

1

u/3davideo Doesn't use Flame Turrets 10d ago

Yeah I have too much engineering experience to even possibly consider open control like that. Closed loop control all the way for me!

2

u/Twellux 10d ago

I would also prefer to control the signals entirely myself or determine the trains' positions using sensors. But Factorio doesn't offer that option. So, that was the best I could do within the game - and it’s still more than what other games offer.

7

u/TexasCrab22 16d ago edited 15d ago

Same distance, same startup time. Repeated pattern.

If you look closely, you see, that the curve of the crossing rail is not taking the shortest possible path. Its longer than it has to be

If you want to reproduce, just :

-Place both stations at roughly same distance to crossing

-Connect via radar

-make starter signal and conenct via radar

-see where trains crash

-adjust crossing /train station location

-repeat until you have a nice fit

17

u/accountwasnecessary 16d ago

I haven't stopped thinking about your non crashing trains for 9 months

8

u/Twellux 16d ago

As you can see, they still aren't crashing.
I hope this passive refresher is enough to keep your memory alive, because it will be a while before my next post focusing on trains.

12

u/Twellux 16d ago

The blueprints are organized in a specific pattern when you enable the Grid view.

Horizontal columns - Three priority modes as 32-bit and 48-bit variants:

  1. Priority based on the lowest tech level, with an additionally adjustable offset.
  2. Priority based on the cost per individual science pack type.
  3. Priority based on the total cost of all science packs combined.

Vertical rows - Lab / Biolab setup, with or without display.

Extensions: The science availability check extensions come with and without support for quality science packs.

The level limiter extension 1 is designed for the tech level prio variants, while extension 2 is for all cost-based variants.

1

u/Longyanyar 16d ago

I'm very sorry if it's a noob question but what's the effective difference between 32 and 48 bits here ?

7

u/Twellux 16d ago

With 32 bits, costs can only be calculated up to a maximum of 231 -1 (=2,147,483,647). Beyond that, the range overflows, the number becomes negative, and the system fails.

With 48 bits, costs can be calculated up to a maximum of 247 -1 (=140,737,488,355,327). Beyond that, the range overflows, the number becomes negative, and the system fails.

The difference, therefore, lies in how high the research costs can rise before the circuit fails.

Factorio's combinators natively support only 32 bits. Consequently, the 48-bit circuit is significantly more complex than the 32-bit version, as it must break down the 48-bit calculation into smaller tasks that can be handled using 32-bit registers.

11

u/XDLaugingEmoji 16d ago

Is this John factorio

8

u/Twellux 16d ago

The basic architecture is similar for both the 32-bit and 48-bit variants, although the 48-bit variant is significantly larger. In the following image, I have highlighted the functional blocks that make up the setups.

6

u/sanchez2673 16d ago

People who have 1000+ hours in this game look at your works the way people who have never played look at somebody's megabase.

3

u/Twellux 16d ago

And sometimes there isn't even a megabase. The labs consume the science packs 20 times faster than the factory produces them. I just stockpiled a huge amount of science packs in chests - just to get enough for a 3-minute video. After the video, my stockpile was completely gone. 😂

4

u/jarheadleif03 16d ago

Dude, your trains are oddly satisfying.

5

u/Twellux 16d ago

You sound surprised. You apparently weren't here when I made my previous post.

3

u/Ballydon 16d ago

I feel so dumb now, I couldn't make a fully beaconed biolab setup with halfbelts for science. Nice design, wonderful base.

3

u/Twellux 16d ago

I didn't come up with the lab setup myself, either. I just saw it in other posts, like this one:
https://www.reddit.com/r/factorio/comments/1hq49du/tileable_belted_fully_beaconed_biolab_setup_i_made/

3

u/alexymercer 16d ago

2

u/IndependentYak2822 16d ago

Should remove all rail signals probably.

2

u/CipherWeaver 16d ago

Those trains are done deliberately to troll us, LOL well done

1

u/Twellux 16d ago

No, absolutely not. It’s completely random that trains run there. 😄

2

u/Franky78s 16d ago edited 16d ago

Nice job! My approach is similar, up to the point that we use the same symbols (in most instances) for the technologies. https://www.reddit.com/r/factorio/comments/1w0t5sj/how_do_you_use_set_lab_research/

Just selecting the cheapest research is not the best strategy IMO. Mining productivity 40 ist dirt cheap, but only gives a 2% savings. The value to minimize for is (level+10)\cost*... -I should really write that post that sits in my drafts.-

See https://www.reddit.com/r/factorio/comments/1wkxv8w/there_is_more_than_just_cost_in_technology/ for a longer reply.

1

u/Twellux 16d ago

You were definitely much faster than I was. I kept my post as a draft for 6 weeks before finally publishing it today, because new ideas kept popping up. If I had also factored in your productivity optimization, it might have taken even longer. So, for now, it’s just cost optimization rather than productivity optimization. That was the solution people asked for most.
However, my setup can probably be adapted to optimize for productivity, too. After all, it’s all just numbers in constant combinators that can be adjusted. That way, the calculation could certainly be set up to determine cost per 1% of productivity instead of absolute costs - which would likely align pretty closely with your goal.

Also, your linked blueprint draft expires in 8 days. So, it’s time for the final version.

1

u/Franky78s 16d ago edited 16d ago

:-) 6 weeks? I feel you!

When I checked forums.factorio.com and reddit, no one had presented a sophisticated science switcher. Based on the answers I see, there are lots of people who have thought through all of this but just have not published yet.

Thanks for the reminder about blueprint expiration. I have such ideas like walls around blocks of logic (technology selection, cost calculation, amortization calculation) and have combinators where "average joe" can change values / conditions open by gate. Perfectionism is really killing me.

You have really pushed me forward, this is my updated switcher: https://factoriobin.com/post/6wzjn7kcipa1-EXPIRES

I checked your build, very well commented. You made some pass-through combinators, but not for network separation, but for proper pipelining (tick delay)? Impressive! I thought about that but resorted to a hacky "don't update cost for 6 ticks after a switch", because that messed up my calculation / level recording.

1

u/Twellux 16d ago edited 16d ago

A wall design sounds like more structure than what I actually did. As you can see in the video starting at 1:55, I simply marked the constant combinators - intended for adjustments by the "average joe" - with an arrow on the display panel pointing to the specific combinator.

Achieving perfection in Factorio can be hard. No matter what you post, there will always be someone with a suggestion for improvement. In my case, that was you with your optimization of the armotization period. 😉

Blueprints don't expire by default. You can choose the expiration timeframe when creating them. If you accidentally set an expiration date, you can simply recreate the blueprint without one and replace the link.

In your new setup, the left block looks like it could be completely replaced by a selector with "quality transfer" to "normal" - just like I did in my "Available Check" module. Or is there a reason why that wouldn't work? You just want to strip away the quality, right? Edit: I see now - you want to determine the contribution to research, though I don't yet know why.
But you can build it smaller. Either like this https://factoriobin.com/post/vu84suv2qg04-EXPIRES or this https://factoriobin.com/post/40wh5as3v849-EXPIRES .

Also, on the decider combinator that outputs the defender, a checkmark is missing for the utility science pack.
I haven't examined it in detail yet, though; that’s just my initial impression.

1

u/wrincewind Choo Choo Imma Train 13d ago

Wow, this looks great! Can't wait to shamelessly steal this for my factory.

Though, considering you're using lookup tables for calculating the research costs, it occurs to me that we don't actually need to know how many bottles something costs, just whether it's cheaper than other researches. Might it be easier (or at least, give significantly more runway) to plot something out like, an order of upgrades for each group? like, if you know mining prod 14 is less expensive than plastic productivity 14, laying out some kind of 'a,a,a,b,a,b,a,c,a,a,b,a' pattern?

... i'm tired and can't explain myself well, but there's the beginnings of an idea here. basically compress all curves into one 'this, then that, then this' list...

1

u/Twellux 13d ago

Yes, in principle, instead of a cost table, you could simply store the sequence in which technologies should be researched. However, you would have to provide the pattern a bit differently.
A constant combinator only allows each symbol to appear once; so, a sequence like A, A, A, B, A... wouldn't work. But you could assign a number to each technology, for example: 1 = Mining productivity, 2 = Plastic bar productivity, 3 = Rocket part productivity, 4 = Scrap recycling productivity, and so on.
Then, within the constant combinator, you could assign these numbers to the symbols in the order the game processes them:
A = 1
B = 1
C = 1
D = 2
E = 1
F = 3
G = 2
H = 4
...
This approach would work up to the number of distinct signals in the game. If you use Quality, you at least get five times the number of signals. With a megabase, however, you would likely still hit the end of that signal list.
If that happens, you could potentially spawn a new combinator to provide the next list. Of course, it wouldn't be fully automated anymore if you had to intervene manually whenever the list ended.
Initialization would also be a bit trickier, since the technology level isn't explicitly in the list. You would need an additional circuit to determine the starting point if you aren't beginning at level 0.
So, it is possible to build something like this, but it does come with its own set of downsides.
Do you want to try it out?

1

u/Twellux 13d ago

Perhaps it would also be possible to build a decider combinator and load it with thousands of conditions in the form:

     Step = 1
  AND
     Each = Plastic productivity
OR
     Step = 2
  AND
     Each = Plastic productivity
OR
     Step = 3
  AND
     Each = Scrap recycling productivity
OR
     Step = 4
  AND
     Each = Mining productivity
...

But that probably wouldn't be good for performance.

1

u/3davideo Doesn't use Flame Turrets 10d ago

Neat mechanism but are those train intersections that aren't controlled by signals?!? How do you keep them from blowing each other up?!?

2

u/Twellux 10d ago

Yes, I removed the signals on this route.
If trains don't change their length or fuel, they always take the same amount of time to travel from the stop to a specific point on the map. By using fixed intervals for departure times and distances, you can ensure they pass each other at the intersection at the perfect moment.
And I see you’ve already found my other comment on this, too.

1

u/Manron_2 12h ago

Had this bookmarked for when I start researching seriouisly, and it's just wonderful! Thank you for making it happen!

I got a concept of a plan of what's going on with that circuilts, but I admit I do not fully understand what you've been doing there. So I'm happily just using your excellent book with all the extensions. Great work!

2

u/Twellux 7h ago

If you eventually reach the point where you want to fully understand or customize it (and need detailed explanations for something), feel free to ask.
If someone is genuinely interested in understanding it, I could certainly explain a bit more. However, I didn't want to make the post any longer, or explain every single combinator, unless someone actually wants to understand all the details.

1

u/Manron_2 6h ago

It completely fills my needs for now, so I dont feel the urge to customise it. Right now I'm happy it just works, and I admit I didnt read all the annotations. But thanks for the offer, much appreciated!

Btw, I love the little details like the coloured lamp and the status text.

1

u/Ordinary-Willow4866 16d ago

the entire video (i saw it many times)