I would like to define the value of a variable
model.variable_costsPerTimeSlot [t] in pyomo and I would like to use if-statements. Depending on the value of the if-statements, another expression should be used for assigning the value. However, I get an error message when doing this
Evaluating Pyomo variables in a Boolean context, e.g. if expression <= 5: is generally invalid. If you want to obtain the Boolean value of the expression based on the current variable values, explicitly evaluate the expression using the value() function: if value(expression) <= 5: or if value(expression <= 5):
My question is how can I avoid this error? I do not really understand what the problem is. I also tried to use the value() function but I got an error telling me `NameError: name 'value' is not defined
So here you can see this constraint:
def costsPerTimeSlotRule (model, t): if (model.variable_pvGeneration [t] <= model.variable_electricalPowerTotal [t]): return model.variable_costsPerTimeSlot [t] == (model.variable_electricalPowerTotal [t] - model.variable_pvGeneration [t]) * SetUpScenarios.timeResolution * 60 * (model.param_electricityPrice_In_Cents[t]/3600000) if (model.variable_pvGeneration [t] > model.variable_electricalPowerTotal [t]): return model.variable_costsPerTimeSlot [t] == (model.variable_pvGeneration [t] - model.variable_electricalPowerTotal [t]) * SetUpScenarios.timeResolution * 60 * (SetUpScenarios.revenueForFeedingBackElecticityIntoTheGrid_CentsPerKWH/3600000) model.constraint_costsPerTimeSlots = pyo.Constraint(model.set_timeslots, rule =costsPerTimeSlotRule )`
I'd appreciate every comment and would be thankful for your help.