Skip to content
Advertisement

Can’t i use the variable in a formula?

I’m coding a math model using gurobiy, but an error occurs.

the error is ‘Var’ object cannot be interpreted as an integer.

i tried to solve it using search, but I don’t have enough information.

spi: required space of block i

cft: area of factory f at t time

s_Time : Start time

p_Time : processing time

c_Time : completion time,

t: time

f: factory

i: block

yif : If blcok i is assgined at factory f 1 otherwise 0

Space must be available for the time the block is assembled before the block can be allocated to the factory.

for i in range(num_Block+1):
    s_Time[i] =m.addVar(lb=0,vtype=GRB.INTEGER,name='s_time'+str(i))
    c_Time[i] =m.addVar(lb=0,vtype=GRB.INTEGER,name='c_time'+str(i))

for i in range(1,num_Block+1):
    m.addConstr(s_Time[i]+p_Time[i]==c_Time[i])

# This part occurs error because of s_Time[i],c_Time[1]
m.addConstrs(sp[i]*y[i,f] <=c[f,t] for f in range(1,num_Factory+1) for i in range(1,num_Block+1) for t in range(s_Time[i],c_Time[i]))   

Is there another way to express constraints? or How can i solve it enter image description here

Advertisement

Answer

Gurobi is for linear (and quadratic) models. You cannot use a variable as a limit for indexing (that would make the model nonlinear). In general, such constructs are reformulated using binary variables or indicator constraints. You may want to discuss this with your teacher/supervisor.

Advertisement