Andrew Wang
Andrew Wang

Reputation: 5

Gurobipy Invalid value for Model.addConstr error

I am using Gurobi to write constraints for a model:

   electric = gp.Model('electric')
#Gurobi Variables
supply = electric.addVars(fuel, time_hour, name='supply')
delay = electric.addVars(work_type, time_hour, period_index, name='delay')
#Gurobi Constraints
electric.update()
electric.addConstrs(supply[0, t] <= 1000*float(renewable_supply_hour[t]) for t in range(24))
electric.update()
electric.addConstrs((gp.quicksum(supply[f, t] for f in fuel for t in range(int(period_hours_start[i]),int(period_hours_end[i]))) >= (int(high_urgency_period[i])*80 + int(med_urgency_period[i])*50 + int(low_urgency_period[i])*30)) for i in range(len(time_period)))
electric.update()

I am using Gurobi to write a constraint as follows:

However, I encountered the following error:

Traceback (most recent call last):
  File "/Users/jiangjie/PycharmProjects/pythonProject9/main.py", line 66, in <module>
    electric.addConstrs(((((((((delay[i, n, m] + int(high_urgency_period[i])*80 + int(med_urgency_period[i])*50 + int(low_urgency_period[i])*30)) == delay[i, m, p] + gp.quicksum(supply[1, t] +supply[0,t]for t in range(int(period_hours_start[m-1]), int(period_hours_end[m-1])))) ))  for i in range(3)) ) and n < m and m < p for m in range(1,len(time_period)) for n in range(len(time_period)-1)) for p in range(2, len(time_period)+1) )
  File "src/gurobipy/_model.pyx", line 4081, in gurobipy._model.Model.addConstrs
  File "src/gurobipy/_model.pyx", line 3989, in gurobipy._model.Model.addConstr
gurobipy._exception.GurobiError: Invalid value for Model.addConstr

I tried searching for "Invalid value", but I did not find any answers.

Upvotes: 0

Views: 35

Answers (0)

Related Questions