Rybadour / Foreman

Visual planning tool for the game Factorio
Other
21 stars 7 forks source link

Tweaks to LinkUpAllInputs algorithm #34

Open riking opened 4 years ago

riking commented 4 years ago

https://github.com/Rybadour/Foreman/blob/master/Foreman/Models/Solver/ProductionGraph.cs#L93-L106

Proposed:

Part of #29

riking commented 4 years ago

If someone wants multiple outputs routing to a single input, they can hook that up manually, let's not do it for them.

Rybadour commented 4 years ago

Not sure if you've made any progress on this issue but I have the motivation to start looking into it.

Here is a note a left on the duplicate issue I created:

Note there are some huge difficulties in generating a reason graph when dealing with the other complex mods. But also when dealing with items like light oil that have multiple different recipes.

Ideally, we should choose recipes based on the player's technology level but in the meantime the best we can do is choose the first one and make it easier to change the recipe.

Rybadour commented 4 years ago

Added a step "Check if the item is a "resource", if so create an infinite supply node." so we avoid using recipes that produce raw resources as a sort of by-product. (Ex. Bobs/Angels/Seablock has several recipes that produce water).

Rybadour commented 4 years ago

FYI: I created a new branch with some of the work I did as a first pass to solving this problem: https://github.com/Rybadour/Foreman/tree/rybadour/graph-gen-revamp

The steps are easy to implement but choosing the correct recipe is going to be a very challenging issue. We might have to go as far as asking the user which recipe to use...

Rybadour commented 4 years ago

Thoughts: The first approach I'd take to "ordering recipes" would be to choose the one that produces the smallest graph. For example, Ammonia in Bobs/Angels need hydrogen gas and nitrogen. The smallest graph would be compressed gas and basic slag processing.

Although we also might want to prioritize recipes that have no by-products. In the above example we might want to avoid slag processing as it produces slag and oxygen as well.

riking commented 4 years ago

I think it's fair to continue to assume by default maximum tech, for now, and let recipe substitution happen by deleting the old generated nodes and leaving an unconnected node of the recipe you want.

To say it another way: the first recipe to pick should always be one that's left unconnected on the graph (at the time the button was pressed? Tricky).

Rybadour commented 4 years ago

left unconnected on the graph

Not sure I understand. We have to pick a recipe to create. If we get to that step that means we didn't find this item on the graph at all.

I was thinking about this last night it would be trivial to generate a value for each recipe called "smallest sub-graph size". It's a fairly straightforward algorithm that checks it's inputs for all valid recipes and sorting them by their smallest sub-graph size. It just needs to recursively evaluate all recipes. We can do this after all mods are loaded so it's pre-computed.