I'm just learning how the PuLP library works, which is a linear programming solver. The code I'm using was found here: LINK. It solves the following optimization problem (in this case, using binary variables x_{ij}):
This is the code from the tutorial:
import random
import pulp as plp
#Creating random constants for the model's input
n = 10
m = 5
set_I = range(1, n+1)
set_J = range(1, m+1)
c = {(i,j): random.normalvariate(0,1) for i in set_I for j in set_J}
a = {(i,j): random.normalvariate(0,5) for i in set_I for j in set_J}
l = {(i,j): random.randint(0,10) for i in set_I for j in set_J}
u = {(i,j): random.randint(10,20) for i in set_I for j in set_J}
b = {j: random.randint(0,30) for j in set_J}
opt_model = plp.LpProblem(name="Binary Model")
# if x is Binary
x_vars = {(i,j):
plp.LpVariable(cat=plp.LpBinary, name="x_{0}_{1}".format(i,j))
for i in set_I for j in set_J}
# Less than equal constraints
constraints = {j : opt_model.addConstraint(
plp.LpConstraint(
e=m(a[i,j] * x_vars[i,j] for i in set_I),
sense=plp.plp.LpConstraintLE,
rhs=b[j],
name="constraint_{0}".format(j)))
for j in set_J}
objective = plp.lpSum(x_vars[i,j] * c[i,j]
for i in set_I
for j in set_J)
# for minimization
opt_model.sense = plp.LpMinimize
opt_model.setObjective(objective)
And I'm getting the following error that I don't understand:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-20-08e33a7305cc> in <module>
28 rhs=b[j],
29 name="constraint_{0}"))
---> 30 for j in set_J}
31
32 objective = plp.lpSum(x_vars[i,j] * c[i,j]
<ipython-input-20-08e33a7305cc> in <dictcomp>(.0)
28 rhs=b[j],
29 name="constraint_{0}"))
---> 30 for j in set_J}
31
32 objective = plp.lpSum(x_vars[i,j] * c[i,j]
TypeError: 'int' object is not callable