javacplexilog

Display Constraints and Conflict Information CPLEX ILOG Java


Using the CPLEX ILOG JAVA API, how can I print out the Constraints generated, and if it there was any problem I want to also print the conflict information. I found this,

https://www.ibm.com/support/knowledgecenter/SSSA5P_12.5.1/ilog.odms.cplex.help/CPLEX/Parameters/topics/ConflictDisplay.html

But still not clear how to set it.

Thanks!


Solution

  • With regards to your first question, you have a couple options. To see the constraints that were generated you can simply export your model to LP format to see a user-readable version of the model. For example, the LPex1.java example program that is shipped with CPLEX shows how to export the model to LP format:

     // write model to file
     cplex.exportModel("lpex1.lp");
    

    Alternately, if we take the LPex1.java example program, we can add the following code to print the constraints manually:

     // print constraints
     System.out.println("Constraints:");
     for (int i = 0; i < rng[0].length; ++i) {
        System.out.println("  " + rng[0][i]);
     }
    

    The IloRange objects are displayed nicely with toString. This will print something like the following:

    Constraints:
      IloRange c1 : -infinity <= (-1.0*x1 + 1.0*x2 + 1.0*x3) <= 20.0
      IloRange c2 : -infinity <= (1.0*x1 - 3.0*x2 + 1.0*x3) <= 30.0
    

    With regards to your second question, you have to call IloCplex.refineConflict to compute the conflicts (as indicated in the other answer). The ConflictDisplay parameter "Decides how much information CPLEX reports when the conflict refiner is working." From your comments, you should already have access to the constraints (if you're not already, just store them in an array or some other data structure); you do not have to use IloLPMatrix to use the refineConflict method. The example in that technote shows how to print the conflicts out after calling refineConflict.