opencobra / optlang

optlang - sympy based mathematical programming language
http://optlang.readthedocs.org/
Apache License 2.0
248 stars 51 forks source link

[feature request] absolute values in linear programming #142

Closed pstjohn closed 2 years ago

pstjohn commented 7 years ago

I know this is listed on the 'future work' section of the readme, but I'll echo support for this feature. It would be great to port code like the following from cobrapy to optlang eventually

https://github.com/opencobra/cobrapy/blob/17b5b77494c3bacd6b51419e681530800ec8013a/cobra/util/solver.py#L324-L368

KristianJensen commented 7 years ago

That's a pretty cool trick. In most cases I think the same can be achieved without adding a new variable, but conceptually this makes it simpler. I would not be opposed to having a suite of utility functions (separate from the current util module which is mostly low level internal stuff) to perform things like this.

cdiener commented 7 years ago

The variable is only created because this allows you to use it in the objective expression which is the use case we have in cobrapy. The limitation with that method is that it only works for minimization problems and will fail completely when used for maximization where you need a MILP formulation to achieve absolute values.

pstjohn commented 7 years ago

Good call! although that's probably a use case that's fairly common.

https://optimization.mccormick.northwestern.edu/index.php/Optimization_with_absolute_values

In particular, one problem I'm dealing with now is related to the method they used in this paper, which essentially does quadratic programming to find the most likely flux distribution together with FVA to find feasible regions for those fluxes.

With the current optlang, doing FVA is tricky since optlang doesn't support a quadratic constraint (i.e., holding the QP-objective at a constant value) while maximizing/minimizing other reactions. And so I was considering using absolute values with @cdiener's method. Although I'm not sure that translates well between objective and constraint.

KristianJensen commented 7 years ago

You should be able to use this method for what you describe. When you minimize an absolute value that can be translated to an upper bound constraint, which is also valid with this implementation.

A function that constrains lower bounds on absolute values would be another good candidate for a utility module.

cdiener commented 2 years ago

Closing for now since we have that functionality in cobrapy now.