Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Displaying constraints added to cplex model

    Posted 05/06/19 02:53 PM

    Originally posted by: CPLEX12USER


    Hi,

       I am having cplex object of type IloCplex and have variable array of tyoe IloNumVar[]. I am using java interface and add constraints by iterating through a huge array.

    Say, I do cplex.addEq(var[i], val[i]). I add different type of constraints and have several loops through the program. When I export model, I see all the constraints added together till then and it is hard to debug where exactly problem lies if there was an issue in formulating the constraint.

    Is there a way to print the constraints as interpreted by CPLEX immediately after adding these constraints using addEq, addLe etc.

     

    Thank you!

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Displaying constraints added to cplex model

    Posted 05/06/19 05:20 PM

    Yes. First, if you are not already doing this, I recommend that you add names to all variables and constraints, to make them more readable. The addEq, addLe and addGe methods return a pointer to the constraints they just added. You can capture this to a variable and then just use that variable in an output statement. The .toString() method will automatically be called on the constraint.

    Here is a snippet from some working code:

        IloCplex mip = new IloCplex();
        IloIntVar[] x = new IloIntVar[n];
        IloRange[] constraints = new IloRange[m];
        for (int i = 0; i < n; i++) {
          x[i] = mip.boolVar("x" + i);
        }
        for (int i = 0; i < m; i++) {
          IloLinearNumExpr sum = mip.linearNumExpr();
          for (int j = 0; j < n; j++) {
            sum.addTerm(a[i][j], x[j]);
          }
          constraints[i] = mip.addGe(sum, 1, "C" + i);
          System.out.println("Constraint " + i + ":\n" + constraints[i]);
        }
    

    The a[][] matrix is constraint coefficients. A typical couple of lines of output is the following:

    Constraint 3:
    IloRange C3 : 1.0 <= (1.0*x2 + 1.0*x6 + 1.0*x7 + 1.0*x11 + 1.0*x13 + 1.0*x14 + 1.0*x15) <= infinity

    Paul


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Displaying constraints added to cplex model

    Posted 05/27/19 07:53 AM

    Originally posted by: CPLEX12USER


    It works and makes it easy to interpret the generated model.

     

    Thank you!


    #CPLEXOptimizers
    #DecisionOptimization