I am exploring optimisation solutions in python. I have list of values
list and total
.
>>> values = [5100, 5000, 4900, 2000]
>>> total = 12000
What I need to do is to select values in a way when sum of them will be more or equal to total. Solution I expect here is list with selected values, [5100, 4900, 2000]
as sum of that values is 12000.
I tried to solve exercise with gekko
model, it provides me different solution.
>>> from gekko import GEKKO
>>> model = GEKKO()
>>> x = model.Array(model.Var, len(values), lb=0, ub=1, integer=True)
>>> model.Minimize(model.sum([value * x[i] for i, value in enumerate(values)]))
>>> model.Equation(model.sum([value * x[i] for i, value in enumerate(values)]) >= total)
<gekko.gekko.EquationObj object at 0x10972d790>
>>> model.options.SOLVER = 1
>>> model.solve()
>>> [value for i, value in enumerate(values) if x[i].value[0] > 0]
[5100, 5000, 2000]
The result of Gekko model provides total sum 12100. If it is that inaccurate on 4 values list, I suspect it will work randomly on the 1k or 10k values. Wondering can I tune gekko
model or you can suggest alternate solution?