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 1


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 use cplex.solution.basis.get_basis()[1], and those that are 1 correspond to active constraints? $\endgroup$
    – Elena
    Commented 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
    Commented 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$ Commented 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
    Commented Jun 24, 2022 at 17:45
  • $\begingroup$ @prubin I am usually way sloppier. I often just look at the dual. $\endgroup$ Commented Jun 24, 2022 at 20:15

Your Answer

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

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