I have developed a code for an optimization problem in Python and defined a binary variable in the model. Then I used the Docplex module to solve the model through the Cplex engine. I've mentioned a part of the code as follows.
from docplex.mp.model import Model
model = Model(name='Logistics')
T = 3
A = 3
I = [3200, 2600, 2530]
LI = [[[model.binary_var(name="LI" + str(t) + str(i) + str(a)) for a in
range(A)] for i in range(I[t])] for t in range(T)]
After running the code, I got an optimal solution depicted below.
But I got some warning messages once I tried to run the code for A = 11. As you can see, I've mentioned some of these warning messages. These messages appeared before the optimal solution.
. . . . . . Warning: Duplicate variable name: LI225110 already used for docplex.mp.Var(type=B,name='LI225110')
Warning: Duplicate variable name: LI225210 already used for docplex.mp.Var(type=B,name='LI225210')
I want to know what these warnings are for and how should I fix them. I need your help! Thank you!
The names should probably be unique.
A simple solution could be to add the t
, i
and a
variable into the name
:
LI = [[[model.binary_var(name=f"LI_{t}_{i}_{a}") for ...