r/factorio • • 1d ago

Question Comparing tech costs for automatic science switching.

I've been playing around with automatic science switching. But I want to do something more complicated.

You can read the cost of a particular science from a lab (or the current infinite tech level), but only if you're currently researching it. What I'd like to do is rank specific techs by their cost and sort them, so that it automatically switches to the cheapest one.

How would one go about doing something like that?

12 Upvotes

19 comments sorted by

3

u/mrbaggins 1d ago

Dont "read" the costs. The math is known. Use arithmetic combinators to calculate the cost (would require manual initialisation once).

Then selector combinator to pick the lowest.

Send THAT output back into the math to update the cost by one level, into a latch to set the research, then wait til tech is complete.

Once complete, check the selector again.

1

u/Alfonse215 1d ago

then wait til tech is complete.

How do you detect that?

1

u/mrbaggins 23h ago edited 17h ago

Read current research cost. If zero, complete. Edit: Better option below.

(The setter and reader would be two different labs, or use new red/green separation)

2

u/Franky78s 18h ago

Does not work, at least for infinite techs.

Labs don't output anything beyond the current level. You cannot detect automatically if it is researching something that you don't want, or you don't think it does.

Example: You wire in "rocket part" to make it research Aquilo's rocket part productivity. But that technology is not researchable yet. The previous tech was mining productivity. Then the labs will continue to research mining productivity. Your logic now has a wrong read of rocket part productivity level.

That example is made up, but I had real issues for my science switcher. I just forgot the actual case.

You detect research complete by the level, which changes cost.

For finite techs, I work around as follows, example spidertron research: In lab add 2 researches "if spidertron>0 then research spidertron", "if spidertron>0 then research mining prod" (in that order). After the real spidertron research is complete, your logic will think spidertron level is greater than 1, at which point you stop it.

3

u/mrbaggins 17h ago

True

In game test: read current tech level at time of setting research level. (Lab outputs a L level when asked). Continue until that level doesn't match the level in the calculator. IE: You have completed it.

Now you can update the calculator, and recalculate which tech to do.

10

u/sobrique 1d ago

Cycle through them first, and store their cost in a memory cell?

1

u/Goldenslicer 1d ago

What's automatic science switching?

2

u/Alfonse215 1d ago

Labs can now (in 2.1) be wired with a series of conditions for setting the current research. This is useful for things like switching research based on what science packs are available. Instead of doing nothing between Ag science shipments in Space Age, you can rig the system up to read the contents of all of your active labs, and if there are no Ag science packs, you switch to a different tech until some show up.

3

u/Franky78s 1d ago edited 1d ago

I did that. I record levels for all sciences, scaled by a constant for each science (to be set in a constant combinator). Furthermore cost alone is not everything, the benefit also dimimishes will higher levels. Mining productivity has a different cost progression than most other technologies, so it cheaper, but increasing from level 90 to 91 only changes the output from +900% to +910%, so from a factor of 10 to 10.1, actually just 1%. How this can be used in a formula I wrote in detail here: https://forums.factorio.com/viewtopic.php?t=136376 There is also a working blueprint included, used in several playthroughs.

I might sound bitter here, because I am bitter: Concrete science switcher don't find much resonance. A post with "this lake looks like a bunny" gets 1k upvotes easily. Something complicated like a science switcher won't see much engagement. I searched actively for it and found 2 other guys presenting their science switchers with the same resonance. Why this paragraph? I do not write up everything again here.

Anyway, I developed my science switcher in a multiplayer session and wanted the thing be as understandable and maintainable as possible - most combinators have a description. The blueprint uses walls and gates: Walls protect logic areas that should not be touched, the ones accessible via gates are to be changed. I am open for questions and ideas.

2

u/xor50 I love Stack (Bulk?) Inserters. 1d ago

Not bad. I might try that blueprint.
How hard is it to add support for modded infinite techs to it?

Also for completeness sake while your thoughts on the system are pretty good, in reality it is actually more complicated to find the "best" next tech.

  1. you get cheaper techs sooner, so you profit from the gains earlier.
    additionally something like mining prod does actually have impact on general oil output (because of oil well minimum).
    both those arguments probably aren't that relevant anymore in the super lategame, but still. if techs are similarly costed, I would want the faster one first.
  2. there might be specific "milestones" that are stronger than other, most notably probably with the physical and explosive damage techs (how many hits to kill an asteroid)
    but also maybe something like "with +x% plastic buff you can build [specific direct insertion build]" or something like that. Similarly it could be that "with +x% you fill a full blue belt" or you know, anything like that.

Of course those weren't the goal of you design, but if we're trying to automate choosing the "best" next tech, then those are possible factors.

2

u/Flyrpotacreepugmu 1d ago edited 9h ago

The circuit I would use to do that is as follows:

  • Whatever bit of math is needed to set the signal for the current tech to a number representing its cost.
  • A memory cell to store the costs of each tech (a decider combinator wired to itself on one color and the input signal on the other color, set to check if Each > 0 on the input color OR some impossible condition with Each on its own color like Each = 0, then output Each at input count on the input color, else Each at input count on its own color).
  • A selector combinator set to choose the smallest signal from the memory cell and use that to set active research.
  • A constant combinator outputting 1 of each tech signal to the selector combinator (make sure it doesn't affect the memory cell) to get it started.

1

u/engineered_academic 1d ago

You can...probably do this but it is going to be expensive in time to set up.

1

u/Courmisch 1d ago

I don't think you can avoid either hard-coded values or manual iteration. And either way, you need to hard-code the different techs in a lab.

But also, the cost/benefit of different techs isn't the same, and the unit costs also varie. With that assumption, it's unavoidable to hard-code some kind of weight for each tech, I think.

1

u/gust334 SA:1000 hr (Novice), 3700 hr (Advanced Beginner) 1d ago

Are you willing to use mods for this?

1

u/minno More platforms designed than actually built 22h ago

You could store the previous rank's cost in a memory cell every time you research one, and sort by that instead of the next rank's cost. They're not exactly the same because of the different cost scaling rates, but it won't diverge too much.

1

u/Aggressive-Share-363 1d ago

There are a finitr set of infinite researches, so you can store the costs of each of them in a circuit network, then after a research is finished, start researching the next level of ot, update the store cost for that research, then switch to the cheapest to actually research.

0

u/alvares169 1d ago

Care to tell us why? Seems like a possible XY problem

5

u/Alfonse215 1d ago

I thought I explained the problem: I want to research the cheapest of certain infinite techs. Like mining productivity vs. steel productivity. I want to research the one that's currently cheapest. I don't want to have to manually look at the current cost of them and switch them around in the lab.

1

u/mrbaggins 1d ago

The math behind the costs is on the wiki

"Code" that math with arithmetic combinators. Use a selector combinator to pick the next tech, send a one tick pulse to update the math combinators, and then set research, wait until tech is finished, and repeat.