Search code examples
pythonoptimizationsolver

Looking for suggestion for an Optimization problem to solve with Python


Let me start by wishing you all a great start of 2023!

Mine begun with a problem that I hope to solve with a python optimizer/solver. It goes like this:

I have a list of numbers "Min_Size" and next to it another list called "Min_Increment" which represent the minum increment size that the number in the "Min_size" column can be incremented by - E.g. (tot value line 1 = (5.148 + x1 * 1.287) where "x1" (integer) represents the amount of times the first line has been increased by the "Min_Increment"). The third column represent the maximum value each line can reach (list of constraints e.g. c1 = 9.586). My goal would be to find the lines to pick (e.g 1,5,12,... and the corresponding x1,x5,x12... to use without breaking c1,c5,c12...) so that when adding them all up the final result will be between 99.99 and 100.01, all of this while trying to maximize the total value of the lines highlighted in yellow.

I'm not expecting a solution, fully aware that this would take some time to build. I'm just looking for a recommendation on the optimizer/solver to use for this type of problems. I've took a look myself but it's a vast confusing topic. It would be awesome if you could just point me in the right direction!

Really appreciate your help!

Cheers!

enter image description here


Solution

  • This is a slight twist on what is called a "knapsack problem" in linear programming. You are making selections of items with some limit on the summation and trying to maximize a total of some kind. You might try pulp as a simple optimization package to do this as it has a solver packaged with it that can handle this. There are several other packages to do this in python that you can research.... pulp is a fine place to start for a simple problem like this because you don't have to go through extra steps of installing a separate solver.

    This is a good place to start.

    Realize you would make a vector of x model variables that would be integer variables with no upper limit (the example has an upper limit of 1 for single selection), just a constraint to keep the selection below the max.

    If you get stuck, repost what you have tried in a reproducible example, and I'm sure you'll get some help.