#How do I evaluate costs of items/recipes

1 messages ยท Page 1 of 1 (latest)

stoic kelp
#

I know some calculators already do this, and have been analyzing some of their code, but am having trouble wrapping my head around it atm. Assuming we have costs for some raw resources, how do we determine the "cost" of an item (assuming we have fixed which techs we have access to as well).

#

I always thought of it as "just linear algebra" but I guess there's more to it.

twin ember
#

the first approach that comes to mind is going bottom up from I assume your computed dag

junior meteor
#

well the cost obviously depends on the recipe you use

stoic kelp
#

Yeah dag is computed, but unwrapping cycles is something I'm stumped by at least for now, so it's not even acyclic atm

#

I know I said I unwrapped them before but it turns out my solution wasn't as solution-y as I thought

stoic kelp
twin ember
#

I would say if something is cyclic, ignore all of it if there's another way to make the thing

junior meteor
#

perhaps look at something like Factory Planner

stoic kelp
#

Wait code, were you a moderator before? This feels recent

twin ember
stoic kelp
#

Ooh nice!

junior meteor
#

there appears to be an excess of yellow in this chat at the moment

twin ember
#

I say not enough

stoic kelp
#

Maybe we should make it worse ๐Ÿ˜›

#

Anyways, I'll take a look at factory planner

junior meteor
#

there's the other one too

#

Helmod

stoic kelp
#

Yeah helmod

#

YAFC too

#

And the uh, website

#

I forget its name

#

Parsing through the code is hard though

#

Oh and foreman2

#

So many

stoic kelp
#

Via some linear algebra techniques that didn't pan out

#

Or, at least, panning out is more nontrivial than I thought

junior meteor
#

AB's percentage-based purification steps come to mind

stoic kelp
#

Recipes should be the only offenders though, right?

twin ember
#

percentages can pretty much be converted directly into decimals

#

like 50% chance to smelt ore into iron, that averages out to 0.5 iron per craft

stoic kelp
#

Yeah, percentages aren't too hard. I guess you need some extra information to really calculate costs, though, not just the graph structure

junior meteor
#

what about situations in which you have a "tool" that may or may not break on each use?

stoic kelp
junior meteor
#

I guess you could figure out some way to convert that into the same decimal format, yeah

stoic kelp
#

Anything more gets into fine-grained territory that makes some of the assumptions of using a calculator in the first place irrelevant

#

It would be interesting to have "payoff times" though, I suppose. Pyanodons for example, requires an expensive first product and then after that feeding the cycle costs less. Even there though, the "first cost" becomes irrelevant fairly quickly.

stoic kelp
#

Oh gosh the factory planner implementation is 1,000 lines of code... Nooo. There must be an easy way with some assumptions?

twin ember
#

nope

urban ruin
#

For vanilla Factorio you could make some assumptions, but not with mods

signal tartan
#

If you actually want to figure out which recipe choices are best in a large enough network, you probably need to use some kind of gradient descent or some kind of probabilistic method.

#

simulated annealing was the name I was looking for

#

I wonder if simulated annealing would work for the whole problem, actually...

winter shell
#

The answer is "not easily". The problem is largely finding out what "costs" something and what is free. YAFC is the closest people have made, but even that pulls arbitrary values for "costs".

stoic kelp
#

Was just thinking about it and essentially it's just a linear program right?

#

Like, I knew this was a tool that could be used to calculate the costs in various situations, but it seems like the recipe/item structure is just exactly a linear program

urban ruin
#

Isn't that what I've been saying? Hahaha

#

I guess only in DMs huh

stoic kelp
#

Like, to fully solve it in the general case is equivalent to solving a pretty general form of linear programs

urban ruin
#

Well, in any case I think that is exactly correct

#

The problem is, lp solvers are often slow, and no one has found one fast enough to run inside a mod

stoic kelp
#

I wonder if you could precompute some stuff in data stage (where 1-2 second loading times are okay and can do as much as a 10-20 second computation in control) that you then use to speed up in-game solving

urban ruin
#

at what point are you planning on randomizing?
In theory you could calculate the costs at startup time if the randomization occurs then

stoic kelp
#

Oh I'm randomizing at startup time

#

It's not an issue for me ๐Ÿ˜€

#

I was just pondering if there were a way to make helmod or factory planner devs' lives easier

#

I have basically the easiest use case for this, since I only need to calculate individual item costs once, and I can do it in data stage. Helmod and factory planner need to do this on the fly throughout the game with pretty much no lag.

#

Note that this "realization" also assumes that costs can be completely determined by the dependency tree. In general, I claim that the following aren't even a concern (for the most part)...

  1. Things like space constraints or other properties not describable in the dependency graph structure don't really matter
  2. The program of crafting whole-number quantities of some given items using whole-number quantities of recipes (i.e.- the ILP variant) is not super relevant
  3. We will only really be asking problems of the form "create this linear combination of items/fluids using the fewest recipes possible"
  4. Needing to simultaneously technology costs
#

In terms of weakening these restrictions...

  1. I really don't see any case where something we want to account for can't be coded in as another constraint/part of the cost function.
  2. This could be useful, but unless ILP solvers miraculously happen to work fine for most of the use cases in factorio, it's just gonna be incredibly complicated and slow (ILP is NP-complete, i.e.- not quickly solvable).
  3. This is essentially what a solver is for, right? And in my case, figuring out costs should just need the same things? Well, there's also "how much do the first few cost versus the last few", I wonder if there's a good way to calculate that.
  4. I do wonder about this. Of course, technology costs don't need to be automated, but taking those and the building costs into account along with (3) or an imposed time limit seems like an interesting problem in order to make the solver more realistic.
indigo junco
#

NP-COMPLETE is a property of the worst case, and the typical case is often polynomial time for common LP solvers like the Simplex Algorithm (though worst case time for the Simplex Algorithm is exponential time)

#

but if you're building the dependency graph as you calculate things, you'd be able to calculate an upper bound on the cost of all recipes

stoic kelp
stoic kelp
indigo junco
#

Oh, LP isn't LP, huh. Wonder why I thought it was...

stoic kelp
indigo junco
#

I meant LP isn't NP-HARD, but typed with brain fog from illness

stoic kelp
#

Ah

#

I mean, simplex is exponential worst case and that's the go-to algorithm, so it's not too off to think that it is

#

LP is actually a "hard for P" problem in many senses actually

#

So it's still pretty hard ๐Ÿ˜›

stoic kelp
#

It looks fine, but I have no idea what all the variables mean