2
$\begingroup$

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?

$\endgroup$

1 Answer 1

3
$\begingroup$

Just look at the basis status of the rows. Non-basic means binding.

$\endgroup$
6
  • $\begingroup$ Thanks! I managed to find the method cplex.solution.basis.get_basis(). Should I use cplex.solution.basis.get_basis()[1], and those that are 1 correspond to active constraints? $\endgroup$
    – Elena
    Jun 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.