Search code examples
pythonmathematical-optimization

Optimization of list of numbers with given cost python


Lets say I have investments:

a)Cost = $10; Projected return = $20
b)Cost = $8; Projected return = $12
c)Cost = $6; Projected return = $19
d)Cost = $4; Projected return = $8
e)Cost = $2; Projected return = $15

Is there some sort of algorithm or math system that can optimize the return with a given amount of money to spend? For example get the highest returns while spending $18? I need this for a much larger and variable set of numbers. So if someone could point me in the right direction that would be great. I will be using python.

Note, I do not need anyone to solve the thing above.

What do you even call this sort of stuff so I can research it


Solution

  • This is the knapsack problem, specifically an 0-1 knapsack problem. It is NP-hard.

    You also will likely want to research Dynamic Programming.