I need to use linprog
for an optimization (minimize
takes far too much RAM), but I need to add a relatively complex constraint that can't be represented by a matrix. Is there a way to use minimize
with a linprog
-like solver that doesn't use a large amount of memory? Or is there a way to implement a custom function within linprog?
Here's an example of what I would like to do:
# inequality constraint
cons = lambda x: sum(x) - 1000
bounds = [(0, 1) for _ in enumerate(solution_length)
coefficients = # coefficients here
results = scipy.optimize.minimize(coefficients, cons=({"ineq": cons},), bounds = bounds)
or use scipy minimize with a matrix of size 10,000,000+ for a linear problem without solving with a nonlinear method.
Where should I start?
As the author of the functions, @MattHaberland, mentioned, there is no way to implement a custom callable within linprog
or milp
. I was eventually able to reimplement multiple iterations of linprog
to solve my problem (thanks @NickODell), but if a function absolutely needs a custom callable, minimize
is your best bet.
For more information on solving complex linear programming problems, here is a Wikipedia article on one of the most fundamental problems, the travelling salesman: https://en.wikipedia.org/wiki/Travelling_salesman_problem