opencobra / optlang

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

Gurobi interface will throw a Gurobipy error if reduced costs and/or shadow prices are accessed on a MIP #258

Closed Palaract closed 9 months ago

Palaract commented 10 months ago

While discussing an issue I found with Cobrapy, it was decided that adding MIP detection in the gurobi interface and updating the reduced costs and shadow prices methods to return a proper error would be beneficial. This is also because both parameters in the form of the attributes Pi and RC are not well-defined for MIPs, for more information see the gurobi documentation and articles:

  1. https://support.gurobi.com/hc/en-us/articles/360034305272-How-do-I-retrieve-the-dual-Pi-values-for-a-MIP-problem
  2. https://www.gurobi.com/documentation/current/refman/pi.html
  3. https://www.gurobi.com/documentation/current/refman/rc.html#attr:RC

The IsMIP attribute is also available since at least version 8.0 of gurobipy, so it shouldn't pose a problem regarding backwards compatibility. This issue is just the reference point for the pull request I will make later.