I am using docplex in Python to solve a ILP.
I would like to translate the following constraint in docplex.
[Constraint][1]
https://i.sstatic.net/OPhwe.png
I tried the following code:
#decision variables
X_var = {(p, w, c, j): opt_model.binary_var(name="X_{0}_{1}_{2}_{3}".format(p, w, c, j))
for p in set_OP for w in set_W for c in set_C for j in set_J}
T_var = {(w, w1, j-1, j): opt_model.binary_var(name="T_{0}_{1}_{2}_{3}".format(w, w1, j-1, j))
for w in set_W for w1 in set_W for j in set_J}
#constraint
cnrt_10 = {(p, w, w1, j-1, j): opt_model.add_constraint(ct=opt_model.sum(X_var[p-1, w, c, j-1] for c in set_C) + opt_model.sum(X_var[p, w1, c, j] for c in set_C) <= 1 + T_var[w, w1, j-1, j],
ctname="cnrt10_{0}_{1}_{2}_{3}_{4}".format(p, w, w1, j-1, j)) for p in set_OP for w in set_W for w1 in set_W for j in set_J}
But it is giving the following error:
KeyError: (0, 1, 1, 0)
I've searched about, and it seems that this is an error related to an empty dictionary. I've tried many different ways to solve it, bus I was not able. Since I am new in Python and CPLEX, I think it is not really complicated. If someone could help me, I will be really grateful.
Thanks in advance,