Please, if someone can give me an example of the application of conflict refiner, I have already read the documentation but I did not understand how to use it well.
ILOG Cplex 20.1 installation comes with a directory with examples. To use the conflict refiner, you want to consult the manual which includes a list of files that contain examples on how to use the conflict refiner. Of particular interest are the following files:
./examples/src/java/ConflictEx1.java ./examples/src/cpp/iloconflictex1.cpp ./examples/src/python/conflictex1.py
Note that the last python file, does not use the Docplex python interface! (for reasons unknown to me, ILOG maintains 2 different python interfaces for the same product, each with a different syntax and capabilities, which is very confusing if you aren't aware of this).
Those 3 example files, plus the manual on Diagnosing infeasibility by refining conflicts should give you a pretty good idea of how to use the conflict refiner. To my knowledge, ILOG does not provide a Docplex conflict refiner example in their example directory, but @EhsanK provided a good example above.
Finally, if you want to understand how the conflict refiner works internally (and why it may take a very long time to compute a minimal conflict), refer to this paper (and the reference in this paper): Parker, M., Ryan, J. Finding the minimum weight IIS cover of an infeasible system of linear inequalities. Ann Math Artif Intell 17, 107–126 (1996). https://doi.org/10.1007/BF02284626 In particular, it has been shown that finding a minimum (irreducible) set of constraints that render your problem infeasible, is NP-hard.
docplex documentation says:
Given an infeasible model, the conflict refiner can identify conflicting constraints and bounds within it.
So, consider you have an infeasible model (I'll call my instance
model). This is one way to use the conflict refiner.
import docplex.mp.conflict_refiner as cr import docplex.mp.model as cpx model = cpx.Model(name='my_model') ... model.solve() solve_status = model.get_solve_status() if solve_status.name == 'INFEASIBLE_SOLUTION': # or also 'INFEASIBLE_OR_UNBOUNDED_SOLUTION' cref = cr.ConflictRefiner() print('show some of the constraints that can be removed to arrive at a minimal conflict') cref.refine_conflict(model, display=True) # display flag is to show the conflicts
You can create a simple model for yourself and intentionally change a constraint to make the model infeasible and observe what this code does.
If you have a lot of conflicts of similar nature (e.g., it's from the same constraint), then cplex tells you about it and only shows you some of them rather than polluting your screen.