getting DOcplexException: cannot convert to expression: <generator object <genexpr> at 0x7f59feda16d0>

469 Views Asked by At

Im trying this code

m.minimize(30sum(x["Product A",j])+28sum(I["Product B",j])+0.9sum(I["Product A",j])+0.75sum(I["Product B",j])for i in Products)

and it keeps giving me DOcplexException: cannot convert to expression: <generator object error

please help me break this down or let it work

1

There are 1 best solutions below

0
On
from docplex.mp.model import Model 
m = Model()
Products=["Product A","Product B"]
Days=[1,2]

I = {}

for i in Products:
    for j in Days:
            I[(i,j)] = m.integer_var()

    
m.add(I[("Product A",1)]==10)

m.minimize(m.sum(30*I[("Product A",j)]+28*I[("Product B",j)]+0.9*I[("Product A",j)]+0.75*I[("Product B",j)] for j in Days))

m.solve()

print("objective = ",m.objective_value)

works fine and gives

objective =  309.0