2

I am attempting to add a constraint to an optimisation model with Gurobi. I have some terms in the constraint that reference both the current hour (that is being looped over), the 'next' hour (hour + 1), as well as some fixed constraints (i.e max_power_ramp).

An example of the code is as follows

for hour in hours:
    if hour > hours[0]:
        for i in num_gen:
            model.addConstr((p_upper[hour, i] <= p[hours[hours.index(hour) - 1], i] + 
                             max_ramp_up[i] * v[hours[hours.index(hour) - 1], i] + 
                                startup_ramp[v[hour, i]] - v[hours[hours.index(hour)-1], i] 
                                    + max_power[i] * (1 - v[hour,i])), name="power ramp up")

Both the num_gen and hours variables are range variables. The issue seems to be associated with how I am referencing the variables such as v[hours[hours.index(hour) - 1], i]

When I debug the code, everything seems to be fine in terms of the individual cell references, but when I try to complete the commands such as max_ramp_up[i] * v[hours[hours.index(hour) - 1], i] & max_power[i] * (1 - v[hour,i]) - it is returning errors such as;

ipdb> max_ramp_up[i] * v[hours[hours.index(hour) - 1], i]
*** gurobipy.GurobiError: Index out of range for attribute 'VarName'
tm553
  • 97
  • 4
  • 15
  • Possible duplicate of [Gurobi Python: how to write nested sum in a constraint](http://stackoverflow.com/questions/43806800/gurobi-python-how-to-write-nested-sum-in-a-constraint) – Greg Glockner May 13 '17 at 15:08

0 Answers0