I code an optimization problem in python (docplex) base on here but my cut is something like that sum(X) <= N + M*sum(Y, Z)
, X, Y and Z
are decision vars. I do not know how I can pass the solution of X, Y, Z
to self.get_cpx_unsatisfied_cts([ct],
solution
, tolerance=1e-6)
.
when I use self.get_values()
, I get this Error:
Error: Internal error in CPLEX solve: AttributeError: 'list' object has no attribute '_get_var_value'
Is there anyone can help ?
Asked
Active
Viewed 795 times
1

moh jor
- 13
- 4
1 Answers
0
In the example [here] (Implementing TSP with Lazy constraint callback), callbacks are aconnected to DOcplex throught the mixin class MosdelCallbackMixin
.
This class has a make_complete_solution
method which returns a solution object (see documentation for docplex.mp.SolveSolution) from the callback internals.
In a second step get_cpx_unsatisfied_cts
returns a list of unsatisfied constraints from a given list of constraints. In your case, if you need to check only one constraint, it is simpler to use the is_satisfied
methods for constraints, which takes a solution and
a tolerance (default is 1e-6, that is:
if not myct.is_satisfied(sol, tolerance):
print(f" constraint {myct} is violated")
To summarize:
- use
make_complete_solution
to generate a solution object when callback is called - use
ct.is_satisfied
to check whether is is satisfied or not.

Philippe Couronne
- 826
- 1
- 5
- 6
-
Thanks a lot for answering and just another question, is there any useful documentation for mixin class `MosdelCallbackMixin` ? I search a lot for it but I don't find any good document. – moh jor Nov 04 '20 at 13:03
-
You're right, this class' documentation was missing. It will be documented in the soon-to-be-published version 2.16 of docplex. – Philippe Couronne Nov 04 '20 at 16:22