The title isn't very helpful, because I'm not sure what I'm trying to say exactly. I'm sure an algorithm for this must exist, but I can't remember. Note: not a homework problem, I finished school a very long time ago.
So here's the problem:
- We're doing a shipping and trading job, trying to maximize profits
- We have a list of items that we can ship in a truck. Each item has:
- A buy price (at the source)
- A sell price (at the destination)
- A per-unit mass
- An upper limit on how many can be purchased
- Our truck is limited in the amount of mass it can carry
- We have an upper limit on how much we're allowed to "invest" (spend on items at the source).
- We want to maximize the profit for our job (buy at the source, transport, sell at the destination).
If there were only one limit (total mass, or total investment), it would be easy, but I'm not sure how to approach this when there are two.
The equation for calculating profit would be:
profit = ItemA['quantity'] * (ItemA['sell_price'] - ItemA['buy_price']) + ItemB['quantity'] * (ItemB['sell_price'] - ItemB['buy_price']) + ...
So I'm trying to choose which items, and the quantity of each item, that should be purchased in order to maximize the profit.
Are there any existing, known algorithms for solving this? Likely some sort of mathematical optimization problem? I'm using Python, so I'm thinking that the mystic package might be appropriate, but I'm not sure how I'd configure it.
You can try the framework optuna for hyperparameter tuning.
Here is an example code that you can try. Products are named product1 etc found in parameters.json file. Data values are just assumptions.
Study/optimization session are now saved in sqlite db. This will support interrupt and resume. See version log in the code.
parameters.json
Code
Output
If you increase the number of trials the program might be able to find a more profitable parameter values.