Assuming your model object is mdl
, when you create the constraints in docplex with add_constraint
(or add_constraints
), the generated constraint is returned and you can save that, similar to what you showed in your example.
For example:
ctr = mdl.add_constraint(x+y<=5, 'c1')
If your constraint is not saved, you can access it after the solve by ctr = mdl.get_constraint_by_name('c1')
as well.
Now, what's the value that you're after? If it's x+y
, then you're after the lhs
. So, to get that expression, you can say ctr.lhs
(Similarly, you can access rhs
using ctr.rhs
). If you want to get the value, it's like getting any other value in docplex, by accessing solution_value
. So, the value of x+y
becomes ctr.lhs.solution_value
. There might be other ways, but this is the one that I'm aware of.