# CPLEX Indicator Constraints in Java API

I'm using the Java API of CPLEX (12.6.1 version) to solve a MILP problem.

This is how I create 'normal' constraints:

public void charge_discharge_constraints() throws IloException {

for (int k = 0; k < periods; k++) {
for (int p = 0; p < num_p; p++) {
IloLinearNumExpr exp = model.linearNumExpr();
for (int n = 0; n < num_n; n++)
IloRange constr = model.addGe(1, exp, "Non simultaneous charge discharge");
}
}
}


Now, I'm trying to add an 'indicator constraint' such as:

if bd_p[p][k] == 1, -> (then) h_p[p][k] >= 4800.0


for every p and k indices.

I tried to achieve this by doing:

public void indicator_constraints() throws IloException {

for (int p = 0; p < num_p; p++) {
for (int k = 0; k < periods; k++) {
IloLinearNumExpr exp = model.linearNumExpr();
}
}
}


But, after having observed the generated ".lp" file, I noticed that the indicator constraints I created use the double-arrow simbol (<->), while my aim is to use the right-arrow symbol (->).

How could I achieve this?

I can confirm that I have previously assigned a name to variables bd_p and h_p. Indeed, inside the LP file:

• both of them are present in the Binaries section (the section which lists the binary variables of the problem);
• they're correctly bounded between 0 and 1.

Anyway, while I was expecting that the indicator constraints which I generated should have used variables bd_p and h_p, actually (after a further investigation of the LP file) I can say that only the h_p variable is involved in the indicator constraints.

Indeed, the LP file contains indicator constraints formulated as:

IloI785: x38223#36652 = 1 <-> h_p(27,17)#34158 >= 4800


So, while h_p variable compares, bd_p variable is not present. In place of bd_p there's another variable called x followed by a progressive number.

bd_p is a binary variable, I previously assigned a name to it, it is correctly defined/bounded in the LP file, and it is used in many other "normal" (linear) constraints without any problem.

I also tried to do this small change:

public void indicator_constraints() throws IloException {
for (int p = 0; p < num_p; p++) {
for (int k = 0; k < periods; k++) {
IloLinearNumExpr exp_if = model.linearNumExpr();
IloLinearNumExpr exp_then = model.linearNumExpr();
}
}
}


or, this other alternative:

public void indicator_constraints() throws IloException {
for (int p = 0; p < num_p; p++) {
for (int k = 0; k < periods; k++) {
IloLinearNumExpr exp_if = model.linearNumExpr();
IloLinearNumExpr exp_then = model.linearNumExpr();
}
}
}


but with no improvement.

So, I can't understand why in the LP file, the binary variable h_p is replaced by a unnamed variable.

Which could be the problem?

• Thank you for your suggestions, very interesting! Actually, I have correctly previoulsy assigned a name to all my variables, but you gave me the intuition to notice that, while the h_p variable is present in the indicator constraints in the LP file, the binary variable bd_p doesn't compare (in place of bd_p there's a generic variable called x followed by a progressive number). Its strange to me; anyway, I edited my original post to add some details which can be useful to you in order to help me to solve this problem. Jun 8 '21 at 22:09