#How do I evaluate costs of items/recipes
1 messages ยท Page 1 of 1 (latest)
the first approach that comes to mind is going bottom up from I assume your computed dag
I do something similar in https://mods.factorio.com/mod/tech-tree-trimmer where I have to go through the entire tree layer by layer
well the cost obviously depends on the recipe you use
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
Yeah, that's part of the problem ๐ฆ
I would say if something is cyclic, ignore all of it if there's another way to make the thing
perhaps look at something like Factory Planner
Wait code, were you a moderator before? This feels recent
Ooh nice!
there appears to be an excess of yellow in this chat at the moment
I say not enough
Yeah helmod
YAFC too
And the uh, website
I forget its name
Parsing through the code is hard though
Oh and foreman2
So many
wait, why is it a DAG?
I previously claimed to have "unwrapped the cycles"
Via some linear algebra techniques that didn't pan out
Or, at least, panning out is more nontrivial than I thought
AB's percentage-based purification steps come to mind
Recipes should be the only offenders though, right?
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
Yeah, percentages aren't too hard. I guess you need some extra information to really calculate costs, though, not just the graph structure
what about situations in which you have a "tool" that may or may not break on each use?
Same percentage, just need to average out over time
I guess you could figure out some way to convert that into the same decimal format, yeah
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.
Oh nice found https://kirkmcdonald.github.io/posts/calculation.html
Oh gosh the factory planner implementation is 1,000 lines of code... Nooo. There must be an easy way with some assumptions?
nope
For vanilla Factorio you could make some assumptions, but not with mods
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...
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".
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
Ah, I thought you were just saying it was a tool, not the actual problem
Like, to fully solve it in the general case is equivalent to solving a pretty general form of linear programs
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
ye exactly lol
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
at what point are you planning on randomizing?
In theory you could calculate the costs at startup time if the randomization occurs then
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)...
- Things like space constraints or other properties not describable in the dependency graph structure don't really matter
- 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
- We will only really be asking problems of the form "create this linear combination of items/fluids using the fewest recipes possible"
- Needing to simultaneously technology costs
In terms of weakening these restrictions...
- 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.
- 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).
- 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.
- 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.
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
Some notes:
- LP is solvable in polynomial time worst case (just not with the simplex algorithm). The algorithm that solves it this way is actually slower in practice, which is why you may not have heard about it.
- I was talking about ILP, the integer linear programming problem. This is notoriously hard, even in practical cases (though an approximation here would be aight).
The dependency graph is easy to build, so we might as well just do that up front.
Oh, LP isn't LP, huh. Wonder why I thought it was...
Hm? You mean ILP isn't LP? I mean integer linear programming btw.
I meant LP isn't NP-HARD, but typed with brain fog from illness
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 ๐
I'm looking into lua LP solvers and all I can find is this: https://github.com/geoffleyland/luasimplex
It looks fine, but I have no idea what all the variables mean