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'