Given some input, find the optimal weightings for edges of a graph to maximize some output

I have a directed graph that describes the relationship between items (nodes) via recipes (edges).
Simple example of a recipe: 2 Iron Ore => 1 Iron Ingot.

I want to find a weighting for each recipe (that is to say the number of times each recipe should be applied) such that given some starting number of items, it produces the maximum amount of a specified item.

How can I go about finding this weighting for each recipe?

Note: All weightings must be non-negative (they can be decimal). No weightings can result in more input being required than the amount available.

That's the main problem I'm trying to solve, but following that, the next thing I want to then solve is taking energy usage into account. Each recipe will either use some amount of energy or produce some amount of energy.

How can I ensure that when finding the weightings, the energy production minus the energy consumption is non-negative?

Thanks in advance for any advice :)

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum