GurobiError: Constraint has no bool value (are you trying "lb <= expr <= ub"?)
Awaiting user inputI have followed all existing discussion posts about this but cannot figure out why I am getting this error. See below code snippet from python script:
b = {}
gap = {}
for k in range(start_yr,end_yr):
for i in multi_df:
reduction[start_yr,i] = 0
reduction[k+1,i] = 0
for j in range(len(multi_df[i]['COMPLIANCE'])):
for u in multi_df[i]['utilities']:
reduction[k+1,i] += td_matrix[i,j,k]*multi_df[i]['COMPLIANCE']['CO2 reduction (Tons CO2e)'].iloc[j]*(multi_df[i]['utilities'][u]['tCO2_per_dict'][k]/multi_df[i]['utilities'][u]['tCO2_per_dict'][start_yr])
multi_df[i]['annual_total2'] = {}
multi_df[i]['annual_total2'][str(k)] = m.addVar(vtype=gp.GRB.CONTINUOUS, name="x")
multi_df[i]['annual_total2'][str(k)] = multi_df[i]['annual_total'][str(k)]-sum(reduction[k,i] for k in range(start_yr,k))
m.addConstr(multi_df[i]['annual_total2'][str(k)], gp.GRB.GREATER_EQUAL,0)
b[k,i] = m.addVar(vtype=gp.GRB.BINARY, name='b')
gap[k,i] = m.addVar(lb=0,vtype=gp.GRB.CONTINUOUS,name='gap')
M = 15000
m.addConstr(multi_df[i]['annual_total2'][str(k)] >= multi_df[i]['SQFT']*(em_fac[k]) - M*(1-count_tax[k,i]))
m.addConstr(multi_df[i]['annual_total2'][str(k)] <= multi_df[i]['SQFT']*(em_fac[k]) + M*count_tax[k,i])
gap[k,i] = b[k,i]*(multi_df[i]['annual_total2'][str(k)] - multi_df[i]['SQFT']*(em_fac[k]))*cost
-
FYI, the GurobiError appears for my first of 2 Big M constraints:
m.addConstr(multi_df[i]['annual_total2'][str(k)] >= multi_df[i]['SQFT']*(em_fac[k]) - M*(1-count_tax[k,i]))
0 -
Dear James,
could you please post a minimal, reproducible example of the code which throws this error?
For a general discussion about this error, have a look here.
Best regards
Jonasz0 -
Could you please adjust the example such that it is reproducible? There are many definitions missing, e.g., what is multi_df[i]['SQFT'], em_fac[k], count_tax[k,i].
Moreover, you first set multi_df[i]['annual_total2'][str(k)] to be an optimization variable and then override it by an expression in the next line. I am not sure whether this is on purpose or not.
0
Please sign in to leave a comment.
Comments
3 comments