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