I am new in CPLEX and I am using docplex in Python to solve an ILP.
I would like to translate the following constraint in docplex:
$$\sum_{c}(X_p{_w}_{cj}+X_{p+1}{_{w'}}_{cj+1})\leqslant T_w{_{w'}}_{,jj+1} + 1$$
Knowing that the binary variables are:
$X_p{_w}_{cj}=1$ if an operation $p$ is done by a machine $w$ with a configuration $c$ at process plan position $j$, and zero otherwise
$T_w{_{w'}}_{,jj+1}=1$ if there is a change of machine $w$ between position $j$ and $j+1$, and zero otherwise.
I've tried to code a dictionary:
cnrt_10 = {(w, w1, j-1, j): opt_model.add_constraint(ct=opt_model.sum(X_var[p-1, w, c, j-1] + 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}".format(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}
And also a list:
opt_model.add_constraints(opt_model.sum(X_var[p-1, w, c, j-1] + X_var[p, w1, c, j] for c in set_C) <= 1 + T_var[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 both are returning an error.
I am sorry for my elementary question, but I am a beginner in Python and CPLEX, so I would really appreciate if someone can help me with these problems.
for j in set_J
and you are accessing indexj-1
in your constraint (which I guess can lead toIndexError
orKeyError
) $\endgroup$