I’m modeling a PV + BESS system to find the optimum size that will meet a certain demand profile. I’m trying to model a condition for the charging of the BESS whereby charging occur when the output of the pv is greater than the demand. I’m getting the error below:
ERROR: Rule failed when generating expression for Constraint
charge_binary_constraint_1 with index 0: PyomoException: Cannot convert non-
constant Pyomo expression (0.0 < PV_output[0]) to bool. This error is
usually caused by using a Var, unit, or mutable Param in a Boolean context
such as an “if” statement, or when checking container membership or equality.
I’m looking for a method to implement the logic. Here is the constraint I tried to formulate
def charge_binary_rule_1(model, t):
if model.PV_output[t] > model.demand[t]:
return model.charge_binary_1[t] == 1
else:
return model.charge_binary_1[t] == 0
model.charge_binary_constraint_1 = pyo.Constraint(model.T, rule=charge_binary_rule_1)