I want to model an integer programming example with docplex in python. for an indicator constraint I have this equation (X is a binary variable):
I wrote this code :
for i1,i2,i3 in P:
mdl.add_indicator_constraints(x[(i,j,k)] for i,j,k in ijk if i==i1 and j==i2 and k==i3)==0
I don't know if I am using the right command for defining this indicator. when I run the program I get this error:
cpx_indvars.append(logct.binary_var.safe_index)
AttributeError: 'Var' object has no attribute 'binary_var'
Your constraint does not look like and indicator constraint. An indicator constraint looks either like "if x
=1 then ..." or "if x
=0 then ..." where x
is a binary variable. There seems to be no "then" part in your constraint.
In case you just want to fix the variable to 0 then you don't have to use an indicator constraint. Just add a regular constraint:
mld.add_linear_constraints(x[(i,j,k)] == 0 for i,j,k in ijk if i==i1 and j==i2 and k==i3)