I was wondering if it is possible to get the active constraints of a linear program from the Python API of Cplex? Or do I have to go through the constraints one by one and check if they bind with equality for the current solution?
1 Answer
Just look at the basis status of the rows. Non-basic means binding.
-
$\begingroup$ Thanks! I managed to find the method
cplex.solution.basis.get_basis()
. Should I usecplex.solution.basis.get_basis()[1]
, and those that are 1 correspond to active constraints? $\endgroup$– ElenaJun 24, 2022 at 14:44 -
$\begingroup$ I agree that nonbasic implies binding, but what about slack variables that are basic but equal to zero? $\endgroup$– prubin ♦Jun 24, 2022 at 15:28
-
1$\begingroup$ @prubin. Then use my favorite approach: do some hand-waving. My number two solution: define binding as being non-basic. Number three: assume non-degeneracy. Last resort: do more checking (basic rows only). $\endgroup$ Jun 24, 2022 at 17:00
-
$\begingroup$ @ErwinKalvelagen I vote for your last resort. Re your favorite approach, hand-waving is legally reserved for academics. (I believe the EU has a law to that effect; in the US, it's just accepted practice.) $\endgroup$– prubin ♦Jun 24, 2022 at 17:45
-
$\begingroup$ @prubin I am usually way sloppier. I often just look at the dual. $\endgroup$ Jun 24, 2022 at 20:15