emilyploszaj / emi

A featureful and accessible item and recipe viewer
MIT License
220 stars 46 forks source link

[Feature Request] Tree of production (not only crafting dependency) #542

Closed AlaronFV closed 1 month ago

AlaronFV commented 1 month ago

I have created some example python code that can generate best production tree for give requirements (resource, amount, needed time, etc.). It create tree of machines and tell that for given time requirements the best amount of instances of each machine is so. Example code is: https://github.com/AlaronFV/Production_Lines

emilyploszaj commented 1 month ago

What you're asking for here is unclear, but the things I can grasp seem out of scope for the information provided to EMI. If you can better explain what you're asking for and it makes more sense, I can reopen this issue.

AlaronFV commented 1 month ago

Ok, things are so. It is the same thing as crafting tree generated by EMI. But it generate not only the amounts of resources for each node, but also if to automate this crafting tree, how many machines (methods) one need to place for each node of crafting tree for given time requirement.

To do that it firstly, from all recipes, create recursively crafting tree with every possible method to generate some resource. And for each sub-tree (input resource for machine) in each method, we creating other bunch of methods, and so on until reaching either no recipe for this input resource or loop.

Then, it, from that resulted recipes tree, generate all possible lines of machines, as to handle all possible ways (in given recipes) to craft needed resource.

Then in uses minimize from python's lib scipy module optimize, to to create best amount of instances of each machine in a production line, by adding or subtracting from initial amount (1) of machines (or at least i think it works so) and runing the simulation for given line of machines, with objective to find such Ms (list of amounts) that total amount of steps (until needed amount of needed resource in last machine is reached) will be nearest to given time requirement.

After that it make these Ms to ints as they can be floats, but we can't have 1.5 machine, thus we have to check 1 machine and 2 machines and choose the variant with nearest total amount of steps to given time requirement. And so for each line of machines.

And that is all. It get 5 lines with nearest total steps to given time requirement, and then give it in form of Obsidian canvas, but it can be do by any other way.

All is needed to make it work, is list of recipes with such structure as in given repository, but basically main things are:

The exact code in repository might not even work, at least it worked and generated such trees, but i didn't test it much, and basically it just need to give an idea what to do and how to do it. There are some images of nodes in Obsidian canvas it've generated for generating cobblestone (images i've created by myself and the code is just accessing them) (i created recipes manually, so as it is too troublesome to extract recipes, parse them, and so on to make such program usable, and because i'm too lazy, I'll just give that code and ideas to someone, who can utilize it). image image image image