Dear support team,
I am trying to write a simple optimization problem (generalized assignment problem) by using docplex on the google colab. As I am very new to use this, I have some issues with defining its syntax to read the problem data. The MP model is as follows:
# Set
tasks = ["job1", "job2", "job3"];
machines = ["m1", "m2"];
# Data
b = [13, 11];
c = [[9, 2],[1, 2],[3, 8]];
a = [[6, 8],[7, 5],[9, 6]];
# create the variables
mdl = Model('GAP')
idx_x = [(i,j) for i in tasks for j in machines]
x = mdl.binary_var_dict(idx_x, name="x");
# MP
mdl.minimize(mdl.sum(x[i,j]*c[i,j] for i in tasks for j in machines));
mdl.add_constraints(mdl.sum(x[i,j] for j in machines) == 1 for i in tasks);
mdl.add_constraints(mdl.sum(x[i,j]*a[i,j] for i in tasks) <= b[j] for j in machines);
mdl.solve()
When I run the engine, it shows the following error:
TypeError Traceback (most recent call last)
<ipython-input-83-21876a9e517b> in <module>()
17
18 # MP
---> 19 mdl.minimize(mdl.sum(x[i,j]*c[i,j] for i in tasks for j in machines));
20 mdl.add_constraints(mdl.sum(x[i,j] for j in machines) == 1 for i in tasks);
21 mdl.add_constraints(mdl.sum(x[i,j]*a[i,j] for i in tasks) <= b[j] for j in machines);
3 frames
<ipython-input-83-21876a9e517b> in <genexpr>(.0)
17
18 # MP
---> 19 mdl.minimize(mdl.sum(x[i,j]*c[i,j] for i in tasks for j in machines));
20 mdl.add_constraints(mdl.sum(x[i,j] for j in machines) == 1 for i in tasks);
21 mdl.add_constraints(mdl.sum(x[i,j]*a[i,j] for i in tasks) <= b[j] for j in machines);
TypeError: list indices must be integers or slices, not tuple
I tried different syntaxes based on the existing example in
this like, but I could not get any reasonable output.
Would you say how can I fix that, please?
Best regards
------------------------------
Abbas Omidi
------------------------------
#DecisionOptimization