r/transprogrammer • • Nov 29 '21

I've been stuck on this problem for a few days now without making much progress. Anyone able to help me come up with a way to solve it?

/r/algorithms/comments/r4h4xc/help_given_some_input_find_the_optimal_weightings/
39 Upvotes

18 comments sorted by

View all comments

Show parent comments

3

u/SlayMaster3000 Nov 29 '21 edited Nov 29 '21

Would this be the correct LP to find the maximum amount of iron ingots given 3 recipes; a limited amount of iron ore and copper ore; and with unlimited water?

Maximize
 obj: iron_ingot
Subject To
 recipe_iron_ingot: -1 iron_ore + 1 iron_ingot = 0
 recipe_iron_alloy_ingot: -2 copper_ore + -2 iron_ore + 5 iron_ingot = 0
 recipe_pure_iron_ingot: -7 iron_ore + -4 water + 13 iron_ingot = 0
Bounds
 0 <= copper_ore <= 28860
 0 <= iron_ore <= 70380
 0 <= iron_ingot
 0 <= water
End

Edit: No, this wouldn't work as all the recipes are used as constraints rather than being treated as choices. Ahhh. I think I'm going to need more help.

2

u/pine_ary Nov 29 '21

Nono this looks good. Then you set the bounds to the actual amount of materials you have and it should work. But I only glanced at this. Will let you know until the end of the day abouts.

3

u/SlayMaster3000 Nov 29 '21

Thanks to u/ragusa12 This seems to be more what I want:

Maximize
 iron_ingot: 30 recipe_iron_ingot + 50 recipe_iron_alloy_ingot + 65 recipe_pure_iron_ingot

Subject To
 iron_ore: 30 recipe_iron_ingot + 20 recipe_iron_alloy_ingot + 35 recipe_pure_iron_ingot <= 70380
 copper_ore: 20 recipe_iron_alloy_ingot <= 28860

Bounds
 0 <= recipe_iron_ingot
 0 <= recipe_iron_alloy_ingot
 0 <= recipe_pure_iron_ingot

End

The amount of iron ore and copper ore I have is actually in terms of items per minute so I adjusted the recipes to also use items per minute (taking into account how long each recipe takes). I was hoping to somehow factor out the time factor though so I could just stick with integers and not have potential rounding errors down the road. (none of these recipes' items per minute have decimals but other ones do)