I am new to optimisation and have a fairly basic query.
I have a model with two decision variables x and y that vary in time. I'd like to add a conditional constraint on y at time t depending upon x[t-1], such that I've implemented the following code:
for t in model.timesteps:
if t>1:
if model.x[t-1] <= 1:
model.addConstr(model.y[t] >= 100)
elif model.x[t-1] <= 0.5:
model.addConstr(model.y[t] >= 50)
elif model.x[t-1] <= 0.3:
model.addConstr(model.y[t] >= 20)
However, the above code produces the error:
File "tempconstr.pxi", line 44, in gurobipy.TempConstr.bool gurobipy.GurobiError: Constraint has no bool value (are you trying "lb <= expr <= ub"?)
Having done a little reading on previous related queries on this page, I believe I might need to use a binary indicator variable in order to implement the above. However, I'm not certain as to whether this would solve the above issue.
Could anyone point me in the right direction here please?
Many thanks in advance!